|
| 1 | +package virtual_machines |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "github.com/hostinger/api-cli/api" |
| 6 | + "github.com/hostinger/api-cli/client" |
| 7 | + "github.com/hostinger/api-cli/output" |
| 8 | + "github.com/hostinger/api-cli/utils" |
| 9 | + "github.com/spf13/cobra" |
| 10 | + "log" |
| 11 | +) |
| 12 | + |
| 13 | +var SetNameserversCmd = &cobra.Command{ |
| 14 | + Use: "set-nameservers <virtual machine ID>", |
| 15 | + Short: "Set nameservers", |
| 16 | + Long: `This endpoint sets the nameservers for a specified virtual machine. |
| 17 | +Be aware, that improper nameserver configuration can lead to the virtual machine being unable to resolve domain names.`, |
| 18 | + Args: cobra.MatchAll(cobra.ExactArgs(1)), |
| 19 | + Run: func(cmd *cobra.Command, args []string) { |
| 20 | + r, err := api.Request().VPSSetNameserversV1WithResponse(context.TODO(), utils.StringToInt(args[0]), setNameserversRequest(cmd)) |
| 21 | + |
| 22 | + if err != nil { |
| 23 | + log.Fatal(err) |
| 24 | + } |
| 25 | + |
| 26 | + output.Format(cmd, r.Body, r.StatusCode()) |
| 27 | + }, |
| 28 | +} |
| 29 | + |
| 30 | +func init() { |
| 31 | + SetHostnameCmd.Flags().StringP("ns1", "", "", "Name server 1") |
| 32 | + SetHostnameCmd.Flags().StringP("ns2", "", "", "Name server 2") |
| 33 | + |
| 34 | + SetHostnameCmd.MarkFlagRequired("ns1") |
| 35 | +} |
| 36 | + |
| 37 | +func setNameserversRequest(cmd *cobra.Command) client.VPSSetNameserversV1JSONRequestBody { |
| 38 | + ns1, _ := cmd.Flags().GetString("ns1") |
| 39 | + ns2, _ := cmd.Flags().GetString("ns2") |
| 40 | + |
| 41 | + return client.VPSSetNameserversV1JSONRequestBody{ |
| 42 | + Ns1: ns1, |
| 43 | + Ns2: utils.StringPtrOrNil(ns2), |
| 44 | + } |
| 45 | +} |
0 commit comments