-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathcloud_managed_rancher.go
More file actions
147 lines (110 loc) · 5.7 KB
/
Copy pathcloud_managed_rancher.go
File metadata and controls
147 lines (110 loc) · 5.7 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// SPDX-FileCopyrightText: 2025 OVH SAS <opensource@ovh.net>
//
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"github.com/ovh/ovhcloud-cli/internal/assets"
"github.com/ovh/ovhcloud-cli/internal/services/cloud"
"github.com/spf13/cobra"
"github.com/ovh/ovhcloud-cli/internal/completion"
)
func initCloudRancherCommand(cloudCmd *cobra.Command) {
rancherCmd := &cobra.Command{
Use: "managed-rancher",
Aliases: []string{"mrs"},
Short: "Manage Rancher services in the given cloud project",
}
rancherCmd.PersistentFlags().StringVar(&cloud.CloudProject, "cloud-project", "", "Cloud project ID")
rancherCmd.RegisterFlagCompletionFunc("cloud-project", completion.CloudProjects) //nolint:errcheck
rancherListCmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List Rancher services",
Run: cloud.ListCloudRanchers,
}
rancherCmd.AddCommand(withFilterFlag(rancherListCmd))
rancherCmd.AddCommand(&cobra.Command{
Use: "get <rancher_id>",
Short: "Get a specific Rancher service",
Run: cloud.GetRancher,
Args: cobra.ExactArgs(1),
})
rancherCmd.AddCommand(getRancherEditCmd())
rancherCmd.AddCommand(getRancherCreateCmd())
rancherCmd.AddCommand(&cobra.Command{
Use: "reset-admin-credentials <rancher_id>",
Short: "Reset admin user credentials",
Run: cloud.ResetRancherAdminCredentials,
Args: cobra.ExactArgs(1),
})
rancherCmd.AddCommand(&cobra.Command{
Use: "delete <rancher_id>",
Short: "Delete a specific Rancher service",
Run: cloud.DeleteRancher,
Args: cobra.ExactArgs(1),
})
cloudCmd.AddCommand(rancherCmd)
}
func getRancherEditCmd() *cobra.Command {
editRancherCmd := &cobra.Command{
Use: "edit <rancher_id>",
Short: "Edit the given Rancher service",
Run: cloud.EditRancher,
Args: cobra.ExactArgs(1),
}
editRancherCmd.Flags().StringVar(&cloud.RancherSpec.TargetSpec.Name, "name", "", "Name of the managed Rancher service")
editRancherCmd.Flags().StringVar(&cloud.RancherSpec.TargetSpec.Plan, "plan", "", "Plan of the managed Rancher service (OVHCLOUD_EDITION, STANDARD)")
editRancherCmd.Flags().StringVar(&cloud.RancherSpec.TargetSpec.Version, "version", "", "Version of the managed Rancher service")
var iamAuthEnabled bool
editRancherCmd.Flags().BoolVar(&iamAuthEnabled, "iam-auth-enabled", false, "Allow Rancher to use identities managed by OVHcloud IAM (Identity and Access Management) to control access")
cloud.RancherSpec.TargetSpec.IAMAuthEnabled = &iamAuthEnabled
// Handle optional iam-auth-enabled boolean
editRancherCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("iam-auth-enabled") {
cloud.RancherSpec.TargetSpec.IAMAuthEnabled = &iamAuthEnabled
} else {
cloud.RancherSpec.TargetSpec.IAMAuthEnabled = nil
}
return nil
}
addInteractiveEditorFlag(editRancherCmd)
return editRancherCmd
}
func getRancherCreateCmd() *cobra.Command {
rancherCreateCmd := &cobra.Command{
Use: "create",
Short: "Create a new Rancher service",
Long: `Use this command to create a managed Rancher service in the given public cloud project.
There are three ways to define the creation parameters:
1. Using only CLI flags:
ovhcloud cloud managed-rancher create --name MyNewRancher --plan OVHCLOUD_EDITION --version 2.11.3
2. Using a configuration file:
First you can generate an example of installation file using the following command:
ovhcloud cloud managed-rancher create --init-file ./params.json
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.
After editing the file to set the correct creation parameters, run:
ovhcloud cloud managed-rancher create --from-file ./params.json
Note that you can also pipe the content of the parameters file, like the following:
cat ./params.json | ovhcloud cloud managed-rancher create
In both cases, you can override the parameters in the given file using command line flags, for example:
ovhcloud cloud managed-rancher create --from-file ./params.json --name NameOverriden
3. Using your default text editor:
ovhcloud cloud managed-rancher create --editor
You will be able to choose from several examples of parameters. Once an example has been selected, the CLI will open your
default text editor to update the parameters. When saving the file, the creation will start.
Note that it is also possible to override values in the presented examples using command line flags like the following:
ovhcloud cloud managed-rancher create --editor --region BHS5
`,
Run: cloud.CreateRancher,
}
// Specific flags for Rancher creation
rancherCreateCmd.Flags().StringVar(&cloud.RancherSpec.TargetSpec.Name, "name", "", "Name of the managed Rancher service")
rancherCreateCmd.Flags().StringVar(&cloud.RancherSpec.TargetSpec.Plan, "plan", "", "Plan of the managed Rancher service (available plans can be listed using 'cloud reference managed-rancher list-plans' command)")
rancherCreateCmd.Flags().StringVar(&cloud.RancherSpec.TargetSpec.Version, "version", "", "Version of the managed Rancher service (available versions can be listed using 'cloud reference managed-rancher list-versions' command)")
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")
// Common flags for other means to define parameters
addParameterFileFlags(rancherCreateCmd, false, assets.CloudV2OpenapiSchema, "/cloud/project/{serviceName}/rancher", "post", cloud.CloudRancherCreationExample, nil)
addInteractiveEditorFlag(rancherCreateCmd)
markFlagsMutuallyExclusive(rancherCreateCmd, "from-file", "editor")
return rancherCreateCmd
}