From 96c09424767c4b958a671681adde87a320fc1798 Mon Sep 17 00:00:00 2001 From: Ujjwal Kumar <78945437+ujjwal-ibm@users.noreply.github.com> Date: Fri, 30 Dec 2022 10:55:09 +0530 Subject: [PATCH] feat(2022-12-27): updated the sdk as per the api spec released on 2022-12-27 (#63) Signed-off-by: Ujjwal Kumar Signed-off-by: Ujjwal Kumar --- README.md | 8 +- common/version.go | 2 +- vpcv1/vpc_v1.go | 785 +++++++++++++++++++++++++++- vpcv1/vpc_v1_examples_test.go | 930 +++++++++++++++++++++++++--------- vpcv1/vpc_v1_test.go | 673 ++++++++++++++++++++++++ 5 files changed, 2158 insertions(+), 240 deletions(-) diff --git a/README.md b/README.md index 25183e6..6b5e277 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.28.0 +# IBM Cloud VPC Go SDK Version 0.29.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.28.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.29.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.28.0 +go get github.com/IBM/vpc-go-sdk@v0.29.0 ``` @@ -90,7 +90,7 @@ to your `Gopkg.toml` file. Here is an example: ``` [[constraint]] name = "github.com/IBM/vpc-go-sdk/" - version = "0.28.0" + version = "0.29.0" ``` Then run `dep ensure`. diff --git a/common/version.go b/common/version.go index 83cbfa7..4a34835 100644 --- a/common/version.go +++ b/common/version.go @@ -1,4 +1,4 @@ package common // Version of the SDK -const Version = "0.28.0" +const Version = "0.29.0" diff --git a/vpcv1/vpc_v1.go b/vpcv1/vpc_v1.go index 202d387..dc4969c 100644 --- a/vpcv1/vpc_v1.go +++ b/vpcv1/vpc_v1.go @@ -37,7 +37,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: 2022-12-13 +// API Version: 2022-12-27 type VpcV1 struct { Service *core.BaseService @@ -9094,6 +9094,158 @@ func (vpc *VpcV1) CreateBackupPolicyWithContext(ctx context.Context, createBacku return } +// ListBackupPolicyJobs : List all jobs for a backup policy +// This request retrieves all jobs for a backup policy. A backup job represents the execution of a backup policy plan +// for a resource matching the policy's criteria. +func (vpc *VpcV1) ListBackupPolicyJobs(listBackupPolicyJobsOptions *ListBackupPolicyJobsOptions) (result *BackupPolicyJobCollection, response *core.DetailedResponse, err error) { + return vpc.ListBackupPolicyJobsWithContext(context.Background(), listBackupPolicyJobsOptions) +} + +// ListBackupPolicyJobsWithContext is an alternate form of the ListBackupPolicyJobs method which supports a Context parameter +func (vpc *VpcV1) ListBackupPolicyJobsWithContext(ctx context.Context, listBackupPolicyJobsOptions *ListBackupPolicyJobsOptions) (result *BackupPolicyJobCollection, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(listBackupPolicyJobsOptions, "listBackupPolicyJobsOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(listBackupPolicyJobsOptions, "listBackupPolicyJobsOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "backup_policy_id": *listBackupPolicyJobsOptions.BackupPolicyID, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = vpc.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(vpc.Service.Options.URL, `/backup_policies/{backup_policy_id}/jobs`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range listBackupPolicyJobsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("vpc", "V1", "ListBackupPolicyJobs") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + builder.AddQuery("version", fmt.Sprint(*vpc.Version)) + builder.AddQuery("generation", fmt.Sprint(*vpc.generation)) + if listBackupPolicyJobsOptions.Status != nil { + builder.AddQuery("status", fmt.Sprint(*listBackupPolicyJobsOptions.Status)) + } + if listBackupPolicyJobsOptions.BackupPolicyPlanID != nil { + builder.AddQuery("backup_policy_plan.id", fmt.Sprint(*listBackupPolicyJobsOptions.BackupPolicyPlanID)) + } + if listBackupPolicyJobsOptions.Start != nil { + builder.AddQuery("start", fmt.Sprint(*listBackupPolicyJobsOptions.Start)) + } + if listBackupPolicyJobsOptions.Limit != nil { + builder.AddQuery("limit", fmt.Sprint(*listBackupPolicyJobsOptions.Limit)) + } + if listBackupPolicyJobsOptions.Sort != nil { + builder.AddQuery("sort", fmt.Sprint(*listBackupPolicyJobsOptions.Sort)) + } + if listBackupPolicyJobsOptions.SourceID != nil { + builder.AddQuery("source.id", fmt.Sprint(*listBackupPolicyJobsOptions.SourceID)) + } + if listBackupPolicyJobsOptions.TargetSnapshotsID != nil { + builder.AddQuery("target_snapshots[].id", fmt.Sprint(*listBackupPolicyJobsOptions.TargetSnapshotsID)) + } + if listBackupPolicyJobsOptions.TargetSnapshotsCRN != nil { + builder.AddQuery("target_snapshots[].crn", fmt.Sprint(*listBackupPolicyJobsOptions.TargetSnapshotsCRN)) + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = vpc.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalBackupPolicyJobCollection) + if err != nil { + return + } + response.Result = result + } + + return +} + +// GetBackupPolicyJob : Retrieve a backup policy job +// This request retrieves a single backup policy job specified by the identifier in the URL. +func (vpc *VpcV1) GetBackupPolicyJob(getBackupPolicyJobOptions *GetBackupPolicyJobOptions) (result *BackupPolicyJob, response *core.DetailedResponse, err error) { + return vpc.GetBackupPolicyJobWithContext(context.Background(), getBackupPolicyJobOptions) +} + +// GetBackupPolicyJobWithContext is an alternate form of the GetBackupPolicyJob method which supports a Context parameter +func (vpc *VpcV1) GetBackupPolicyJobWithContext(ctx context.Context, getBackupPolicyJobOptions *GetBackupPolicyJobOptions) (result *BackupPolicyJob, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getBackupPolicyJobOptions, "getBackupPolicyJobOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getBackupPolicyJobOptions, "getBackupPolicyJobOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "backup_policy_id": *getBackupPolicyJobOptions.BackupPolicyID, + "id": *getBackupPolicyJobOptions.ID, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = vpc.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(vpc.Service.Options.URL, `/backup_policies/{backup_policy_id}/jobs/{id}`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range getBackupPolicyJobOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("vpc", "V1", "GetBackupPolicyJob") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + builder.AddQuery("version", fmt.Sprint(*vpc.Version)) + builder.AddQuery("generation", fmt.Sprint(*vpc.generation)) + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = vpc.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalBackupPolicyJob) + if err != nil { + return + } + response.Result = result + } + + return +} + // ListBackupPolicyPlans : List all plans for a backup policy // This request retrieves all plans for a backup policy. Backup plans provide the backup schedule and deletion triggers. func (vpc *VpcV1) ListBackupPolicyPlans(listBackupPolicyPlansOptions *ListBackupPolicyPlansOptions) (result *BackupPolicyPlanCollection, response *core.DetailedResponse, err error) { @@ -21864,6 +22016,352 @@ func UnmarshalBackupPolicyCollectionNext(m map[string]json.RawMessage, result in return } +// BackupPolicyJob : BackupPolicyJob struct +type BackupPolicyJob struct { + // Indicates whether this backup policy job will be automatically deleted after it completes. At present, this is + // always `true`, but may be modifiable in the future. + AutoDelete *bool `json:"auto_delete" validate:"required"` + + // If `auto_delete` is `true`, the days after completion that this backup policy job will be deleted. This value may be + // modifiable in the future. + AutoDeleteAfter *int64 `json:"auto_delete_after" validate:"required"` + + // The backup policy plan operated this backup policy job (may be + // [deleted](https://cloud.ibm.com/apidocs/vpc#deleted-resources)). + BackupPolicyPlan *BackupPolicyPlanReference `json:"backup_policy_plan" validate:"required"` + + // The date and time that the backup policy job was completed. + // + // If absent, the backup policy job has not yet completed. + CompletedAt *strfmt.DateTime `json:"completed_at,omitempty"` + + // The date and time that the backup policy job was created. + CreatedAt *strfmt.DateTime `json:"created_at" validate:"required"` + + // The URL for this backup policy job. + Href *string `json:"href" validate:"required"` + + // The unique identifier for this backup policy job. + ID *string `json:"id" validate:"required"` + + // The type of backup policy job. + // + // The enumerated values for this property will expand in the future. When processing this property, check for and log + // unknown values. Optionally halt processing and surface the error, or bypass the backup policy job on which the + // unexpected property value was encountered. + JobType *string `json:"job_type" validate:"required"` + + // The resource type. + ResourceType *string `json:"resource_type" validate:"required"` + + // The source this backup was created from (may be + // [deleted](https://cloud.ibm.com/apidocs/vpc#deleted-resources)). + Source BackupPolicyJobSourceIntf `json:"source" validate:"required"` + + // The status of the backup policy job. + // + // The enumerated values for this property will expand in the future. When processing this property, check for and log + // unknown values. Optionally halt processing and surface the error, or bypass the backup policy job on which the + // unexpected property value was encountered. + Status *string `json:"status" validate:"required"` + + // The reasons for the current status (if any). + // + // The enumerated reason code values for this property will expand in the future. When processing this property, check + // for and log unknown values. Optionally halt processing and surface the error, or bypass the resource on which the + // unexpected reason code was encountered. + StatusReasons []BackupPolicyJobStatusReason `json:"status_reasons" validate:"required"` + + // The snapshots operated on by this backup policy job (may be + // [deleted](https://cloud.ibm.com/apidocs/vpc#deleted-resources)). + TargetSnapshots []SnapshotReference `json:"target_snapshots" validate:"required"` +} + +// Constants associated with the BackupPolicyJob.JobType property. +// The type of backup policy job. +// +// The enumerated values for this property will expand in the future. When processing this property, check for and log +// unknown values. Optionally halt processing and surface the error, or bypass the backup policy job on which the +// unexpected property value was encountered. +const ( + BackupPolicyJobJobTypeCreationConst = "creation" + BackupPolicyJobJobTypeDeletionConst = "deletion" +) + +// Constants associated with the BackupPolicyJob.ResourceType property. +// The resource type. +const ( + BackupPolicyJobResourceTypeBackupPolicyJobConst = "backup_policy_job" +) + +// Constants associated with the BackupPolicyJob.Status property. +// The status of the backup policy job. +// +// The enumerated values for this property will expand in the future. When processing this property, check for and log +// unknown values. Optionally halt processing and surface the error, or bypass the backup policy job on which the +// unexpected property value was encountered. +const ( + BackupPolicyJobStatusFailedConst = "failed" + BackupPolicyJobStatusRunningConst = "running" + BackupPolicyJobStatusSucceededConst = "succeeded" +) + +// UnmarshalBackupPolicyJob unmarshals an instance of BackupPolicyJob from the specified map of raw messages. +func UnmarshalBackupPolicyJob(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(BackupPolicyJob) + err = core.UnmarshalPrimitive(m, "auto_delete", &obj.AutoDelete) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "auto_delete_after", &obj.AutoDeleteAfter) + if err != nil { + return + } + err = core.UnmarshalModel(m, "backup_policy_plan", &obj.BackupPolicyPlan, UnmarshalBackupPolicyPlanReference) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "completed_at", &obj.CompletedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "job_type", &obj.JobType) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "resource_type", &obj.ResourceType) + if err != nil { + return + } + err = core.UnmarshalModel(m, "source", &obj.Source, UnmarshalBackupPolicyJobSource) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "status", &obj.Status) + if err != nil { + return + } + err = core.UnmarshalModel(m, "status_reasons", &obj.StatusReasons, UnmarshalBackupPolicyJobStatusReason) + if err != nil { + return + } + err = core.UnmarshalModel(m, "target_snapshots", &obj.TargetSnapshots, UnmarshalSnapshotReference) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// BackupPolicyJobCollection : BackupPolicyJobCollection struct +type BackupPolicyJobCollection struct { + // A link to the first page of resources. + First *BackupPolicyJobCollectionFirst `json:"first" validate:"required"` + + // Collection of backup policy jobs. + Jobs []BackupPolicyJob `json:"jobs" validate:"required"` + + // The maximum number of resources that can be returned by the request. + Limit *int64 `json:"limit" validate:"required"` + + // A link to the next page of resources. This property is present for all pages + // except the last page. + Next *BackupPolicyJobCollectionNext `json:"next,omitempty"` + + // The total number of resources across all pages. + TotalCount *int64 `json:"total_count" validate:"required"` +} + +// UnmarshalBackupPolicyJobCollection unmarshals an instance of BackupPolicyJobCollection from the specified map of raw messages. +func UnmarshalBackupPolicyJobCollection(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(BackupPolicyJobCollection) + err = core.UnmarshalModel(m, "first", &obj.First, UnmarshalBackupPolicyJobCollectionFirst) + if err != nil { + return + } + err = core.UnmarshalModel(m, "jobs", &obj.Jobs, UnmarshalBackupPolicyJob) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "limit", &obj.Limit) + if err != nil { + return + } + err = core.UnmarshalModel(m, "next", &obj.Next, UnmarshalBackupPolicyJobCollectionNext) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// Retrieve the value to be passed to a request to access the next page of results +func (resp *BackupPolicyJobCollection) GetNextStart() (*string, error) { + if core.IsNil(resp.Next) { + return nil, nil + } + start, err := core.GetQueryParam(resp.Next.Href, "start") + if err != nil || start == nil { + return nil, err + } + return start, nil +} + +// BackupPolicyJobCollectionFirst : A link to the first page of resources. +type BackupPolicyJobCollectionFirst struct { + // The URL for a page of resources. + Href *string `json:"href" validate:"required"` +} + +// UnmarshalBackupPolicyJobCollectionFirst unmarshals an instance of BackupPolicyJobCollectionFirst from the specified map of raw messages. +func UnmarshalBackupPolicyJobCollectionFirst(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(BackupPolicyJobCollectionFirst) + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// BackupPolicyJobCollectionNext : A link to the next page of resources. This property is present for all pages except the last page. +type BackupPolicyJobCollectionNext struct { + // The URL for a page of resources. + Href *string `json:"href" validate:"required"` +} + +// UnmarshalBackupPolicyJobCollectionNext unmarshals an instance of BackupPolicyJobCollectionNext from the specified map of raw messages. +func UnmarshalBackupPolicyJobCollectionNext(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(BackupPolicyJobCollectionNext) + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// BackupPolicyJobSource : The source this backup was created from (may be +// [deleted](https://cloud.ibm.com/apidocs/vpc#deleted-resources)). +// Models which "extend" this model: +// - BackupPolicyJobSourceVolumeReference +type BackupPolicyJobSource struct { + // The CRN for this volume. + CRN *string `json:"crn,omitempty"` + + // If present, this property indicates the referenced resource has been deleted, and provides + // some supplementary information. + Deleted *VolumeReferenceDeleted `json:"deleted,omitempty"` + + // The URL for this volume. + Href *string `json:"href,omitempty"` + + // The unique identifier for this volume. + ID *string `json:"id,omitempty"` + + // The name for this volume. The name is unique across all volumes in the region. + Name *string `json:"name,omitempty"` +} + +func (*BackupPolicyJobSource) isaBackupPolicyJobSource() bool { + return true +} + +type BackupPolicyJobSourceIntf interface { + isaBackupPolicyJobSource() bool +} + +// UnmarshalBackupPolicyJobSource unmarshals an instance of BackupPolicyJobSource from the specified map of raw messages. +func UnmarshalBackupPolicyJobSource(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(BackupPolicyJobSource) + err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) + if err != nil { + return + } + err = core.UnmarshalModel(m, "deleted", &obj.Deleted, UnmarshalVolumeReferenceDeleted) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// BackupPolicyJobStatusReason : BackupPolicyJobStatusReason struct +type BackupPolicyJobStatusReason struct { + // A snake case string succinctly identifying the status reason: + // - `internal_error`: Internal error (contact IBM support) + // - `snapshot_pending`: Cannot delete backup (snapshot) in the `pending` lifecycle state + // - `snapshot_volume_limit`: The snapshot limit for the source volume has been reached + // - `source_volume_busy`: The source volume has `busy` set (after multiple retries). + Code *string `json:"code" validate:"required"` + + // An explanation of the status reason. + Message *string `json:"message" validate:"required"` + + // Link to documentation about this status reason. + MoreInfo *string `json:"more_info,omitempty"` +} + +// Constants associated with the BackupPolicyJobStatusReason.Code property. +// A snake case string succinctly identifying the status reason: +// - `internal_error`: Internal error (contact IBM support) +// - `snapshot_pending`: Cannot delete backup (snapshot) in the `pending` lifecycle state +// - `snapshot_volume_limit`: The snapshot limit for the source volume has been reached +// - `source_volume_busy`: The source volume has `busy` set (after multiple retries). +const ( + BackupPolicyJobStatusReasonCodeInternalErrorConst = "internal_error" + BackupPolicyJobStatusReasonCodeSnapshotPendingConst = "snapshot_pending" + BackupPolicyJobStatusReasonCodeSnapshotVolumeLimitConst = "snapshot_volume_limit" + BackupPolicyJobStatusReasonCodeSourceVolumeBusyConst = "source_volume_busy" +) + +// UnmarshalBackupPolicyJobStatusReason unmarshals an instance of BackupPolicyJobStatusReason from the specified map of raw messages. +func UnmarshalBackupPolicyJobStatusReason(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(BackupPolicyJobStatusReason) + err = core.UnmarshalPrimitive(m, "code", &obj.Code) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "message", &obj.Message) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "more_info", &obj.MoreInfo) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // BackupPolicyPatch : BackupPolicyPatch struct type BackupPolicyPatch struct { // The user tags this backup policy applies to (replacing any existing tags). Resources that have both a matching user @@ -33724,6 +34222,44 @@ func UnmarshalGenericResourceReferenceDeleted(m map[string]json.RawMessage, resu return } +// GetBackupPolicyJobOptions : The GetBackupPolicyJob options. +type GetBackupPolicyJobOptions struct { + // The backup policy identifier. + BackupPolicyID *string `json:"backup_policy_id" validate:"required,ne="` + + // The backup policy job identifier. + ID *string `json:"id" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetBackupPolicyJobOptions : Instantiate GetBackupPolicyJobOptions +func (*VpcV1) NewGetBackupPolicyJobOptions(backupPolicyID string, id string) *GetBackupPolicyJobOptions { + return &GetBackupPolicyJobOptions{ + BackupPolicyID: core.StringPtr(backupPolicyID), + ID: core.StringPtr(id), + } +} + +// SetBackupPolicyID : Allow user to set BackupPolicyID +func (_options *GetBackupPolicyJobOptions) SetBackupPolicyID(backupPolicyID string) *GetBackupPolicyJobOptions { + _options.BackupPolicyID = core.StringPtr(backupPolicyID) + return _options +} + +// SetID : Allow user to set ID +func (_options *GetBackupPolicyJobOptions) SetID(id string) *GetBackupPolicyJobOptions { + _options.ID = core.StringPtr(id) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetBackupPolicyJobOptions) SetHeaders(param map[string]string) *GetBackupPolicyJobOptions { + options.Headers = param + return options +} + // GetBackupPolicyOptions : The GetBackupPolicy options. type GetBackupPolicyOptions struct { // The backup policy identifier. @@ -43656,6 +44192,117 @@ func (options *ListBackupPoliciesOptions) SetHeaders(param map[string]string) *L return options } +// ListBackupPolicyJobsOptions : The ListBackupPolicyJobs options. +type ListBackupPolicyJobsOptions struct { + // The backup policy identifier. + BackupPolicyID *string `json:"backup_policy_id" validate:"required,ne="` + + // Filters the collection to backup policy jobs with the specified status. + Status *string `json:"status,omitempty"` + + // Filters the collection to backup policy jobs with the backup plan with the specified identifier. + BackupPolicyPlanID *string `json:"backup_policy_plan.id,omitempty"` + + // A server-provided token determining what resource to start the page on. + Start *string `json:"start,omitempty"` + + // The number of resources to return on a page. + Limit *int64 `json:"limit,omitempty"` + + // Sorts the returned collection by the specified property name in ascending order. A `-` may be prepended to the name + // to sort in descending order. For example, the value `-created_at` sorts the collection by the `created_at` property + // in descending order, and the value `name` sorts it by the `name` property in ascending order. + Sort *string `json:"sort,omitempty"` + + // Filters the collection to backup policy jobs with a source with the specified identifier. + SourceID *string `json:"source.id,omitempty"` + + // Filters the collection to resources with the target snapshot with the specified identifier. + TargetSnapshotsID *string `json:"target_snapshots[].id,omitempty"` + + // Filters the collection to backup policy jobs with the target snapshot with the specified CRN. + TargetSnapshotsCRN *string `json:"target_snapshots[].crn,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// Constants associated with the ListBackupPolicyJobsOptions.Sort property. +// Sorts the returned collection by the specified property name in ascending order. A `-` may be prepended to the name +// to sort in descending order. For example, the value `-created_at` sorts the collection by the `created_at` property +// in descending order, and the value `name` sorts it by the `name` property in ascending order. +const ( + ListBackupPolicyJobsOptionsSortCreatedAtConst = "created_at" + ListBackupPolicyJobsOptionsSortNameConst = "name" +) + +// NewListBackupPolicyJobsOptions : Instantiate ListBackupPolicyJobsOptions +func (*VpcV1) NewListBackupPolicyJobsOptions(backupPolicyID string) *ListBackupPolicyJobsOptions { + return &ListBackupPolicyJobsOptions{ + BackupPolicyID: core.StringPtr(backupPolicyID), + } +} + +// SetBackupPolicyID : Allow user to set BackupPolicyID +func (_options *ListBackupPolicyJobsOptions) SetBackupPolicyID(backupPolicyID string) *ListBackupPolicyJobsOptions { + _options.BackupPolicyID = core.StringPtr(backupPolicyID) + return _options +} + +// SetStatus : Allow user to set Status +func (_options *ListBackupPolicyJobsOptions) SetStatus(status string) *ListBackupPolicyJobsOptions { + _options.Status = core.StringPtr(status) + return _options +} + +// SetBackupPolicyPlanID : Allow user to set BackupPolicyPlanID +func (_options *ListBackupPolicyJobsOptions) SetBackupPolicyPlanID(backupPolicyPlanID string) *ListBackupPolicyJobsOptions { + _options.BackupPolicyPlanID = core.StringPtr(backupPolicyPlanID) + return _options +} + +// SetStart : Allow user to set Start +func (_options *ListBackupPolicyJobsOptions) SetStart(start string) *ListBackupPolicyJobsOptions { + _options.Start = core.StringPtr(start) + return _options +} + +// SetLimit : Allow user to set Limit +func (_options *ListBackupPolicyJobsOptions) SetLimit(limit int64) *ListBackupPolicyJobsOptions { + _options.Limit = core.Int64Ptr(limit) + return _options +} + +// SetSort : Allow user to set Sort +func (_options *ListBackupPolicyJobsOptions) SetSort(sort string) *ListBackupPolicyJobsOptions { + _options.Sort = core.StringPtr(sort) + return _options +} + +// SetSourceID : Allow user to set SourceID +func (_options *ListBackupPolicyJobsOptions) SetSourceID(sourceID string) *ListBackupPolicyJobsOptions { + _options.SourceID = core.StringPtr(sourceID) + return _options +} + +// SetTargetSnapshotsID : Allow user to set TargetSnapshotsID +func (_options *ListBackupPolicyJobsOptions) SetTargetSnapshotsID(targetSnapshotsID string) *ListBackupPolicyJobsOptions { + _options.TargetSnapshotsID = core.StringPtr(targetSnapshotsID) + return _options +} + +// SetTargetSnapshotsCRN : Allow user to set TargetSnapshotsCRN +func (_options *ListBackupPolicyJobsOptions) SetTargetSnapshotsCRN(targetSnapshotsCRN string) *ListBackupPolicyJobsOptions { + _options.TargetSnapshotsCRN = core.StringPtr(targetSnapshotsCRN) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *ListBackupPolicyJobsOptions) SetHeaders(param map[string]string) *ListBackupPolicyJobsOptions { + options.Headers = param + return options +} + // ListBackupPolicyPlansOptions : The ListBackupPolicyPlans options. type ListBackupPolicyPlansOptions struct { // The backup policy identifier. @@ -64377,6 +65024,57 @@ func UnmarshalZoneReference(m map[string]json.RawMessage, result interface{}) (e return } +// BackupPolicyJobSourceVolumeReference : BackupPolicyJobSourceVolumeReference struct +// This model "extends" BackupPolicyJobSource +type BackupPolicyJobSourceVolumeReference struct { + // The CRN for this volume. + CRN *string `json:"crn" validate:"required"` + + // If present, this property indicates the referenced resource has been deleted, and provides + // some supplementary information. + Deleted *VolumeReferenceDeleted `json:"deleted,omitempty"` + + // The URL for this volume. + Href *string `json:"href" validate:"required"` + + // The unique identifier for this volume. + ID *string `json:"id" validate:"required"` + + // The name for this volume. The name is unique across all volumes in the region. + Name *string `json:"name" validate:"required"` +} + +func (*BackupPolicyJobSourceVolumeReference) isaBackupPolicyJobSource() bool { + return true +} + +// UnmarshalBackupPolicyJobSourceVolumeReference unmarshals an instance of BackupPolicyJobSourceVolumeReference from the specified map of raw messages. +func UnmarshalBackupPolicyJobSourceVolumeReference(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(BackupPolicyJobSourceVolumeReference) + err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) + if err != nil { + return + } + err = core.UnmarshalModel(m, "deleted", &obj.Deleted, UnmarshalVolumeReferenceDeleted) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // BareMetalServerBootTargetBareMetalServerDiskReference : BareMetalServerBootTargetBareMetalServerDiskReference struct // This model "extends" BareMetalServerBootTarget type BareMetalServerBootTargetBareMetalServerDiskReference struct { @@ -85912,6 +86610,91 @@ func (pager *BackupPoliciesPager) GetAll() (allItems []BackupPolicy, err error) return pager.GetAllWithContext(context.Background()) } +// BackupPolicyJobsPager can be used to simplify the use of the "ListBackupPolicyJobs" method. +type BackupPolicyJobsPager struct { + hasNext bool + options *ListBackupPolicyJobsOptions + client *VpcV1 + pageContext struct { + next *string + } +} + +// NewBackupPolicyJobsPager returns a new BackupPolicyJobsPager instance. +func (vpc *VpcV1) NewBackupPolicyJobsPager(options *ListBackupPolicyJobsOptions) (pager *BackupPolicyJobsPager, err error) { + if options.Start != nil && *options.Start != "" { + err = fmt.Errorf("the 'options.Start' field should not be set") + return + } + + var optionsCopy ListBackupPolicyJobsOptions = *options + pager = &BackupPolicyJobsPager{ + hasNext: true, + options: &optionsCopy, + client: vpc, + } + return +} + +// HasNext returns true if there are potentially more results to be retrieved. +func (pager *BackupPolicyJobsPager) HasNext() bool { + return pager.hasNext +} + +// GetNextWithContext returns the next page of results using the specified Context. +func (pager *BackupPolicyJobsPager) GetNextWithContext(ctx context.Context) (page []BackupPolicyJob, err error) { + if !pager.HasNext() { + return nil, fmt.Errorf("no more results available") + } + + pager.options.Start = pager.pageContext.next + + result, _, err := pager.client.ListBackupPolicyJobsWithContext(ctx, pager.options) + if err != nil { + return + } + + var next *string + if result.Next != nil { + var start *string + start, err = core.GetQueryParam(result.Next.Href, "start") + if err != nil { + err = fmt.Errorf("error retrieving 'start' query parameter from URL '%s': %s", *result.Next.Href, err.Error()) + return + } + next = start + } + pager.pageContext.next = next + pager.hasNext = (pager.pageContext.next != nil) + page = result.Jobs + + return +} + +// GetAllWithContext returns all results by invoking GetNextWithContext() repeatedly +// until all pages of results have been retrieved. +func (pager *BackupPolicyJobsPager) GetAllWithContext(ctx context.Context) (allItems []BackupPolicyJob, err error) { + for pager.HasNext() { + var nextPage []BackupPolicyJob + nextPage, err = pager.GetNextWithContext(ctx) + if err != nil { + return + } + allItems = append(allItems, nextPage...) + } + return +} + +// GetNext invokes GetNextWithContext() using context.Background() as the Context parameter. +func (pager *BackupPolicyJobsPager) GetNext() (page []BackupPolicyJob, err error) { + return pager.GetNextWithContext(context.Background()) +} + +// GetAll invokes GetAllWithContext() using context.Background() as the Context parameter. +func (pager *BackupPolicyJobsPager) GetAll() (allItems []BackupPolicyJob, err error) { + return pager.GetAllWithContext(context.Background()) +} + // PlacementGroupsPager can be used to simplify the use of the "ListPlacementGroups" method. type PlacementGroupsPager struct { hasNext bool diff --git a/vpcv1/vpc_v1_examples_test.go b/vpcv1/vpc_v1_examples_test.go index f8f86d1..79445d0 100644 --- a/vpcv1/vpc_v1_examples_test.go +++ b/vpcv1/vpc_v1_examples_test.go @@ -178,15 +178,25 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { // begin-list_vpcs listVpcsOptions := &vpcv1.ListVpcsOptions{} - vpcs, response, err := vpcService.ListVpcs(listVpcsOptions) - // end-list_vpcs + pager, err := vpcService.NewVpcsPager(listVpcsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.VPC + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_vpcs + Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(vpcs).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateVPC request example`, func() { @@ -310,18 +320,26 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { It(`ListVPCAddressPrefixes request example`, func() { fmt.Println("\nListVPCAddressPrefixes() result:") // begin-list_vpc_address_prefixes - listVpcAddressPrefixesOptions := &vpcv1.ListVPCAddressPrefixesOptions{} - listVpcAddressPrefixesOptions.SetVPCID(vpcID) - addressPrefixes, response, err := - vpcService.ListVPCAddressPrefixes(listVpcAddressPrefixesOptions) + listVPCAddressPrefixesOptions := &vpcv1.ListVPCAddressPrefixesOptions{} + listVPCAddressPrefixesOptions.SetVPCID(vpcID) - // end-list_vpc_address_prefixes + pager, err := vpcService.NewVPCAddressPrefixesPager(listVPCAddressPrefixesOptions) if err != nil { panic(err) } + + var allResults []vpcv1.AddressPrefix + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_vpc_address_prefixes + Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(addressPrefixes).ToNot(BeNil()) }) It(`CreateVPCAddressPrefix request example`, func() { @@ -395,16 +413,25 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListVPCRoutingTables() result:") // begin-list_vpc_routing_tables - options := vpcService.NewListVPCRoutingTablesOptions(vpcID) - routingTableCollection, response, err := vpcService.ListVPCRoutingTables(options) + listVPCRoutingTablesOptions := vpcService.NewListVPCRoutingTablesOptions(vpcID) - // end-list_vpc_routing_tables + pager, err := vpcService.NewVPCRoutingTablesPager(listVPCRoutingTablesOptions) if err != nil { panic(err) } + + var allResults []vpcv1.RoutingTable + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + // end-list_vpc_routing_tables + Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(routingTableCollection).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateVPCRoutingTable request example`, func() { @@ -488,19 +515,28 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListVPCRoutingTableRoutes() result:") // begin-list_vpc_routing_table_routes - options := vpcService.NewListVPCRoutingTableRoutesOptions( + listVPCRoutingTableRoutesOptions := vpcService.NewListVPCRoutingTableRoutesOptions( vpcID, routingTableID, ) - routeCollection, response, err := vpcService.ListVPCRoutingTableRoutes(options) - // end-list_vpc_routing_table_routes + pager, err := vpcService.NewVPCRoutingTableRoutesPager(listVPCRoutingTableRoutesOptions) if err != nil { panic(err) } + + var allResults []vpcv1.Route + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_vpc_routing_table_routes + Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(routeCollection).ToNot(BeNil()) }) It(`CreateVPCRoutingTableRoute request example`, func() { @@ -584,14 +620,26 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListSubnets() result:") // begin-list_subnets - options := &vpcv1.ListSubnetsOptions{} - subnets, response, err := vpcService.ListSubnets(options) + listSubnetsOptions := &vpcv1.ListSubnetsOptions{} + + pager, err := vpcService.NewSubnetsPager(listSubnetsOptions) + if err != nil { + panic(err) + } + + var allResults []vpcv1.Subnet + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } // end-list_subnets Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(subnets).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateSubnet request example`, func() { @@ -831,16 +879,26 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListSubnetReservedIps() result:") // begin-list_subnet_reserved_ips - options := vpcService.NewListSubnetReservedIpsOptions(subnetID) - reservedIPCollection, response, err := vpcService.ListSubnetReservedIps(options) + listSubnetReservedIpsOptions := vpcService.NewListSubnetReservedIpsOptions(subnetID) - // end-list_subnet_reserved_ips + pager, err := vpcService.NewSubnetReservedIpsPager(listSubnetReservedIpsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.ReservedIP + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_subnet_reserved_ips + Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(reservedIPCollection).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateSubnetReservedIP request example`, func() { @@ -939,17 +997,28 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { It(`ListImages request example`, func() { fmt.Println("\nListImages() result:") // begin-list_images - options := &vpcv1.ListImagesOptions{} - options.SetVisibility("private") - images, response, err := vpcService.ListImages(options) + listImagesOptions := &vpcv1.ListImagesOptions{} + listImagesOptions.SetVisibility("public") - // end-list_images + pager, err := vpcService.NewImagesPager(listImagesOptions) if err != nil { panic(err) } + + var allResults []vpcv1.Image + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_images + Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(images).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) + }) It(`CreateImage request example`, func() { fmt.Println("\nCreateImage() result:") @@ -1023,17 +1092,27 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListOperatingSystems() result:") // begin-list_operating_systems - options := &vpcv1.ListOperatingSystemsOptions{} - operatingSystems, response, err := vpcService.ListOperatingSystems(options) + listOperatingSystemsOptions := &vpcv1.ListOperatingSystemsOptions{} - // end-list_operating_systems + pager, err := vpcService.NewOperatingSystemsPager(listOperatingSystemsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.OperatingSystem + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_operating_systems + Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(operatingSystems).ToNot(BeNil()) - operatingSystemName = *operatingSystems.OperatingSystems[0].Name + Expect(allResults).ShouldNot(BeEmpty()) + operatingSystemName = *allResults[0].Name }) It(`GetOperatingSystem request example`, func() { fmt.Println("\nGetOperatingSystem() result:") @@ -1057,13 +1136,25 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { // begin-list_keys listKeysOptions := &vpcv1.ListKeysOptions{} - keys, response, err := vpcService.ListKeys(listKeysOptions) + + pager, err := vpcService.NewKeysPager(listKeysOptions) + if err != nil { + panic(err) + } + + var allResults []vpcv1.Key + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } // end-list_keys Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(keys).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateKey request example`, func() { @@ -1126,16 +1217,27 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListFloatingIps() result:") // begin-list_floating_ips listFloatingIpsOptions := vpcService.NewListFloatingIpsOptions() - floatingIPs, response, err := - vpcService.ListFloatingIps(listFloatingIpsOptions) + + pager, err := vpcService.NewFloatingIpsPager(listFloatingIpsOptions) + if err != nil { + panic(err) + } + + var allResults []vpcv1.FloatingIP + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } // end-list_floating_ips if err != nil { panic(err) } Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(floatingIPs).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateFloatingIP request example`, func() { @@ -1210,16 +1312,28 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListVolumes() result:") // begin-list_volumes - options := &vpcv1.ListVolumesOptions{} - volumes, response, err := vpcService.ListVolumes(options) + listVolumesOptions := &vpcv1.ListVolumesOptions{} + + pager, err := vpcService.NewVolumesPager(listVolumesOptions) + if err != nil { + panic(err) + } + + var allResults []vpcv1.Volume + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } // end-list_volumes if err != nil { panic(err) } Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(volumes).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateVolume request example`, func() { @@ -1430,16 +1544,28 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListInstances() result:") // begin-list_instances - options := &vpcv1.ListInstancesOptions{} - instances, response, err := vpcService.ListInstances(options) + listInstancesOptions := &vpcv1.ListInstancesOptions{} + + pager, err := vpcService.NewInstancesPager(listInstancesOptions) + if err != nil { + panic(err) + } + + var allResults []vpcv1.Instance + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } // end-list_instances if err != nil { panic(err) } Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(instances).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateInstance request example`, func() { @@ -1818,6 +1944,55 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { }) + It(`ListInstanceNetworkInterfaceIps request example`, func() { + fmt.Println("\nListInstanceNetworkInterfaceIps() result:") + // begin-list_instance_network_interface_ips + listInstanceNetworkInterfaceIpsOptions := &vpcv1.ListInstanceNetworkInterfaceIpsOptions{ + InstanceID: &instanceID, + NetworkInterfaceID: ð2ID, + } + + pager, err := vpcService.NewInstanceNetworkInterfaceIpsPager(listInstanceNetworkInterfaceIpsOptions) + if err != nil { + panic(err) + } + + var allResults []vpcv1.ReservedIP + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + // end-list_instance_network_interface_ips + reservedIPID2 = *allResults[0].ID + Expect(err).To(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) + }) + + It(`GetInstanceNetworkInterfaceIP request example`, func() { + fmt.Println("\nGetInstanceNetworkInterfaceIP() result:") + // begin-get_instance_network_interface_ip + + getInstanceNetworkInterfaceIPOptions := vpcService.NewGetInstanceNetworkInterfaceIPOptions( + instanceID, + eth2ID, + reservedIPID2, + ) + + reservedIP, response, err := vpcService.GetInstanceNetworkInterfaceIP(getInstanceNetworkInterfaceIPOptions) + if err != nil { + panic(err) + } + + // end-get_instance_network_interface_ip + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(reservedIP).ToNot(BeNil()) + }) + It(`ListInstanceVolumeAttachments request example`, func() { fmt.Println("\nListInstanceVolumeAttachments() result:") // begin-list_instance_volume_attachments @@ -1909,16 +2084,26 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListInstanceGroups() result:") // begin-list_instance_groups - options := &vpcv1.ListInstanceGroupsOptions{} - instanceGroups, response, err := vpcService.ListInstanceGroups(options) + listInstanceGroupsOptions := &vpcv1.ListInstanceGroupsOptions{} - // end-list_instance_groups + pager, err := vpcService.NewInstanceGroupsPager(listInstanceGroupsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.InstanceGroup + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_instance_groups + Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(instanceGroups).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateInstanceGroup request example`, func() { @@ -1999,18 +2184,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListInstanceGroupManagers() result:") // begin-list_instance_group_managers - options := &vpcv1.ListInstanceGroupManagersOptions{} - options.SetInstanceGroupID(instanceGroupID) - instanceGroupManagers, response, err := - vpcService.ListInstanceGroupManagers(options) - - // end-list_instance_group_managers + listInstanceGroupManagersOptions := &vpcv1.ListInstanceGroupManagersOptions{} + listInstanceGroupManagersOptions.SetInstanceGroupID(instanceGroupID) + pager, err := vpcService.NewInstanceGroupManagersPager(listInstanceGroupManagersOptions) if err != nil { panic(err) } + + var allResults []vpcv1.InstanceGroupManagerIntf + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_instance_group_managers Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(instanceGroupManagers).ToNot(BeNil()) }) It(`CreateInstanceGroupManager request example`, func() { @@ -2085,19 +2276,25 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListInstanceGroupManagerActions() result:") // begin-list_instance_group_manager_actions - options := &vpcv1.ListInstanceGroupManagerActionsOptions{} - options.SetInstanceGroupID(instanceGroupID) - options.SetInstanceGroupManagerID(instanceGroupManagerID) - instanceGroupManagerActions, response, err := - vpcService.ListInstanceGroupManagerActions(options) - - // end-list_instance_group_manager_actions + listInstanceGroupManagerActionsOptions := &vpcv1.ListInstanceGroupManagerActionsOptions{} + listInstanceGroupManagerActionsOptions.SetInstanceGroupID(instanceGroupID) + listInstanceGroupManagerActionsOptions.SetInstanceGroupManagerID(instanceGroupManagerID) + pager, err := vpcService.NewInstanceGroupManagerActionsPager(listInstanceGroupManagerActionsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.InstanceGroupManagerActionIntf + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_instance_group_manager_actions Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(instanceGroupManagerActions).ToNot(BeNil()) }) It(`CreateInstanceGroupManagerAction request example`, func() { @@ -2199,19 +2396,25 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListInstanceGroupManagerPolicies() result:") // begin-list_instance_group_manager_policies - options := &vpcv1.ListInstanceGroupManagerPoliciesOptions{} - options.SetInstanceGroupID(instanceGroupID) - options.SetInstanceGroupManagerID(instanceGroupManagerID) - instanceGroupManagerPolicies, response, err := - vpcService.ListInstanceGroupManagerPolicies(options) - - // end-list_instance_group_manager_policies + listInstanceGroupManagerPoliciesOptions := &vpcv1.ListInstanceGroupManagerPoliciesOptions{} + listInstanceGroupManagerPoliciesOptions.SetInstanceGroupID(instanceGroupID) + listInstanceGroupManagerPoliciesOptions.SetInstanceGroupManagerID(instanceGroupManagerID) + pager, err := vpcService.NewInstanceGroupManagerPoliciesPager(listInstanceGroupManagerPoliciesOptions) if err != nil { panic(err) } + + var allResults []vpcv1.InstanceGroupManagerPolicyIntf + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_instance_group_manager_policies Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(instanceGroupManagerPolicies).ToNot(BeNil()) }) It(`CreateInstanceGroupManagerPolicy request example`, func() { @@ -2295,19 +2498,26 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListInstanceGroupMemberships() result:") // begin-list_instance_group_memberships - options := &vpcv1.ListInstanceGroupMembershipsOptions{} - options.SetInstanceGroupID(instanceGroupID) - instanceGroupMemberships, response, err := - vpcService.ListInstanceGroupMemberships(options) - - // end-list_instance_group_memberships + listInstanceGroupMembershipsOptions := &vpcv1.ListInstanceGroupMembershipsOptions{} + listInstanceGroupMembershipsOptions.SetInstanceGroupID(instanceGroupID) + pager, err := vpcService.NewInstanceGroupMembershipsPager(listInstanceGroupMembershipsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.InstanceGroupMembership + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_instance_group_memberships Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(instanceGroupMemberships).ToNot(BeNil()) - instanceGroupMembershipID = *instanceGroupMemberships.Memberships[0].ID + Expect(allResults).ShouldNot(BeEmpty()) + instanceGroupMembershipID = *allResults[0].ID }) It(`GetInstanceGroupMembership request example`, func() { fmt.Println("\nGetInstanceGroupMembership() result:") @@ -2359,17 +2569,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListDedicatedHostGroups() result:") // begin-list_dedicated_host_groups - options := vpcService.NewListDedicatedHostGroupsOptions() - dedicatedHostGroups, response, err := - vpcService.ListDedicatedHostGroups(options) - - // end-list_dedicated_host_groups + listDedicatedHostGroupsOptions := vpcService.NewListDedicatedHostGroupsOptions() + pager, err := vpcService.NewDedicatedHostGroupsPager(listDedicatedHostGroupsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.DedicatedHostGroup + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_dedicated_host_groups Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(dedicatedHostGroups).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateDedicatedHostGroup request example`, func() { @@ -2445,17 +2662,25 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListDedicatedHostProfiles() result:") // begin-list_dedicated_host_profiles - options := &vpcv1.ListDedicatedHostProfilesOptions{} - profiles, response, err := vpcService.ListDedicatedHostProfiles(options) - - // end-list_dedicated_host_profiles + listDedicatedHostProfilesOptions := &vpcv1.ListDedicatedHostProfilesOptions{} + pager, err := vpcService.NewDedicatedHostProfilesPager(listDedicatedHostProfilesOptions) if err != nil { panic(err) } + + var allResults []vpcv1.DedicatedHostProfile + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_dedicated_host_profiles Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(profiles).ToNot(BeNil()) - dhProfile = *profiles.Profiles[0].Name + Expect(allResults).ShouldNot(BeEmpty()) + dhProfile = *allResults[0].Name }) It(`GetDedicatedHostProfile request example`, func() { fmt.Println("\nGetDedicatedHostProfile() result:") @@ -2478,17 +2703,25 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListDedicatedHosts() result:") // begin-list_dedicated_hosts - options := vpcService.NewListDedicatedHostsOptions() - dedicatedHosts, response, err := - vpcService.ListDedicatedHosts(options) + listDedicatedHostsOptions := vpcService.NewListDedicatedHostsOptions() - // end-list_dedicated_hosts + pager, err := vpcService.NewDedicatedHostsPager(listDedicatedHostsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.DedicatedHost + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_dedicated_hosts Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(dedicatedHosts).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateDedicatedHost request example`, func() { @@ -2638,16 +2871,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListVolumeProfiles() result:") // begin-list_volume_profiles - options := &vpcv1.ListVolumeProfilesOptions{} - profiles, response, err := vpcService.ListVolumeProfiles(options) - - // end-list_volume_profiles + listVolumeProfilesOptions := &vpcv1.ListVolumeProfilesOptions{} + pager, err := vpcService.NewVolumeProfilesPager(listVolumeProfilesOptions) if err != nil { panic(err) } + + var allResults []vpcv1.VolumeProfile + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_volume_profiles Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(profiles).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`GetVolumeProfile request example`, func() { @@ -2672,16 +2913,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListSnapshots() result:") // begin-list_snapshots - options := &vpcv1.ListSnapshotsOptions{} - snapshotCollection, response, err := vpcService.ListSnapshots(options) - - // end-list_snapshots + listSnapshotsOptions := &vpcv1.ListSnapshotsOptions{} + pager, err := vpcService.NewSnapshotsPager(listSnapshotsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.Snapshot + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_snapshots Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(snapshotCollection).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateSnapshot request example`, func() { @@ -2842,16 +3091,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListPublicGateways() result:") // begin-list_public_gateways - options := &vpcv1.ListPublicGatewaysOptions{} - publicGateways, response, err := vpcService.ListPublicGateways(options) - - // end-list_public_gateways + listPublicGatewaysOptions := &vpcv1.ListPublicGatewaysOptions{} + pager, err := vpcService.NewPublicGatewaysPager(listPublicGatewaysOptions) if err != nil { panic(err) } + + var allResults []vpcv1.PublicGateway + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_public_gateways Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(publicGateways).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreatePublicGateway request example`, func() { @@ -2921,16 +3178,25 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListNetworkAcls() result:") // begin-list_network_acls - options := &vpcv1.ListNetworkAclsOptions{} - networkACLCollection, response, err := vpcService.ListNetworkAcls(options) + listNetworkAclsOptions := &vpcv1.ListNetworkAclsOptions{} - // end-list_network_acls + pager, err := vpcService.NewNetworkAclsPager(listNetworkAclsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.NetworkACL + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_network_acls Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(networkACLCollection).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateNetworkACL request example`, func() { @@ -3001,17 +3267,26 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListNetworkACLRules() result:") // begin-list_network_acl_rules - options := &vpcv1.ListNetworkACLRulesOptions{} - options.SetNetworkACLID(networkACLID) - networkACLRules, response, err := vpcService.ListNetworkACLRules(options) + listNetworkACLRulesOptions := &vpcv1.ListNetworkACLRulesOptions{} + listNetworkACLRulesOptions.SetNetworkACLID(networkACLID) - // end-list_network_acl_rules + pager, err := vpcService.NewNetworkACLRulesPager(listNetworkACLRulesOptions) if err != nil { panic(err) } + + var allResults []vpcv1.NetworkACLRuleItemIntf + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_network_acl_rules Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(networkACLRules).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateNetworkACLRule request example`, func() { @@ -3084,16 +3359,25 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListSecurityGroups() result:") // begin-list_security_groups - options := &vpcv1.ListSecurityGroupsOptions{} - securityGroups, response, err := vpcService.ListSecurityGroups(options) + listSecurityGroupsOptions := &vpcv1.ListSecurityGroupsOptions{} - // end-list_security_groups + pager, err := vpcService.NewSecurityGroupsPager(listSecurityGroupsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.SecurityGroup + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_security_groups Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(securityGroups).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateSecurityGroup request example`, func() { @@ -3245,17 +3529,25 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListSecurityGroupTargets() result:") // begin-list_security_group_targets - options := &vpcv1.ListSecurityGroupTargetsOptions{} - options.SetSecurityGroupID(securityGroupID) - targets, response, err := vpcService.ListSecurityGroupTargets(options) - - // end-list_security_group_targets + listSecurityGroupTargetsOptions := &vpcv1.ListSecurityGroupTargetsOptions{} + listSecurityGroupTargetsOptions.SetSecurityGroupID(securityGroupID) + pager, err := vpcService.NewSecurityGroupTargetsPager(listSecurityGroupTargetsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.SecurityGroupTargetReferenceIntf + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_security_group_targets Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(targets).ToNot(BeNil()) + }) It(`CreateSecurityGroupTargetBinding request example`, func() { fmt.Println("\nCreateSecurityGroupTargetBinding() result:") @@ -3302,16 +3594,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListIkePolicies() result:") // begin-list_ike_policies - options := vpcService.NewListIkePoliciesOptions() - ikePolicies, response, err := vpcService.ListIkePolicies(options) - - // end-list_ike_policies + listIkePoliciesOptions := vpcService.NewListIkePoliciesOptions() + pager, err := vpcService.NewIkePoliciesPager(listIkePoliciesOptions) if err != nil { panic(err) } + + var allResults []vpcv1.IkePolicy + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_ike_policies Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(ikePolicies).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateIkePolicy request example`, func() { @@ -3399,16 +3699,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListIpsecPolicies() result:") // begin-list_ipsec_policies - options := &vpcv1.ListIpsecPoliciesOptions{} - ipsecPolicies, response, err := vpcService.ListIpsecPolicies(options) - - // end-list_ipsec_policies + listIpsecPoliciesOptions := &vpcv1.ListIpsecPoliciesOptions{} + pager, err := vpcService.NewIpsecPoliciesPager(listIpsecPoliciesOptions) if err != nil { panic(err) } + + var allResults []vpcv1.IPsecPolicy + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_ipsec_policies Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(ipsecPolicies).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateIpsecPolicy request example`, func() { @@ -3497,15 +3805,23 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { // begin-list_vpn_gateways listVPNGatewaysOptions := vpcService.NewListVPNGatewaysOptions() - vpnGatewayCollection, response, err := vpcService.ListVPNGateways(listVPNGatewaysOptions) - - // end-list_vpn_gateways + pager, err := vpcService.NewVPNGatewaysPager(listVPNGatewaysOptions) if err != nil { panic(err) } + + var allResults []vpcv1.VPNGatewayIntf + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_vpn_gateways Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(vpnGatewayCollection).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateVPNGateway request example`, func() { @@ -3795,17 +4111,25 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { listBareMetalServerProfilesOptions := vpcService.NewListBareMetalServerProfilesOptions() - bareMetalServerProfileCollection, response, err := vpcService.ListBareMetalServerProfiles(listBareMetalServerProfilesOptions) + pager, err := vpcService.NewBareMetalServerProfilesPager(listBareMetalServerProfilesOptions) if err != nil { panic(err) } + var allResults []vpcv1.BareMetalServerProfile + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + // end-list_bare_metal_server_profiles Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(bareMetalServerProfileCollection).ToNot(BeNil()) - bareMetalServerProfileName = *bareMetalServerProfileCollection.Profiles[0].Name + Expect(allResults).ShouldNot(BeEmpty()) + bareMetalServerProfileName = *allResults[0].Name }) It(`GetBareMetalServerProfile request example`, func() { @@ -3834,16 +4158,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { listBareMetalServersOptions := &vpcv1.ListBareMetalServersOptions{} - bareMetalServerCollection, response, err := vpcService.ListBareMetalServers(listBareMetalServersOptions) + pager, err := vpcService.NewBareMetalServersPager(listBareMetalServersOptions) if err != nil { panic(err) } + var allResults []vpcv1.BareMetalServer + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + // end-list_bare_metal_servers Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(bareMetalServerCollection).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateBareMetalServer request example`, func() { @@ -3998,16 +4330,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { BareMetalServerID: &bareMetalServerId, } - bareMetalServerNetworkInterfaceCollection, response, err := vpcService.ListBareMetalServerNetworkInterfaces(listBareMetalServerNetworkInterfacesOptions) + pager, err := vpcService.NewBareMetalServerNetworkInterfacesPager(listBareMetalServerNetworkInterfacesOptions) if err != nil { panic(err) } + var allResults []vpcv1.BareMetalServerNetworkInterfaceIntf + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + // end-list_bare_metal_server_network_interfaces Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(bareMetalServerNetworkInterfaceCollection).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateBareMetalServerNetworkInterface request example`, func() { @@ -4293,16 +4633,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { listBackupPoliciesOptions := vpcService.NewListBackupPoliciesOptions() - backupPolicyCollection, response, err := vpcService.ListBackupPolicies(listBackupPoliciesOptions) + pager, err := vpcService.NewBackupPoliciesPager(listBackupPoliciesOptions) if err != nil { panic(err) } + var allResults []vpcv1.BackupPolicy + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + // end-list_backup_policies Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(backupPolicyCollection).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateBackupPolicy request example`, func() { @@ -4349,6 +4697,49 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { Expect(backupPolicyPlan).ToNot(BeNil()) }) + It(`ListBackupPolicyJobs request example`, func() { + fmt.Println("\nListBackupPolicyJobs() result:") + // begin-list_backup_policy_jobs + listBackupPolicyJobsOptions := &vpcv1.ListBackupPolicyJobsOptions{ + BackupPolicyID: core.StringPtr(backupPolicyID), + } + + pager, err := vpcService.NewBackupPolicyJobsPager(listBackupPolicyJobsOptions) + if err != nil { + panic(err) + } + + var allResults []vpcv1.BackupPolicyJob + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + // end-list_backup_policy_jobs + backupPolicyJobID = *allResults[0].ID + }) + It(`GetBackupPolicyJob request example`, func() { + fmt.Println("\nGetBackupPolicyJob() result:") + // begin-get_backup_policy_job + + getBackupPolicyJobOptions := vpcService.NewGetBackupPolicyJobOptions( + backupPolicyID, + backupPolicyJobID, + ) + + backupPolicyJob, response, err := vpcService.GetBackupPolicyJob(getBackupPolicyJobOptions) + if err != nil { + panic(err) + } + + // end-get_backup_policy_job + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(backupPolicyJob).ToNot(BeNil()) + }) It(`ListBackupPolicyPlans request example`, func() { fmt.Println("\nListBackupPolicyPlans() result:") // begin-list_backup_policy_plans @@ -4473,16 +4864,25 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListPlacementGroups() result:") // begin-list_placement_groups - options := &vpcv1.ListPlacementGroupsOptions{} - placementGroups, response, err := vpcService.ListPlacementGroups(options) + listPlacementGroupsOptions := &vpcv1.ListPlacementGroupsOptions{} - // end-list_flow_log_collectors + pager, err := vpcService.NewPlacementGroupsPager(listPlacementGroupsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.PlacementGroup + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_flow_log_collectors Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(placementGroups).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreatePlacementGroup request example`, func() { @@ -4582,16 +4982,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { listVPNServersOptions := vpcService.NewListVPNServersOptions() listVPNServersOptions.SetSort("name") - vpnServerCollection, response, err := vpcService.ListVPNServers(listVPNServersOptions) + pager, err := vpcService.NewVPNServersPager(listVPNServersOptions) if err != nil { panic(err) } + var allResults []vpcv1.VPNServer + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + // end-list_vpn_servers Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(vpnServerCollection).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateVPNServer request example`, func() { @@ -4713,16 +5121,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { ) listVPNServerClientsOptions.SetSort("created_at") - vpnServerClientCollection, response, err := vpcService.ListVPNServerClients(listVPNServerClientsOptions) + pager, err := vpcService.NewVPNServerClientsPager(listVPNServerClientsOptions) if err != nil { panic(err) } + var allResults []vpcv1.VPNServerClient + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + // end-list_vpn_server_clients - vpnClientID = *vpnServerClientCollection.Clients[0].ID + vpnClientID = *allResults[0].ID Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(vpnServerClientCollection).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`GetVPNServerClient request example`, func() { @@ -4777,16 +5193,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { ) listVPNServerRoutesOptions.SetSort("name") - vpnServerRouteCollection, response, err := vpcService.ListVPNServerRoutes(listVPNServerRoutesOptions) + pager, err := vpcService.NewVPNServerRoutesPager(listVPNServerRoutesOptions) if err != nil { panic(err) } + var allResults []vpcv1.VPNServerRoute + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + // end-list_vpn_server_routes Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(vpnServerRouteCollection).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateVPNServerRoute request example`, func() { @@ -4864,16 +5288,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListLoadBalancerProfiles() result:") // begin-list_load_balancer_profiles - options := &vpcv1.ListLoadBalancerProfilesOptions{} - profiles, response, err := vpcService.ListLoadBalancerProfiles(options) - - // end-list_load_balancer_profiles + listLoadBalancerProfilesOptions := &vpcv1.ListLoadBalancerProfilesOptions{} + pager, err := vpcService.NewLoadBalancerProfilesPager(listLoadBalancerProfilesOptions) if err != nil { panic(err) } + + var allResults []vpcv1.LoadBalancerProfile + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_load_balancer_profiles Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(profiles).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`GetLoadBalancerProfile request example`, func() { @@ -4895,16 +5327,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListLoadBalancers() result:") // begin-list_load_balancers - options := &vpcv1.ListLoadBalancersOptions{} - loadBalancers, response, err := vpcService.ListLoadBalancers(options) - - // end-list_load_balancers + listLoadBalancersOptions := &vpcv1.ListLoadBalancersOptions{} + pager, err := vpcService.NewLoadBalancersPager(listLoadBalancersOptions) if err != nil { panic(err) } + + var allResults []vpcv1.LoadBalancer + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_load_balancers Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(loadBalancers).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateLoadBalancer request example`, func() { @@ -5582,17 +6022,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListEndpointGateways() result:") // begin-list_endpoint_gateways - options := vpcService.NewListEndpointGatewaysOptions() - endpointGateways, response, err := - vpcService.ListEndpointGateways(options) - - // end-list_endpoint_gateways + listEndpointGatewaysOptions := vpcService.NewListEndpointGatewaysOptions() + pager, err := vpcService.NewEndpointGatewaysPager(listEndpointGatewaysOptions) if err != nil { panic(err) } + + var allResults []vpcv1.EndpointGateway + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_endpoint_gateways Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(endpointGateways).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateEndpointGateway request example`, func() { @@ -5629,16 +6076,23 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListEndpointGatewayIps() result:") // begin-list_endpoint_gateway_ips - options := vpcService.NewListEndpointGatewayIpsOptions(endpointGatewayID) - reservedIPs, response, err := vpcService.ListEndpointGatewayIps(options) - - // end-list_endpoint_gateway_ips + listEndpointGatewayIpsOptions := vpcService.NewListEndpointGatewayIpsOptions(endpointGatewayID) + pager, err := vpcService.NewEndpointGatewayIpsPager(listEndpointGatewayIpsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.ReservedIP + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_endpoint_gateway_ips Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(reservedIPs).ToNot(BeNil()) }) It(`AddEndpointGatewayIP request example`, func() { @@ -5761,16 +6215,24 @@ var _ = Describe(`VpcV1 Examples Tests`, func() { fmt.Println("\nListFlowLogCollectors() result:") // begin-list_flow_log_collectors - options := &vpcv1.ListFlowLogCollectorsOptions{} - flowLogs, response, err := vpcService.ListFlowLogCollectors(options) - - // end-list_flow_log_collectors + listFlowLogCollectorsOptions := &vpcv1.ListFlowLogCollectorsOptions{} + pager, err := vpcService.NewFlowLogCollectorsPager(listFlowLogCollectorsOptions) if err != nil { panic(err) } + + var allResults []vpcv1.FlowLogCollector + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + + // end-list_flow_log_collectors Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(flowLogs).ToNot(BeNil()) + Expect(allResults).ShouldNot(BeEmpty()) }) It(`CreateFlowLogCollector request example`, func() { diff --git a/vpcv1/vpc_v1_test.go b/vpcv1/vpc_v1_test.go index 3b07246..e1e85e0 100644 --- a/vpcv1/vpc_v1_test.go +++ b/vpcv1/vpc_v1_test.go @@ -35044,6 +35044,640 @@ var _ = Describe(`VpcV1`, func() { }) }) }) + Describe(`ListBackupPolicyJobs(listBackupPolicyJobsOptions *ListBackupPolicyJobsOptions) - Operation response error`, func() { + version := "testString" + listBackupPolicyJobsPath := "/backup_policies/testString/jobs" + 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(listBackupPolicyJobsPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["version"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["generation"]).To(Equal([]string{fmt.Sprint(int64(2))})) + Expect(req.URL.Query()["status"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["backup_policy_plan.id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["start"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) + Expect(req.URL.Query()["sort"]).To(Equal([]string{"name"})) + Expect(req.URL.Query()["source.id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["target_snapshots[].id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["target_snapshots[].crn"]).To(Equal([]string{"testString"})) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListBackupPolicyJobs 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 ListBackupPolicyJobsOptions model + listBackupPolicyJobsOptionsModel := new(vpcv1.ListBackupPolicyJobsOptions) + listBackupPolicyJobsOptionsModel.BackupPolicyID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Status = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.BackupPolicyPlanID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Start = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Limit = core.Int64Ptr(int64(10)) + listBackupPolicyJobsOptionsModel.Sort = core.StringPtr("name") + listBackupPolicyJobsOptionsModel.SourceID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.TargetSnapshotsID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.TargetSnapshotsCRN = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.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.ListBackupPolicyJobs(listBackupPolicyJobsOptionsModel) + 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.ListBackupPolicyJobs(listBackupPolicyJobsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListBackupPolicyJobs(listBackupPolicyJobsOptions *ListBackupPolicyJobsOptions)`, func() { + version := "testString" + listBackupPolicyJobsPath := "/backup_policies/testString/jobs" + 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(listBackupPolicyJobsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["version"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["generation"]).To(Equal([]string{fmt.Sprint(int64(2))})) + Expect(req.URL.Query()["status"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["backup_policy_plan.id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["start"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) + Expect(req.URL.Query()["sort"]).To(Equal([]string{"name"})) + Expect(req.URL.Query()["source.id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["target_snapshots[].id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["target_snapshots[].crn"]).To(Equal([]string{"testString"})) + // 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", `{"first": {"href": "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/7241e2a8-601f-11ea-8503-000c29475bed/jobs?limit=20"}, "jobs": [{"auto_delete": true, "auto_delete_after": 90, "backup_policy_plan": {"deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178", "id": "r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178", "name": "my-policy-plan", "resource_type": "backup_policy_plan"}, "completed_at": "2019-01-01T12:00:00.000Z", "created_at": "2019-01-01T12:00:00.000Z", "href": "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/0fe9e5d8-0a4d-4818-96ec-e99708644a58/jobs/4cf9171a-0043-4434-8727-15b53dbc374c", "id": "4cf9171a-0043-4434-8727-15b53dbc374c", "job_type": "creation", "resource_type": "backup_policy_job", "source": {"crn": "crn:v1:bluemix:public:is:us-south-1:a/123456::volume:1a6b7274-678d-4dfb-8981-c71dd9d4daa5", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/volumes/1a6b7274-678d-4dfb-8981-c71dd9d4daa5", "id": "1a6b7274-678d-4dfb-8981-c71dd9d4daa5", "name": "my-volume"}, "status": "failed", "status_reasons": [{"code": "source_volume_busy", "message": "Message", "more_info": "https://cloud.ibm.com/docs/vpc?topic=vpc-troubleshooting-backup-for-vpc"}], "target_snapshots": [{"crn": "crn:v1:bluemix:public:is:us-south:a/123456::snapshot:r134-f6bfa329-0e36-433f-a3bb-0df632e79263", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/snapshots/r134-f6bfa329-0e36-433f-a3bb-0df632e79263", "id": "r134-f6bfa329-0e36-433f-a3bb-0df632e79263", "name": "my-snapshot", "resource_type": "snapshot"}]}], "limit": 20, "next": {"href": "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/7241e2a8-601f-11ea-8503-000c29475bed/jobss?start=9d5a91a3e2cbd233b5a5b33436855ed1&limit=20"}, "total_count": 132}`) + })) + }) + It(`Invoke ListBackupPolicyJobs 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 ListBackupPolicyJobsOptions model + listBackupPolicyJobsOptionsModel := new(vpcv1.ListBackupPolicyJobsOptions) + listBackupPolicyJobsOptionsModel.BackupPolicyID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Status = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.BackupPolicyPlanID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Start = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Limit = core.Int64Ptr(int64(10)) + listBackupPolicyJobsOptionsModel.Sort = core.StringPtr("name") + listBackupPolicyJobsOptionsModel.SourceID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.TargetSnapshotsID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.TargetSnapshotsCRN = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.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.ListBackupPolicyJobsWithContext(ctx, listBackupPolicyJobsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + vpcService.DisableRetries() + result, response, operationErr := vpcService.ListBackupPolicyJobs(listBackupPolicyJobsOptionsModel) + 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.ListBackupPolicyJobsWithContext(ctx, listBackupPolicyJobsOptionsModel) + 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(listBackupPolicyJobsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["version"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["generation"]).To(Equal([]string{fmt.Sprint(int64(2))})) + Expect(req.URL.Query()["status"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["backup_policy_plan.id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["start"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) + Expect(req.URL.Query()["sort"]).To(Equal([]string{"name"})) + Expect(req.URL.Query()["source.id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["target_snapshots[].id"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["target_snapshots[].crn"]).To(Equal([]string{"testString"})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"first": {"href": "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/7241e2a8-601f-11ea-8503-000c29475bed/jobs?limit=20"}, "jobs": [{"auto_delete": true, "auto_delete_after": 90, "backup_policy_plan": {"deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178", "id": "r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178", "name": "my-policy-plan", "resource_type": "backup_policy_plan"}, "completed_at": "2019-01-01T12:00:00.000Z", "created_at": "2019-01-01T12:00:00.000Z", "href": "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/0fe9e5d8-0a4d-4818-96ec-e99708644a58/jobs/4cf9171a-0043-4434-8727-15b53dbc374c", "id": "4cf9171a-0043-4434-8727-15b53dbc374c", "job_type": "creation", "resource_type": "backup_policy_job", "source": {"crn": "crn:v1:bluemix:public:is:us-south-1:a/123456::volume:1a6b7274-678d-4dfb-8981-c71dd9d4daa5", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/volumes/1a6b7274-678d-4dfb-8981-c71dd9d4daa5", "id": "1a6b7274-678d-4dfb-8981-c71dd9d4daa5", "name": "my-volume"}, "status": "failed", "status_reasons": [{"code": "source_volume_busy", "message": "Message", "more_info": "https://cloud.ibm.com/docs/vpc?topic=vpc-troubleshooting-backup-for-vpc"}], "target_snapshots": [{"crn": "crn:v1:bluemix:public:is:us-south:a/123456::snapshot:r134-f6bfa329-0e36-433f-a3bb-0df632e79263", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/snapshots/r134-f6bfa329-0e36-433f-a3bb-0df632e79263", "id": "r134-f6bfa329-0e36-433f-a3bb-0df632e79263", "name": "my-snapshot", "resource_type": "snapshot"}]}], "limit": 20, "next": {"href": "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/7241e2a8-601f-11ea-8503-000c29475bed/jobss?start=9d5a91a3e2cbd233b5a5b33436855ed1&limit=20"}, "total_count": 132}`) + })) + }) + It(`Invoke ListBackupPolicyJobs 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.ListBackupPolicyJobs(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListBackupPolicyJobsOptions model + listBackupPolicyJobsOptionsModel := new(vpcv1.ListBackupPolicyJobsOptions) + listBackupPolicyJobsOptionsModel.BackupPolicyID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Status = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.BackupPolicyPlanID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Start = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Limit = core.Int64Ptr(int64(10)) + listBackupPolicyJobsOptionsModel.Sort = core.StringPtr("name") + listBackupPolicyJobsOptionsModel.SourceID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.TargetSnapshotsID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.TargetSnapshotsCRN = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = vpcService.ListBackupPolicyJobs(listBackupPolicyJobsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke ListBackupPolicyJobs 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 ListBackupPolicyJobsOptions model + listBackupPolicyJobsOptionsModel := new(vpcv1.ListBackupPolicyJobsOptions) + listBackupPolicyJobsOptionsModel.BackupPolicyID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Status = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.BackupPolicyPlanID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Start = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Limit = core.Int64Ptr(int64(10)) + listBackupPolicyJobsOptionsModel.Sort = core.StringPtr("name") + listBackupPolicyJobsOptionsModel.SourceID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.TargetSnapshotsID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.TargetSnapshotsCRN = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.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.ListBackupPolicyJobs(listBackupPolicyJobsOptionsModel) + 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 ListBackupPolicyJobsOptions model with no property values + listBackupPolicyJobsOptionsModelNew := new(vpcv1.ListBackupPolicyJobsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = vpcService.ListBackupPolicyJobs(listBackupPolicyJobsOptionsModelNew) + 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 ListBackupPolicyJobs 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 ListBackupPolicyJobsOptions model + listBackupPolicyJobsOptionsModel := new(vpcv1.ListBackupPolicyJobsOptions) + listBackupPolicyJobsOptionsModel.BackupPolicyID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Status = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.BackupPolicyPlanID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Start = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Limit = core.Int64Ptr(int64(10)) + listBackupPolicyJobsOptionsModel.Sort = core.StringPtr("name") + listBackupPolicyJobsOptionsModel.SourceID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.TargetSnapshotsID = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.TargetSnapshotsCRN = core.StringPtr("testString") + listBackupPolicyJobsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := vpcService.ListBackupPolicyJobs(listBackupPolicyJobsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Test pagination helper method on response`, func() { + It(`Invoke GetNextStart successfully`, func() { + responseObject := new(vpcv1.BackupPolicyJobCollection) + nextObject := new(vpcv1.BackupPolicyJobCollectionNext) + nextObject.Href = core.StringPtr("ibm.com?start=abc-123") + responseObject.Next = nextObject + + value, err := responseObject.GetNextStart() + Expect(err).To(BeNil()) + Expect(value).To(Equal(core.StringPtr("abc-123"))) + }) + It(`Invoke GetNextStart without a "Next" property in the response`, func() { + responseObject := new(vpcv1.BackupPolicyJobCollection) + + value, err := responseObject.GetNextStart() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + It(`Invoke GetNextStart without any query params in the "Next" URL`, func() { + responseObject := new(vpcv1.BackupPolicyJobCollection) + nextObject := new(vpcv1.BackupPolicyJobCollectionNext) + nextObject.Href = core.StringPtr("ibm.com") + responseObject.Next = nextObject + + value, err := responseObject.GetNextStart() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + }) + Context(`Using mock server endpoint - paginated response`, func() { + BeforeEach(func() { + var requestNumber int = 0 + 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(listBackupPolicyJobsPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + requestNumber++ + if requestNumber == 1 { + fmt.Fprintf(res, "%s", `{"next":{"href":"https://myhost.com/somePath?start=1"},"total_count":2,"jobs":[{"auto_delete":true,"auto_delete_after":90,"backup_policy_plan":{"deleted":{"more_info":"https://cloud.ibm.com/apidocs/vpc#deleted-resources"},"href":"https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178","id":"r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178","name":"my-policy-plan","resource_type":"backup_policy_plan"},"completed_at":"2019-01-01T12:00:00.000Z","created_at":"2019-01-01T12:00:00.000Z","href":"https://us-south.iaas.cloud.ibm.com/v1/backup_policies/0fe9e5d8-0a4d-4818-96ec-e99708644a58/jobs/4cf9171a-0043-4434-8727-15b53dbc374c","id":"4cf9171a-0043-4434-8727-15b53dbc374c","job_type":"creation","resource_type":"backup_policy_job","source":{"crn":"crn:v1:bluemix:public:is:us-south-1:a/123456::volume:1a6b7274-678d-4dfb-8981-c71dd9d4daa5","deleted":{"more_info":"https://cloud.ibm.com/apidocs/vpc#deleted-resources"},"href":"https://us-south.iaas.cloud.ibm.com/v1/volumes/1a6b7274-678d-4dfb-8981-c71dd9d4daa5","id":"1a6b7274-678d-4dfb-8981-c71dd9d4daa5","name":"my-volume"},"status":"failed","status_reasons":[{"code":"source_volume_busy","message":"Message","more_info":"https://cloud.ibm.com/docs/vpc?topic=vpc-troubleshooting-backup-for-vpc"}],"target_snapshots":[{"crn":"crn:v1:bluemix:public:is:us-south:a/123456::snapshot:r134-f6bfa329-0e36-433f-a3bb-0df632e79263","deleted":{"more_info":"https://cloud.ibm.com/apidocs/vpc#deleted-resources"},"href":"https://us-south.iaas.cloud.ibm.com/v1/snapshots/r134-f6bfa329-0e36-433f-a3bb-0df632e79263","id":"r134-f6bfa329-0e36-433f-a3bb-0df632e79263","name":"my-snapshot","resource_type":"snapshot"}]}],"limit":1}`) + } else if requestNumber == 2 { + fmt.Fprintf(res, "%s", `{"total_count":2,"jobs":[{"auto_delete":true,"auto_delete_after":90,"backup_policy_plan":{"deleted":{"more_info":"https://cloud.ibm.com/apidocs/vpc#deleted-resources"},"href":"https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178","id":"r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178","name":"my-policy-plan","resource_type":"backup_policy_plan"},"completed_at":"2019-01-01T12:00:00.000Z","created_at":"2019-01-01T12:00:00.000Z","href":"https://us-south.iaas.cloud.ibm.com/v1/backup_policies/0fe9e5d8-0a4d-4818-96ec-e99708644a58/jobs/4cf9171a-0043-4434-8727-15b53dbc374c","id":"4cf9171a-0043-4434-8727-15b53dbc374c","job_type":"creation","resource_type":"backup_policy_job","source":{"crn":"crn:v1:bluemix:public:is:us-south-1:a/123456::volume:1a6b7274-678d-4dfb-8981-c71dd9d4daa5","deleted":{"more_info":"https://cloud.ibm.com/apidocs/vpc#deleted-resources"},"href":"https://us-south.iaas.cloud.ibm.com/v1/volumes/1a6b7274-678d-4dfb-8981-c71dd9d4daa5","id":"1a6b7274-678d-4dfb-8981-c71dd9d4daa5","name":"my-volume"},"status":"failed","status_reasons":[{"code":"source_volume_busy","message":"Message","more_info":"https://cloud.ibm.com/docs/vpc?topic=vpc-troubleshooting-backup-for-vpc"}],"target_snapshots":[{"crn":"crn:v1:bluemix:public:is:us-south:a/123456::snapshot:r134-f6bfa329-0e36-433f-a3bb-0df632e79263","deleted":{"more_info":"https://cloud.ibm.com/apidocs/vpc#deleted-resources"},"href":"https://us-south.iaas.cloud.ibm.com/v1/snapshots/r134-f6bfa329-0e36-433f-a3bb-0df632e79263","id":"r134-f6bfa329-0e36-433f-a3bb-0df632e79263","name":"my-snapshot","resource_type":"snapshot"}]}],"limit":1}`) + } else { + res.WriteHeader(400) + } + })) + }) + It(`Use BackupPolicyJobsPager.GetNext 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()) + + listBackupPolicyJobsOptionsModel := &vpcv1.ListBackupPolicyJobsOptions{ + BackupPolicyID: core.StringPtr("testString"), + Status: core.StringPtr("testString"), + BackupPolicyPlanID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(10)), + Sort: core.StringPtr("name"), + SourceID: core.StringPtr("testString"), + TargetSnapshotsID: core.StringPtr("testString"), + TargetSnapshotsCRN: core.StringPtr("testString"), + } + + pager, err := vpcService.NewBackupPolicyJobsPager(listBackupPolicyJobsOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []vpcv1.BackupPolicyJob + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + Expect(len(allResults)).To(Equal(2)) + }) + It(`Use BackupPolicyJobsPager.GetAll 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()) + + listBackupPolicyJobsOptionsModel := &vpcv1.ListBackupPolicyJobsOptions{ + BackupPolicyID: core.StringPtr("testString"), + Status: core.StringPtr("testString"), + BackupPolicyPlanID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(10)), + Sort: core.StringPtr("name"), + SourceID: core.StringPtr("testString"), + TargetSnapshotsID: core.StringPtr("testString"), + TargetSnapshotsCRN: core.StringPtr("testString"), + } + + pager, err := vpcService.NewBackupPolicyJobsPager(listBackupPolicyJobsOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allResults, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allResults).ToNot(BeNil()) + Expect(len(allResults)).To(Equal(2)) + }) + }) + }) + Describe(`GetBackupPolicyJob(getBackupPolicyJobOptions *GetBackupPolicyJobOptions) - Operation response error`, func() { + version := "testString" + getBackupPolicyJobPath := "/backup_policies/testString/jobs/testString" + 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(getBackupPolicyJobPath)) + Expect(req.Method).To(Equal("GET")) + 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 GetBackupPolicyJob 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 GetBackupPolicyJobOptions model + getBackupPolicyJobOptionsModel := new(vpcv1.GetBackupPolicyJobOptions) + getBackupPolicyJobOptionsModel.BackupPolicyID = core.StringPtr("testString") + getBackupPolicyJobOptionsModel.ID = core.StringPtr("testString") + getBackupPolicyJobOptionsModel.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.GetBackupPolicyJob(getBackupPolicyJobOptionsModel) + 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.GetBackupPolicyJob(getBackupPolicyJobOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetBackupPolicyJob(getBackupPolicyJobOptions *GetBackupPolicyJobOptions)`, func() { + version := "testString" + getBackupPolicyJobPath := "/backup_policies/testString/jobs/testString" + 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(getBackupPolicyJobPath)) + Expect(req.Method).To(Equal("GET")) + + 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", `{"auto_delete": true, "auto_delete_after": 90, "backup_policy_plan": {"deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178", "id": "r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178", "name": "my-policy-plan", "resource_type": "backup_policy_plan"}, "completed_at": "2019-01-01T12:00:00.000Z", "created_at": "2019-01-01T12:00:00.000Z", "href": "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/0fe9e5d8-0a4d-4818-96ec-e99708644a58/jobs/4cf9171a-0043-4434-8727-15b53dbc374c", "id": "4cf9171a-0043-4434-8727-15b53dbc374c", "job_type": "creation", "resource_type": "backup_policy_job", "source": {"crn": "crn:v1:bluemix:public:is:us-south-1:a/123456::volume:1a6b7274-678d-4dfb-8981-c71dd9d4daa5", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/volumes/1a6b7274-678d-4dfb-8981-c71dd9d4daa5", "id": "1a6b7274-678d-4dfb-8981-c71dd9d4daa5", "name": "my-volume"}, "status": "failed", "status_reasons": [{"code": "source_volume_busy", "message": "Message", "more_info": "https://cloud.ibm.com/docs/vpc?topic=vpc-troubleshooting-backup-for-vpc"}], "target_snapshots": [{"crn": "crn:v1:bluemix:public:is:us-south:a/123456::snapshot:r134-f6bfa329-0e36-433f-a3bb-0df632e79263", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/snapshots/r134-f6bfa329-0e36-433f-a3bb-0df632e79263", "id": "r134-f6bfa329-0e36-433f-a3bb-0df632e79263", "name": "my-snapshot", "resource_type": "snapshot"}]}`) + })) + }) + It(`Invoke GetBackupPolicyJob 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 GetBackupPolicyJobOptions model + getBackupPolicyJobOptionsModel := new(vpcv1.GetBackupPolicyJobOptions) + getBackupPolicyJobOptionsModel.BackupPolicyID = core.StringPtr("testString") + getBackupPolicyJobOptionsModel.ID = core.StringPtr("testString") + getBackupPolicyJobOptionsModel.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.GetBackupPolicyJobWithContext(ctx, getBackupPolicyJobOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + vpcService.DisableRetries() + result, response, operationErr := vpcService.GetBackupPolicyJob(getBackupPolicyJobOptionsModel) + 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.GetBackupPolicyJobWithContext(ctx, getBackupPolicyJobOptionsModel) + 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(getBackupPolicyJobPath)) + Expect(req.Method).To(Equal("GET")) + + 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", `{"auto_delete": true, "auto_delete_after": 90, "backup_policy_plan": {"deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178", "id": "r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178", "name": "my-policy-plan", "resource_type": "backup_policy_plan"}, "completed_at": "2019-01-01T12:00:00.000Z", "created_at": "2019-01-01T12:00:00.000Z", "href": "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/0fe9e5d8-0a4d-4818-96ec-e99708644a58/jobs/4cf9171a-0043-4434-8727-15b53dbc374c", "id": "4cf9171a-0043-4434-8727-15b53dbc374c", "job_type": "creation", "resource_type": "backup_policy_job", "source": {"crn": "crn:v1:bluemix:public:is:us-south-1:a/123456::volume:1a6b7274-678d-4dfb-8981-c71dd9d4daa5", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/volumes/1a6b7274-678d-4dfb-8981-c71dd9d4daa5", "id": "1a6b7274-678d-4dfb-8981-c71dd9d4daa5", "name": "my-volume"}, "status": "failed", "status_reasons": [{"code": "source_volume_busy", "message": "Message", "more_info": "https://cloud.ibm.com/docs/vpc?topic=vpc-troubleshooting-backup-for-vpc"}], "target_snapshots": [{"crn": "crn:v1:bluemix:public:is:us-south:a/123456::snapshot:r134-f6bfa329-0e36-433f-a3bb-0df632e79263", "deleted": {"more_info": "https://cloud.ibm.com/apidocs/vpc#deleted-resources"}, "href": "https://us-south.iaas.cloud.ibm.com/v1/snapshots/r134-f6bfa329-0e36-433f-a3bb-0df632e79263", "id": "r134-f6bfa329-0e36-433f-a3bb-0df632e79263", "name": "my-snapshot", "resource_type": "snapshot"}]}`) + })) + }) + It(`Invoke GetBackupPolicyJob 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.GetBackupPolicyJob(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetBackupPolicyJobOptions model + getBackupPolicyJobOptionsModel := new(vpcv1.GetBackupPolicyJobOptions) + getBackupPolicyJobOptionsModel.BackupPolicyID = core.StringPtr("testString") + getBackupPolicyJobOptionsModel.ID = core.StringPtr("testString") + getBackupPolicyJobOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = vpcService.GetBackupPolicyJob(getBackupPolicyJobOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetBackupPolicyJob 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 GetBackupPolicyJobOptions model + getBackupPolicyJobOptionsModel := new(vpcv1.GetBackupPolicyJobOptions) + getBackupPolicyJobOptionsModel.BackupPolicyID = core.StringPtr("testString") + getBackupPolicyJobOptionsModel.ID = core.StringPtr("testString") + getBackupPolicyJobOptionsModel.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.GetBackupPolicyJob(getBackupPolicyJobOptionsModel) + 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 GetBackupPolicyJobOptions model with no property values + getBackupPolicyJobOptionsModelNew := new(vpcv1.GetBackupPolicyJobOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = vpcService.GetBackupPolicyJob(getBackupPolicyJobOptionsModelNew) + 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 GetBackupPolicyJob 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 GetBackupPolicyJobOptions model + getBackupPolicyJobOptionsModel := new(vpcv1.GetBackupPolicyJobOptions) + getBackupPolicyJobOptionsModel.BackupPolicyID = core.StringPtr("testString") + getBackupPolicyJobOptionsModel.ID = core.StringPtr("testString") + getBackupPolicyJobOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := vpcService.GetBackupPolicyJob(getBackupPolicyJobOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) Describe(`ListBackupPolicyPlans(listBackupPolicyPlansOptions *ListBackupPolicyPlansOptions) - Operation response error`, func() { version := "testString" listBackupPolicyPlansPath := "/backup_policies/testString/plans" @@ -83722,6 +84356,19 @@ var _ = Describe(`VpcV1`, func() { Expect(disconnectVPNClientOptionsModel.ID).To(Equal(core.StringPtr("testString"))) Expect(disconnectVPNClientOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewGetBackupPolicyJobOptions successfully`, func() { + // Construct an instance of the GetBackupPolicyJobOptions model + backupPolicyID := "testString" + id := "testString" + getBackupPolicyJobOptionsModel := vpcService.NewGetBackupPolicyJobOptions(backupPolicyID, id) + getBackupPolicyJobOptionsModel.SetBackupPolicyID("testString") + getBackupPolicyJobOptionsModel.SetID("testString") + getBackupPolicyJobOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getBackupPolicyJobOptionsModel).ToNot(BeNil()) + Expect(getBackupPolicyJobOptionsModel.BackupPolicyID).To(Equal(core.StringPtr("testString"))) + Expect(getBackupPolicyJobOptionsModel.ID).To(Equal(core.StringPtr("testString"))) + Expect(getBackupPolicyJobOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewGetBackupPolicyOptions successfully`, func() { // Construct an instance of the GetBackupPolicyOptions model id := "testString" @@ -84644,6 +85291,32 @@ var _ = Describe(`VpcV1`, func() { Expect(listBackupPoliciesOptionsModel.Tag).To(Equal(core.StringPtr("testString"))) Expect(listBackupPoliciesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewListBackupPolicyJobsOptions successfully`, func() { + // Construct an instance of the ListBackupPolicyJobsOptions model + backupPolicyID := "testString" + listBackupPolicyJobsOptionsModel := vpcService.NewListBackupPolicyJobsOptions(backupPolicyID) + listBackupPolicyJobsOptionsModel.SetBackupPolicyID("testString") + listBackupPolicyJobsOptionsModel.SetStatus("testString") + listBackupPolicyJobsOptionsModel.SetBackupPolicyPlanID("testString") + listBackupPolicyJobsOptionsModel.SetStart("testString") + listBackupPolicyJobsOptionsModel.SetLimit(int64(10)) + listBackupPolicyJobsOptionsModel.SetSort("name") + listBackupPolicyJobsOptionsModel.SetSourceID("testString") + listBackupPolicyJobsOptionsModel.SetTargetSnapshotsID("testString") + listBackupPolicyJobsOptionsModel.SetTargetSnapshotsCRN("testString") + listBackupPolicyJobsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listBackupPolicyJobsOptionsModel).ToNot(BeNil()) + Expect(listBackupPolicyJobsOptionsModel.BackupPolicyID).To(Equal(core.StringPtr("testString"))) + Expect(listBackupPolicyJobsOptionsModel.Status).To(Equal(core.StringPtr("testString"))) + Expect(listBackupPolicyJobsOptionsModel.BackupPolicyPlanID).To(Equal(core.StringPtr("testString"))) + Expect(listBackupPolicyJobsOptionsModel.Start).To(Equal(core.StringPtr("testString"))) + Expect(listBackupPolicyJobsOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(10)))) + Expect(listBackupPolicyJobsOptionsModel.Sort).To(Equal(core.StringPtr("name"))) + Expect(listBackupPolicyJobsOptionsModel.SourceID).To(Equal(core.StringPtr("testString"))) + Expect(listBackupPolicyJobsOptionsModel.TargetSnapshotsID).To(Equal(core.StringPtr("testString"))) + Expect(listBackupPolicyJobsOptionsModel.TargetSnapshotsCRN).To(Equal(core.StringPtr("testString"))) + Expect(listBackupPolicyJobsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewListBackupPolicyPlansOptions successfully`, func() { // Construct an instance of the ListBackupPolicyPlansOptions model backupPolicyID := "testString"