-
Notifications
You must be signed in to change notification settings - Fork 18
/
dns_create.go
50 lines (41 loc) · 1.11 KB
/
dns_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exo "github.com/exoscale/egoscale/v2"
exoapi "github.com/exoscale/egoscale/v2/api"
)
func init() {
dnsCmd.AddCommand(&cobra.Command{
Use: "create DOMAIN-NAME",
Short: "Create a domain",
Aliases: gCreateAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
return createDomain(args[0])
},
})
}
func createDomain(domainName string) error {
var err error
domain := &exo.DNSDomain{}
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, account.CurrentAccount.DefaultZone))
decorateAsyncOperation(fmt.Sprintf("Creating DNS domain %q...", domainName), func() {
domain, err = globalstate.EgoscaleClient.CreateDNSDomain(
ctx,
account.CurrentAccount.DefaultZone,
&exo.DNSDomain{UnicodeName: &domainName},
)
})
if err != nil {
return err
}
if !globalstate.Quiet {
fmt.Printf("Domain %q was created successfully\n", *domain.UnicodeName)
}
return nil
}