-
Notifications
You must be signed in to change notification settings - Fork 20
/
dns_create.go
47 lines (39 loc) · 996 Bytes
/
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
package cmd
import (
"fmt"
exo "github.com/exoscale/egoscale/v2"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
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(gCurrentAccount.Environment, gCurrentAccount.DefaultZone))
decorateAsyncOperation(fmt.Sprintf("Creating DNS domain %q...", domainName), func() {
domain, err = cs.CreateDNSDomain(
ctx,
gCurrentAccount.DefaultZone,
&exo.DNSDomain{UnicodeName: &domainName},
)
})
if err != nil {
return err
}
if !gQuiet {
fmt.Printf("Domain %q was created successfully\n", *domain.UnicodeName)
}
return nil
}