diff --git a/README.md b/README.md index 3f3f7c8..d5cd422 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/IBM/vpc-go-sdk) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) -# IBM Cloud VPC Go SDK Version 0.55.0 +# IBM Cloud VPC Go SDK Version 0.56.0 Go client library to interact with the various [IBM Cloud VPC Services APIs](https://cloud.ibm.com/apidocs?category=vpc). **Note:** Given the current version of all VPC SDKs across supported languages and the current VPC API specification, we retracted the vpc-go-sdk version 1.x to version v0.6.0, which had the same features as v1.0.1. -Consider using v0.55.0 from now on. Refrain from using commands like `go get -u ..` and `go get ..@latest` on go 1.14 and lower as you will not get the latest release. +Consider using v0.56.0 from now on. Refrain from using commands like `go get -u ..` and `go get ..@latest` on go 1.14 and lower as you will not get the latest release. This SDK uses [Semantic Versioning](https://semver.org), and as such there may be backward-incompatible changes for any new `0.y.z` version. ## Table of Contents @@ -64,7 +64,7 @@ Use this command to download and install the VPC Go SDK service to allow your Go use it: ``` -go get github.com/IBM/vpc-go-sdk@v0.55.0 +go get github.com/IBM/vpc-go-sdk@v0.56.0 ``` @@ -90,7 +90,7 @@ to your `Gopkg.toml` file. Here is an example: ``` [[constraint]] name = "github.com/IBM/vpc-go-sdk/" - version = "0.55.0" + version = "0.56.0" ``` Then run `dep ensure`. diff --git a/common/version.go b/common/version.go index d03134b..d767b10 100644 --- a/common/version.go +++ b/common/version.go @@ -1,4 +1,4 @@ package common // Version of the SDK -const Version = "0.55.0" +const Version = "0.56.0" diff --git a/vpcv1/vpc_v1.go b/vpcv1/vpc_v1.go index 521e1cf..6b3ace9 100644 --- a/vpcv1/vpc_v1.go +++ b/vpcv1/vpc_v1.go @@ -38,7 +38,7 @@ import ( // VpcV1 : The IBM Cloud Virtual Private Cloud (VPC) API can be used to programmatically provision and manage virtual // server instances, along with subnets, volumes, load balancers, and more. // -// API Version: 2024-07-17 +// API Version: 2024-07-22 type VpcV1 struct { Service *core.BaseService @@ -47,7 +47,7 @@ type VpcV1 struct { Generation *int64 // The API version, in format `YYYY-MM-DD`. For the API behavior documented here, specify any date between `2024-04-30` - // and `2024-07-17`. + // and `2024-07-22`. Version *string } @@ -68,7 +68,7 @@ type VpcV1Options struct { Generation *int64 // The API version, in format `YYYY-MM-DD`. For the API behavior documented here, specify any date between `2024-04-30` - // and `2024-07-10`. + // and `2024-07-22`. Version *string } @@ -14755,6 +14755,96 @@ func (vpc *VpcV1) GetBareMetalServerInitializationWithContext(ctx context.Contex return } +// ReplaceBareMetalServerInitialization : Reinitialize a bare metal server +// This request reinitializes a bare metal server with the specified image and SSH keys. The server must be stopped. +// Upon successful reinitiatilization, the bare metal server will be started automatically. +func (vpc *VpcV1) ReplaceBareMetalServerInitialization(replaceBareMetalServerInitializationOptions *ReplaceBareMetalServerInitializationOptions) (result *BareMetalServerInitialization, response *core.DetailedResponse, err error) { + result, response, err = vpc.ReplaceBareMetalServerInitializationWithContext(context.Background(), replaceBareMetalServerInitializationOptions) + err = core.RepurposeSDKProblem(err, "") + return +} + +// ReplaceBareMetalServerInitializationWithContext is an alternate form of the ReplaceBareMetalServerInitialization method which supports a Context parameter +func (vpc *VpcV1) ReplaceBareMetalServerInitializationWithContext(ctx context.Context, replaceBareMetalServerInitializationOptions *ReplaceBareMetalServerInitializationOptions) (result *BareMetalServerInitialization, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(replaceBareMetalServerInitializationOptions, "replaceBareMetalServerInitializationOptions cannot be nil") + if err != nil { + err = core.SDKErrorf(err, "", "unexpected-nil-param", common.GetComponentInfo()) + return + } + err = core.ValidateStruct(replaceBareMetalServerInitializationOptions, "replaceBareMetalServerInitializationOptions") + if err != nil { + err = core.SDKErrorf(err, "", "struct-validation-error", common.GetComponentInfo()) + return + } + + pathParamsMap := map[string]string{ + "id": *replaceBareMetalServerInitializationOptions.ID, + } + + builder := core.NewRequestBuilder(core.PUT) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = vpc.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(vpc.Service.Options.URL, `/bare_metal_servers/{id}/initialization`, pathParamsMap) + if err != nil { + err = core.SDKErrorf(err, "", "url-resolve-error", common.GetComponentInfo()) + return + } + + for headerName, headerValue := range replaceBareMetalServerInitializationOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("vpc", "V1", "ReplaceBareMetalServerInitialization") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + builder.AddQuery("version", fmt.Sprint(*vpc.Version)) + builder.AddQuery("generation", fmt.Sprint(*vpc.Generation)) + + body := make(map[string]interface{}) + if replaceBareMetalServerInitializationOptions.Image != nil { + body["image"] = replaceBareMetalServerInitializationOptions.Image + } + if replaceBareMetalServerInitializationOptions.Keys != nil { + body["keys"] = replaceBareMetalServerInitializationOptions.Keys + } + if replaceBareMetalServerInitializationOptions.UserData != nil { + body["user_data"] = replaceBareMetalServerInitializationOptions.UserData + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + err = core.SDKErrorf(err, "", "set-json-body-error", common.GetComponentInfo()) + return + } + + request, err := builder.Build() + if err != nil { + err = core.SDKErrorf(err, "", "build-error", common.GetComponentInfo()) + return + } + + var rawResponse map[string]json.RawMessage + response, err = vpc.Service.Request(request, &rawResponse) + if err != nil { + core.EnrichHTTPProblem(err, "replace_bare_metal_server_initialization", getServiceComponentInfo()) + err = core.SDKErrorf(err, "", "http-request-err", common.GetComponentInfo()) + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalBareMetalServerInitialization) + if err != nil { + err = core.SDKErrorf(err, "", "unmarshal-resp-error", common.GetComponentInfo()) + return + } + response.Result = result + } + + return +} + // RestartBareMetalServer : Restart a bare metal server // This request immediately restarts a bare metal server. For this request to succeed, the server must have a `status` // of `running`. @@ -29977,7 +30067,7 @@ func (vpc *VpcV1) UpdateFlowLogCollectorWithContext(ctx context.Context, updateF return } func getServiceComponentInfo() *core.ProblemComponent { - return core.NewProblemComponent(DefaultServiceName, "today") + return core.NewProblemComponent(DefaultServiceName, "2024-07-09") } // AccountReference : AccountReference struct @@ -32405,6 +32495,7 @@ type BareMetalServer struct { // - `failed`: server is failed and not usable (see `status_reasons`) // - `maintenance`: server is undergoing maintenance (not usable) // - `pending`: server is being provisioned and not yet usable + // - `reinitializing`: server is reinitializing and not yet usable // - `restarting`: server is restarting and not yet usable // - `running`: server is powered on // - `starting`: server is starting and not yet usable @@ -32450,6 +32541,7 @@ const ( // - `failed`: server is failed and not usable (see `status_reasons`) // - `maintenance`: server is undergoing maintenance (not usable) // - `pending`: server is being provisioned and not yet usable +// - `reinitializing`: server is reinitializing and not yet usable // - `restarting`: server is restarting and not yet usable // - `running`: server is powered on // - `starting`: server is starting and not yet usable @@ -32458,14 +32550,15 @@ const ( // The enumerated values for this property may // [expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future. const ( - BareMetalServerStatusDeletingConst = "deleting" - BareMetalServerStatusFailedConst = "failed" - BareMetalServerStatusMaintenanceConst = "maintenance" - BareMetalServerStatusPendingConst = "pending" - BareMetalServerStatusRestartingConst = "restarting" - BareMetalServerStatusRunningConst = "running" - BareMetalServerStatusStartingConst = "starting" - BareMetalServerStatusStoppedConst = "stopped" + BareMetalServerStatusDeletingConst = "deleting" + BareMetalServerStatusFailedConst = "failed" + BareMetalServerStatusMaintenanceConst = "maintenance" + BareMetalServerStatusPendingConst = "pending" + BareMetalServerStatusReinitializingConst = "reinitializing" + BareMetalServerStatusRestartingConst = "restarting" + BareMetalServerStatusRunningConst = "running" + BareMetalServerStatusStartingConst = "starting" + BareMetalServerStatusStoppedConst = "stopped" ) // UnmarshalBareMetalServer unmarshals an instance of BareMetalServer from the specified map of raw messages. @@ -36358,6 +36451,7 @@ type BareMetalServerStatusReason struct { // The enumerated values for this property may // [expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future. const ( + BareMetalServerStatusReasonCodeCannotReinitializeConst = "cannot_reinitialize" BareMetalServerStatusReasonCodeCannotStartConst = "cannot_start" BareMetalServerStatusReasonCodeCannotStartCapacityConst = "cannot_start_capacity" BareMetalServerStatusReasonCodeCannotStartComputeConst = "cannot_start_compute" @@ -74004,6 +74098,71 @@ func (options *RemoveVPNGatewayConnectionsPeerCIDROptions) SetHeaders(param map[ return options } +// ReplaceBareMetalServerInitializationOptions : The ReplaceBareMetalServerInitialization options. +type ReplaceBareMetalServerInitializationOptions struct { + // The bare metal server identifier. + ID *string `json:"id" validate:"required,ne="` + + // The image to be used when provisioning the bare metal server. + Image ImageIdentityIntf `json:"image" validate:"required"` + + // The public SSH keys to install on the bare metal server. Keys will be made available to the bare metal server as + // cloud-init vendor data. For cloud-init enabled images, these keys will also be added as SSH authorized keys for the + // administrative user. + // + // For Windows images, at least one key must be specified, and one will be selected to encrypt the administrator + // password. Keys are optional for other images, but if no keys are specified, the instance will be inaccessible unless + // the specified image provides another means of access. + Keys []KeyIdentityIntf `json:"keys" validate:"required"` + + // User data to be made available when initializing the bare metal server. + // + // If unspecified, no user data will be made available. + UserData *string `json:"user_data,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewReplaceBareMetalServerInitializationOptions : Instantiate ReplaceBareMetalServerInitializationOptions +func (*VpcV1) NewReplaceBareMetalServerInitializationOptions(id string, image ImageIdentityIntf, keys []KeyIdentityIntf) *ReplaceBareMetalServerInitializationOptions { + return &ReplaceBareMetalServerInitializationOptions{ + ID: core.StringPtr(id), + Image: image, + Keys: keys, + } +} + +// SetID : Allow user to set ID +func (_options *ReplaceBareMetalServerInitializationOptions) SetID(id string) *ReplaceBareMetalServerInitializationOptions { + _options.ID = core.StringPtr(id) + return _options +} + +// SetImage : Allow user to set Image +func (_options *ReplaceBareMetalServerInitializationOptions) SetImage(image ImageIdentityIntf) *ReplaceBareMetalServerInitializationOptions { + _options.Image = image + return _options +} + +// SetKeys : Allow user to set Keys +func (_options *ReplaceBareMetalServerInitializationOptions) SetKeys(keys []KeyIdentityIntf) *ReplaceBareMetalServerInitializationOptions { + _options.Keys = keys + return _options +} + +// SetUserData : Allow user to set UserData +func (_options *ReplaceBareMetalServerInitializationOptions) SetUserData(userData string) *ReplaceBareMetalServerInitializationOptions { + _options.UserData = core.StringPtr(userData) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ReplaceBareMetalServerInitializationOptions) SetHeaders(param map[string]string) *ReplaceBareMetalServerInitializationOptions { + options.Headers = param + return options +} + // ReplaceLoadBalancerPoolMembersOptions : The ReplaceLoadBalancerPoolMembers options. type ReplaceLoadBalancerPoolMembersOptions struct { // The load balancer identifier. diff --git a/vpcv1/vpc_v1_test.go b/vpcv1/vpc_v1_test.go index c6d5195..a4cc05f 100644 --- a/vpcv1/vpc_v1_test.go +++ b/vpcv1/vpc_v1_test.go @@ -49566,6 +49566,318 @@ var _ = Describe(`VpcV1`, func() { }) }) }) + Describe(`ReplaceBareMetalServerInitialization(replaceBareMetalServerInitializationOptions *ReplaceBareMetalServerInitializationOptions) - Operation response error`, func() { + version := "testString" + replaceBareMetalServerInitializationPath := "/bare_metal_servers/testString/initialization" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(replaceBareMetalServerInitializationPath)) + Expect(req.Method).To(Equal("PUT")) + Expect(req.URL.Query()["version"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["generation"]).To(Equal([]string{fmt.Sprint(int64(2))})) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ReplaceBareMetalServerInitialization with error: Operation response processing error`, func() { + vpcService, serviceErr := vpcv1.NewVpcV1(&vpcv1.VpcV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Version: core.StringPtr(version), + }) + Expect(serviceErr).To(BeNil()) + Expect(vpcService).ToNot(BeNil()) + + // Construct an instance of the ImageIdentityByID model + imageIdentityModel := new(vpcv1.ImageIdentityByID) + imageIdentityModel.ID = core.StringPtr("r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8") + + // Construct an instance of the KeyIdentityByID model + keyIdentityModel := new(vpcv1.KeyIdentityByID) + keyIdentityModel.ID = core.StringPtr("a6b1a881-2ce8-41a3-80fc-36316a73f803") + + // Construct an instance of the ReplaceBareMetalServerInitializationOptions model + replaceBareMetalServerInitializationOptionsModel := new(vpcv1.ReplaceBareMetalServerInitializationOptions) + replaceBareMetalServerInitializationOptionsModel.ID = core.StringPtr("testString") + replaceBareMetalServerInitializationOptionsModel.Image = imageIdentityModel + replaceBareMetalServerInitializationOptionsModel.Keys = []vpcv1.KeyIdentityIntf{keyIdentityModel} + replaceBareMetalServerInitializationOptionsModel.UserData = core.StringPtr("testString") + replaceBareMetalServerInitializationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := vpcService.ReplaceBareMetalServerInitialization(replaceBareMetalServerInitializationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + vpcService.EnableRetries(0, 0) + result, response, operationErr = vpcService.ReplaceBareMetalServerInitialization(replaceBareMetalServerInitializationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ReplaceBareMetalServerInitialization(replaceBareMetalServerInitializationOptions *ReplaceBareMetalServerInitializationOptions)`, func() { + version := "testString" + replaceBareMetalServerInitializationPath := "/bare_metal_servers/testString/initialization" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(replaceBareMetalServerInitializationPath)) + Expect(req.Method).To(Equal("PUT")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + Expect(req.URL.Query()["version"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["generation"]).To(Equal([]string{fmt.Sprint(int64(2))})) + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"image": {"crn": "crn:v1:bluemix:public:is:us-south:a/aa2432b1fa4d4ace891e9b80fc104e34::image:r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/images/r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8", "id": "r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8", "name": "my-image", "remote": {"account": {"id": "bb1b52262f7441a586f49068482f1e60", "resource_type": "account"}, "region": {"href": "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south", "name": "us-south"}}, "resource_type": "image"}, "keys": [{"crn": "crn:v1:bluemix:public:is:us-south:a/aa2432b1fa4d4ace891e9b80fc104e34::key:a6b1a881-2ce8-41a3-80fc-36316a73f803", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "fingerprint": "SHA256:yxavE4CIOL2NlsqcurRO3xGjkP6m/0mp8ugojH5yxlY", "href": "https://us-south.iaas.cloud.ibm.com/v1/keys/a6b1a881-2ce8-41a3-80fc-36316a73f803", "id": "a6b1a881-2ce8-41a3-80fc-36316a73f803", "name": "my-key"}], "user_accounts": [{"encrypted_password": "qQ+/YEApnl1ZtEgIrfprzb065307thTkzlnLqL5ICpesdbBN03dyCQ==", "encryption_key": {"crn": "crn:v1:bluemix:public:is:us-south:a/aa2432b1fa4d4ace891e9b80fc104e34::key:a6b1a881-2ce8-41a3-80fc-36316a73f803", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "fingerprint": "SHA256:yxavE4CIOL2NlsqcurRO3xGjkP6m/0mp8ugojH5yxlY", "href": "https://us-south.iaas.cloud.ibm.com/v1/keys/a6b1a881-2ce8-41a3-80fc-36316a73f803", "id": "a6b1a881-2ce8-41a3-80fc-36316a73f803", "name": "my-key"}, "resource_type": "host_user_account", "username": "Administrator"}]}`) + })) + }) + It(`Invoke ReplaceBareMetalServerInitialization successfully with retries`, func() { + vpcService, serviceErr := vpcv1.NewVpcV1(&vpcv1.VpcV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Version: core.StringPtr(version), + }) + Expect(serviceErr).To(BeNil()) + Expect(vpcService).ToNot(BeNil()) + vpcService.EnableRetries(0, 0) + + // Construct an instance of the ImageIdentityByID model + imageIdentityModel := new(vpcv1.ImageIdentityByID) + imageIdentityModel.ID = core.StringPtr("r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8") + + // Construct an instance of the KeyIdentityByID model + keyIdentityModel := new(vpcv1.KeyIdentityByID) + keyIdentityModel.ID = core.StringPtr("a6b1a881-2ce8-41a3-80fc-36316a73f803") + + // Construct an instance of the ReplaceBareMetalServerInitializationOptions model + replaceBareMetalServerInitializationOptionsModel := new(vpcv1.ReplaceBareMetalServerInitializationOptions) + replaceBareMetalServerInitializationOptionsModel.ID = core.StringPtr("testString") + replaceBareMetalServerInitializationOptionsModel.Image = imageIdentityModel + replaceBareMetalServerInitializationOptionsModel.Keys = []vpcv1.KeyIdentityIntf{keyIdentityModel} + replaceBareMetalServerInitializationOptionsModel.UserData = core.StringPtr("testString") + replaceBareMetalServerInitializationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := vpcService.ReplaceBareMetalServerInitializationWithContext(ctx, replaceBareMetalServerInitializationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + vpcService.DisableRetries() + result, response, operationErr := vpcService.ReplaceBareMetalServerInitialization(replaceBareMetalServerInitializationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = vpcService.ReplaceBareMetalServerInitializationWithContext(ctx, replaceBareMetalServerInitializationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(replaceBareMetalServerInitializationPath)) + Expect(req.Method).To(Equal("PUT")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + Expect(req.URL.Query()["version"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["generation"]).To(Equal([]string{fmt.Sprint(int64(2))})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"image": {"crn": "crn:v1:bluemix:public:is:us-south:a/aa2432b1fa4d4ace891e9b80fc104e34::image:r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/images/r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8", "id": "r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8", "name": "my-image", "remote": {"account": {"id": "bb1b52262f7441a586f49068482f1e60", "resource_type": "account"}, "region": {"href": "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south", "name": "us-south"}}, "resource_type": "image"}, "keys": [{"crn": "crn:v1:bluemix:public:is:us-south:a/aa2432b1fa4d4ace891e9b80fc104e34::key:a6b1a881-2ce8-41a3-80fc-36316a73f803", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "fingerprint": "SHA256:yxavE4CIOL2NlsqcurRO3xGjkP6m/0mp8ugojH5yxlY", "href": "https://us-south.iaas.cloud.ibm.com/v1/keys/a6b1a881-2ce8-41a3-80fc-36316a73f803", "id": "a6b1a881-2ce8-41a3-80fc-36316a73f803", "name": "my-key"}], "user_accounts": [{"encrypted_password": "qQ+/YEApnl1ZtEgIrfprzb065307thTkzlnLqL5ICpesdbBN03dyCQ==", "encryption_key": {"crn": "crn:v1:bluemix:public:is:us-south:a/aa2432b1fa4d4ace891e9b80fc104e34::key:a6b1a881-2ce8-41a3-80fc-36316a73f803", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "fingerprint": "SHA256:yxavE4CIOL2NlsqcurRO3xGjkP6m/0mp8ugojH5yxlY", "href": "https://us-south.iaas.cloud.ibm.com/v1/keys/a6b1a881-2ce8-41a3-80fc-36316a73f803", "id": "a6b1a881-2ce8-41a3-80fc-36316a73f803", "name": "my-key"}, "resource_type": "host_user_account", "username": "Administrator"}]}`) + })) + }) + It(`Invoke ReplaceBareMetalServerInitialization successfully`, func() { + vpcService, serviceErr := vpcv1.NewVpcV1(&vpcv1.VpcV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Version: core.StringPtr(version), + }) + Expect(serviceErr).To(BeNil()) + Expect(vpcService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := vpcService.ReplaceBareMetalServerInitialization(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ImageIdentityByID model + imageIdentityModel := new(vpcv1.ImageIdentityByID) + imageIdentityModel.ID = core.StringPtr("r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8") + + // Construct an instance of the KeyIdentityByID model + keyIdentityModel := new(vpcv1.KeyIdentityByID) + keyIdentityModel.ID = core.StringPtr("a6b1a881-2ce8-41a3-80fc-36316a73f803") + + // Construct an instance of the ReplaceBareMetalServerInitializationOptions model + replaceBareMetalServerInitializationOptionsModel := new(vpcv1.ReplaceBareMetalServerInitializationOptions) + replaceBareMetalServerInitializationOptionsModel.ID = core.StringPtr("testString") + replaceBareMetalServerInitializationOptionsModel.Image = imageIdentityModel + replaceBareMetalServerInitializationOptionsModel.Keys = []vpcv1.KeyIdentityIntf{keyIdentityModel} + replaceBareMetalServerInitializationOptionsModel.UserData = core.StringPtr("testString") + replaceBareMetalServerInitializationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = vpcService.ReplaceBareMetalServerInitialization(replaceBareMetalServerInitializationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ReplaceBareMetalServerInitialization with error: Operation validation and request error`, func() { + vpcService, serviceErr := vpcv1.NewVpcV1(&vpcv1.VpcV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Version: core.StringPtr(version), + }) + Expect(serviceErr).To(BeNil()) + Expect(vpcService).ToNot(BeNil()) + + // Construct an instance of the ImageIdentityByID model + imageIdentityModel := new(vpcv1.ImageIdentityByID) + imageIdentityModel.ID = core.StringPtr("r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8") + + // Construct an instance of the KeyIdentityByID model + keyIdentityModel := new(vpcv1.KeyIdentityByID) + keyIdentityModel.ID = core.StringPtr("a6b1a881-2ce8-41a3-80fc-36316a73f803") + + // Construct an instance of the ReplaceBareMetalServerInitializationOptions model + replaceBareMetalServerInitializationOptionsModel := new(vpcv1.ReplaceBareMetalServerInitializationOptions) + replaceBareMetalServerInitializationOptionsModel.ID = core.StringPtr("testString") + replaceBareMetalServerInitializationOptionsModel.Image = imageIdentityModel + replaceBareMetalServerInitializationOptionsModel.Keys = []vpcv1.KeyIdentityIntf{keyIdentityModel} + replaceBareMetalServerInitializationOptionsModel.UserData = core.StringPtr("testString") + replaceBareMetalServerInitializationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := vpcService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := vpcService.ReplaceBareMetalServerInitialization(replaceBareMetalServerInitializationOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the ReplaceBareMetalServerInitializationOptions model with no property values + replaceBareMetalServerInitializationOptionsModelNew := new(vpcv1.ReplaceBareMetalServerInitializationOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = vpcService.ReplaceBareMetalServerInitialization(replaceBareMetalServerInitializationOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ReplaceBareMetalServerInitialization successfully`, func() { + vpcService, serviceErr := vpcv1.NewVpcV1(&vpcv1.VpcV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + Version: core.StringPtr(version), + }) + Expect(serviceErr).To(BeNil()) + Expect(vpcService).ToNot(BeNil()) + + // Construct an instance of the ImageIdentityByID model + imageIdentityModel := new(vpcv1.ImageIdentityByID) + imageIdentityModel.ID = core.StringPtr("r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8") + + // Construct an instance of the KeyIdentityByID model + keyIdentityModel := new(vpcv1.KeyIdentityByID) + keyIdentityModel.ID = core.StringPtr("a6b1a881-2ce8-41a3-80fc-36316a73f803") + + // Construct an instance of the ReplaceBareMetalServerInitializationOptions model + replaceBareMetalServerInitializationOptionsModel := new(vpcv1.ReplaceBareMetalServerInitializationOptions) + replaceBareMetalServerInitializationOptionsModel.ID = core.StringPtr("testString") + replaceBareMetalServerInitializationOptionsModel.Image = imageIdentityModel + replaceBareMetalServerInitializationOptionsModel.Keys = []vpcv1.KeyIdentityIntf{keyIdentityModel} + replaceBareMetalServerInitializationOptionsModel.UserData = core.StringPtr("testString") + replaceBareMetalServerInitializationOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := vpcService.ReplaceBareMetalServerInitialization(replaceBareMetalServerInitializationOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) Describe(`RestartBareMetalServer(restartBareMetalServerOptions *RestartBareMetalServerOptions)`, func() { version := "testString" restartBareMetalServerPath := "/bare_metal_servers/testString/restart" @@ -108122,6 +108434,36 @@ var _ = Describe(`VpcV1`, func() { Expect(removeVPNGatewayConnectionsPeerCIDROptionsModel.CIDR).To(Equal(core.StringPtr("192.168.1.0/24"))) Expect(removeVPNGatewayConnectionsPeerCIDROptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewReplaceBareMetalServerInitializationOptions successfully`, func() { + // Construct an instance of the ImageIdentityByID model + imageIdentityModel := new(vpcv1.ImageIdentityByID) + Expect(imageIdentityModel).ToNot(BeNil()) + imageIdentityModel.ID = core.StringPtr("r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8") + Expect(imageIdentityModel.ID).To(Equal(core.StringPtr("r006-72b27b5c-f4b0-48bb-b954-5becc7c1dcb8"))) + + // Construct an instance of the KeyIdentityByID model + keyIdentityModel := new(vpcv1.KeyIdentityByID) + Expect(keyIdentityModel).ToNot(BeNil()) + keyIdentityModel.ID = core.StringPtr("a6b1a881-2ce8-41a3-80fc-36316a73f803") + Expect(keyIdentityModel.ID).To(Equal(core.StringPtr("a6b1a881-2ce8-41a3-80fc-36316a73f803"))) + + // Construct an instance of the ReplaceBareMetalServerInitializationOptions model + id := "testString" + var replaceBareMetalServerInitializationOptionsImage vpcv1.ImageIdentityIntf = nil + replaceBareMetalServerInitializationOptionsKeys := []vpcv1.KeyIdentityIntf{} + replaceBareMetalServerInitializationOptionsModel := vpcService.NewReplaceBareMetalServerInitializationOptions(id, replaceBareMetalServerInitializationOptionsImage, replaceBareMetalServerInitializationOptionsKeys) + replaceBareMetalServerInitializationOptionsModel.SetID("testString") + replaceBareMetalServerInitializationOptionsModel.SetImage(imageIdentityModel) + replaceBareMetalServerInitializationOptionsModel.SetKeys([]vpcv1.KeyIdentityIntf{keyIdentityModel}) + replaceBareMetalServerInitializationOptionsModel.SetUserData("testString") + replaceBareMetalServerInitializationOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(replaceBareMetalServerInitializationOptionsModel).ToNot(BeNil()) + Expect(replaceBareMetalServerInitializationOptionsModel.ID).To(Equal(core.StringPtr("testString"))) + Expect(replaceBareMetalServerInitializationOptionsModel.Image).To(Equal(imageIdentityModel)) + Expect(replaceBareMetalServerInitializationOptionsModel.Keys).To(Equal([]vpcv1.KeyIdentityIntf{keyIdentityModel})) + Expect(replaceBareMetalServerInitializationOptionsModel.UserData).To(Equal(core.StringPtr("testString"))) + Expect(replaceBareMetalServerInitializationOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewReplaceLoadBalancerPoolMembersOptions successfully`, func() { // Construct an instance of the LoadBalancerPoolMemberTargetPrototypeInstanceIdentityInstanceIdentityByID model loadBalancerPoolMemberTargetPrototypeModel := new(vpcv1.LoadBalancerPoolMemberTargetPrototypeInstanceIdentityInstanceIdentityByID)