github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/ims/v1/imagecopy/requests.go (about) 1 package imagecopy 2 3 import "github.com/chnsz/golangsdk" 4 5 // WithinRegionCopyOptsBuilder allows extensions to add parameters to the Create request. 6 type WithinRegionCopyOptsBuilder interface { 7 // ToWithinRegionCopyMap Returns value that can be passed to json.Marshal 8 ToWithinRegionCopyMap() (map[string]interface{}, error) 9 } 10 11 // WithinRegionCopyOpts represents options used to create an image. 12 type WithinRegionCopyOpts struct { 13 // the name of the copy image 14 Name string `json:"name" required:"true"` 15 // description of the copy image 16 Description string `json:"description,omitempty"` 17 // the master key used for encrypting an image. 18 CmkId string `json:"cmk_id,omitempty"` 19 // Enterprise project ID 20 EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` 21 } 22 23 func (opts WithinRegionCopyOpts) ToWithinRegionCopyMap() (map[string]interface{}, error) { 24 return golangsdk.BuildRequestBody(opts, "") 25 } 26 27 // WithinRegionCopy implements create image request. 28 func WithinRegionCopy(client *golangsdk.ServiceClient, imageId string, opts WithinRegionCopyOptsBuilder) (r JobResult) { 29 b, err := opts.ToWithinRegionCopyMap() 30 if err != nil { 31 r.Err = err 32 return 33 } 34 35 _, r.Err = client.Post(withinRegionCopyURL(client, imageId), b, &r.Body, nil) 36 return 37 } 38 39 // CrossRegionCopyOptsBuilder allows extensions to add parameters to the Create request. 40 type CrossRegionCopyOptsBuilder interface { 41 // ToCrossRegionCopyMap Returns value that can be passed to json.Marshal 42 ToCrossRegionCopyMap() (map[string]interface{}, error) 43 } 44 45 // CrossRegionCopyOpts represents options used to create an image. 46 type CrossRegionCopyOpts struct { 47 // the name of the copy image 48 Name string `json:"name" required:"true"` 49 // description of the copy image 50 Description string `json:"description,omitempty"` 51 // the target region name. 52 TargetRegion string `json:"region" required:"true"` 53 // the name of the project in the destination region. 54 TargetProjectName string `json:"project_name" required:"true"` 55 // the agency name. 56 AgencyName string `json:"agency_name" required:"true"` 57 // the ID of the vault 58 VaultId string `json:"vault_id,omitempty"` 59 } 60 61 func (opts CrossRegionCopyOpts) ToCrossRegionCopyMap() (map[string]interface{}, error) { 62 return golangsdk.BuildRequestBody(opts, "") 63 } 64 65 // CrossRegionCopy implements create image request. 66 func CrossRegionCopy(client *golangsdk.ServiceClient, imageId string, opts CrossRegionCopyOptsBuilder) (r JobResult) { 67 b, err := opts.ToCrossRegionCopyMap() 68 if err != nil { 69 r.Err = err 70 return 71 } 72 73 _, r.Err = client.Post(crossRegionCopyURL(client, imageId), b, &r.Body, nil) 74 return 75 }