|
5 | 5 | package cmd |
6 | 6 |
|
7 | 7 | import ( |
| 8 | + "github.com/ovh/ovhcloud-cli/internal/assets" |
8 | 9 | "github.com/ovh/ovhcloud-cli/internal/services/cloud" |
9 | 10 | "github.com/spf13/cobra" |
10 | 11 | ) |
@@ -37,12 +38,80 @@ func initCloudRancherCommand(cloudCmd *cobra.Command) { |
37 | 38 | Run: cloud.EditRancher, |
38 | 39 | Args: cobra.ExactArgs(1), |
39 | 40 | } |
40 | | - editRancherCmd.Flags().StringVar(&cloud.RancherTargetSpec.Name, "name", "", "Name of the managed Rancher service") |
41 | | - editRancherCmd.Flags().StringVar(&cloud.RancherTargetSpec.Plan, "plan", "", "Plan of the managed Rancher service (OVHCLOUD_EDITION, STANDARD)") |
42 | | - editRancherCmd.Flags().StringVar(&cloud.RancherTargetSpec.Version, "version", "", "Version of the managed Rancher service") |
43 | | - editRancherCmd.Flags().StringArrayVar(&cloud.RancherTargetSpec.CLIIPRestrictions, "ip-restrictions", nil, "List of IP restrictions (expected format: '<cidrBlock>,<description>')") |
| 41 | + editRancherCmd.Flags().StringVar(&cloud.RancherSpec.TargetSpec.Name, "name", "", "Name of the managed Rancher service") |
| 42 | + editRancherCmd.Flags().StringVar(&cloud.RancherSpec.TargetSpec.Plan, "plan", "", "Plan of the managed Rancher service (OVHCLOUD_EDITION, STANDARD)") |
| 43 | + editRancherCmd.Flags().StringVar(&cloud.RancherSpec.TargetSpec.Version, "version", "", "Version of the managed Rancher service") |
| 44 | + editRancherCmd.Flags().StringArrayVar(&cloud.RancherSpec.TargetSpec.CLIIPRestrictions, "ip-restrictions", nil, "List of IP restrictions (expected format: '<cidrBlock>,<description>')") |
44 | 45 | addInteractiveEditorFlag(editRancherCmd) |
45 | 46 | rancherCmd.AddCommand(editRancherCmd) |
46 | 47 |
|
| 48 | + rancherCmd.AddCommand(getRancherCreateCmd()) |
| 49 | + |
| 50 | + rancherCmd.AddCommand(&cobra.Command{ |
| 51 | + Use: "delete <rancher_id>", |
| 52 | + Short: "Delete a specific Rancher service", |
| 53 | + Run: cloud.DeleteRancher, |
| 54 | + Args: cobra.ExactArgs(1), |
| 55 | + }) |
| 56 | + |
47 | 57 | cloudCmd.AddCommand(rancherCmd) |
48 | 58 | } |
| 59 | + |
| 60 | +func getRancherCreateCmd() *cobra.Command { |
| 61 | + rancherCreateCmd := &cobra.Command{ |
| 62 | + Use: "create", |
| 63 | + Short: "Create a new Rancher service", |
| 64 | + Long: `Use this command to create a managed Rancher service in the given public cloud project. |
| 65 | +There are three ways to define the creation parameters: |
| 66 | +
|
| 67 | +1. Using only CLI flags: |
| 68 | +
|
| 69 | + ovhcloud cloud rancher create --name MyNewRancher --plan OVHCLOUD_EDITION --version 2.11.3 |
| 70 | +
|
| 71 | +2. Using a configuration file: |
| 72 | +
|
| 73 | + First you can generate an example of installation file using the following command: |
| 74 | +
|
| 75 | + ovhcloud cloud rancher create --init-file ./params.json |
| 76 | +
|
| 77 | + You will be able to choose from several examples of parameters. Once an example has been selected, the content is written in the given file. |
| 78 | + After editing the file to set the correct creation parameters, run: |
| 79 | +
|
| 80 | + ovhcloud cloud rancher create --from-file ./params.json |
| 81 | +
|
| 82 | + Note that you can also pipe the content of the parameters file, like the following: |
| 83 | +
|
| 84 | + cat ./params.json | ovhcloud cloud rancher create |
| 85 | +
|
| 86 | + In both cases, you can override the parameters in the given file using command line flags, for example: |
| 87 | +
|
| 88 | + ovhcloud cloud rancher create --from-file ./params.json --name NameOverriden |
| 89 | +
|
| 90 | +3. Using your default text editor: |
| 91 | +
|
| 92 | + ovhcloud cloud rancher create --editor |
| 93 | +| |
| 94 | + You will be able to choose from several examples of parameters. Once an example has been selected, the CLI will open your |
| 95 | + default text editor to update the parameters. When saving the file, the creation will start. |
| 96 | +
|
| 97 | + Note that it is also possible to override values in the presented examples using command line flags like the following: |
| 98 | +
|
| 99 | + ovhcloud cloud rancher create --editor --region BHS5 |
| 100 | +`, |
| 101 | + Run: cloud.CreateRancher, |
| 102 | + } |
| 103 | + |
| 104 | + // Specific flags for Rancher creation |
| 105 | + rancherCreateCmd.Flags().StringVar(&cloud.RancherSpec.TargetSpec.Name, "name", "", "Name of the managed Rancher service") |
| 106 | + rancherCreateCmd.Flags().StringVar(&cloud.RancherSpec.TargetSpec.Plan, "plan", "", "Plan of the managed Rancher service (available plans can be listed using 'cloud reference rancher list-plans' command)") |
| 107 | + rancherCreateCmd.Flags().StringVar(&cloud.RancherSpec.TargetSpec.Version, "version", "", "Version of the managed Rancher service (available versions can be listed using 'cloud reference rancher list-versions' command)") |
| 108 | + rancherCreateCmd.Flags().BoolVar(&cloud.RancherSpec.TargetSpec.IAMAuthEnabled, "iam-auth-enabled", false, "Allow Rancher to use identities managed by OVHcloud IAM (Identity and Access Management) to control access") |
| 109 | + |
| 110 | + // Common flags for other means to define parameters |
| 111 | + addInitParameterFileFlag(rancherCreateCmd, assets.CloudV2OpenapiSchema, "/cloud/project/{serviceName}/rancher", "post", cloud.CloudRancherCreationExample, nil) |
| 112 | + addInteractiveEditorFlag(rancherCreateCmd) |
| 113 | + addFromFileFlag(rancherCreateCmd) |
| 114 | + rancherCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") |
| 115 | + |
| 116 | + return rancherCreateCmd |
| 117 | +} |
0 commit comments