From 9999fe586be97fb7b150c7eea7d41c66d6151c67 Mon Sep 17 00:00:00 2001 From: Van Thong Nguyen Date: Thu, 11 May 2023 01:40:01 +0200 Subject: [PATCH 1/2] upgrade gsclient-go v3.12.0 --- go.mod | 6 +++--- go.sum | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b22105a5..ec81ed91 100644 --- a/go.mod +++ b/go.mod @@ -4,12 +4,12 @@ go 1.18 require ( github.com/google/uuid v1.3.0 - github.com/gridscale/gsclient-go/v3 v3.10.0 + github.com/gridscale/gsclient-go/v3 v3.12.0 github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f github.com/mattn/go-runewidth v0.0.13 github.com/sethvargo/go-password v0.2.0 - github.com/sirupsen/logrus v1.8.1 + github.com/sirupsen/logrus v1.9.0 github.com/spf13/cobra v1.4.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.12.0 @@ -48,7 +48,7 @@ require ( github.com/subosito/gotenv v1.3.0 // indirect golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect - golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect + golang.org/x/sys v0.8.0 // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect diff --git a/go.sum b/go.sum index 07578726..11e67250 100644 --- a/go.sum +++ b/go.sum @@ -165,6 +165,8 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/gridscale/gsclient-go/v3 v3.10.0 h1:eujhUcc/y9JWnzvWLW9YEAo7kyG4MeRZXoFNKVKXZms= github.com/gridscale/gsclient-go/v3 v3.10.0/go.mod h1:A9+Af0aJL+uei0DwAEnZ3G6gZgdC5oOyw2ZUPxUfvTs= +github.com/gridscale/gsclient-go/v3 v3.12.0 h1:emsXXMKwGD8IAid1sHtGw5gaDoTIrHt/rWIvwq/FEoc= +github.com/gridscale/gsclient-go/v3 v3.12.0/go.mod h1:A9+Af0aJL+uei0DwAEnZ3G6gZgdC5oOyw2ZUPxUfvTs= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= @@ -245,6 +247,8 @@ github.com/sethvargo/go-password v0.2.0/go.mod h1:Ym4Mr9JXLBycr02MFuVQ/0JHidNetS github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo= github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo= @@ -426,6 +430,9 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= From 837a8c4d9e60231bec50abdeb4b6bd0f726765a9 Mon Sep 17 00:00:00 2001 From: Van Thong Nguyen Date: Thu, 11 May 2023 01:51:29 +0200 Subject: [PATCH 2/2] allow to create/update server with user_data --- cmd/server.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index 9d28c736..ea7fac39 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -30,6 +30,7 @@ type serverCmdFlags struct { autoRecovery bool includeRelated bool force bool + userDataBase64 string } var ( @@ -307,14 +308,18 @@ To create a server without any storage just omit --with-template flag: } cleanupServer := false - server, err := serverOp.CreateServer(ctx, gsclient.ServerCreateRequest{ + serverCreateRequest := gsclient.ServerCreateRequest{ Name: serverFlags.serverName, Cores: serverFlags.cores, Memory: serverFlags.memory, HardwareProfile: profile, AvailablityZone: serverFlags.availabilityZone, AutoRecovery: &serverFlags.autoRecovery, - }) + } + if serverFlags.userDataBase64 != "" { + serverCreateRequest.UserData = &serverFlags.userDataBase64 + } + server, err := serverOp.CreateServer(ctx, serverCreateRequest) if err != nil { return NewError(cmd, "Creating server failed", err) } @@ -388,14 +393,19 @@ var serverSetCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { serverOp := rt.ServerOperator() ctx := context.Background() + serverUpdateRequest := gsclient.ServerUpdateRequest{ + Cores: serverFlags.cores, + Memory: serverFlags.memory, + Name: serverFlags.serverName, + } + if serverFlags.userDataBase64 != "" { + serverUpdateRequest.UserData = &serverFlags.userDataBase64 + } err := serverOp.UpdateServer( ctx, args[0], - gsclient.ServerUpdateRequest{ - Cores: serverFlags.cores, - Memory: serverFlags.memory, - Name: serverFlags.serverName, - }) + serverUpdateRequest, + ) if err != nil { return NewError(cmd, "Failed setting property", err) } @@ -507,10 +517,12 @@ func init() { serverCreateCmd.Flags().StringVar(&serverFlags.profile, "profile", "q35", "Hardware profile") serverCreateCmd.Flags().StringVar(&serverFlags.availabilityZone, "availability-zone", "", "Availability zone. One of \"a\", \"b\", \"c\" (default \"\")") serverCreateCmd.Flags().BoolVar(&serverFlags.autoRecovery, "auto-recovery", true, "Whether to restart in case of errors") + serverCreateCmd.Flags().StringVar(&serverFlags.userDataBase64, "user-data-base64", "", "For system configuration on first boot. May contain cloud-config data or shell scripting, encoded as base64 string. Supported tools are cloud-init, Cloudbase-init, and Ignition.") serverSetCmd.Flags().IntVar(&serverFlags.memory, "mem", 0, "Memory (GB)") serverSetCmd.Flags().IntVar(&serverFlags.cores, "cores", 0, "No. of cores") serverSetCmd.Flags().StringVarP(&serverFlags.serverName, "name", "n", "", "Name of the server") + serverSetCmd.Flags().StringVar(&serverFlags.userDataBase64, "user-data-base64", "", "For system configuration on first boot. May contain cloud-config data or shell scripting, encoded as base64 string. Supported tools are cloud-init, Cloudbase-init, and Ignition.") serverRmCmd.Flags().BoolVarP(&serverFlags.includeRelated, "include-related", "i", false, "Remove all objects currently related to this server, not just the server") serverRmCmd.Flags().BoolVarP(&serverFlags.force, "force", "f", false, "Force a destructive operation")