github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/sdrs/v1/protectiongroups/requests.go (about)

     1  package protectiongroups
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  )
     6  
     7  var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{
     8  	MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
     9  }
    10  
    11  // CreateOptsBuilder allows extensions to add additional parameters to the
    12  // Create request.
    13  type CreateOptsBuilder interface {
    14  	ToGroupCreateMap() (map[string]interface{}, error)
    15  }
    16  
    17  // CreateOpts contains all the values needed to create a new group.
    18  type CreateOpts struct {
    19  	//Group Name
    20  	Name string `json:"name" required:"true"`
    21  	//Group Description
    22  	Description string `json:"description,omitempty"`
    23  	//The source AZ of a protection group
    24  	SourceAZ string `json:"source_availability_zone" required:"true"`
    25  	//The target AZ of a protection group
    26  	TargetAZ string `json:"target_availability_zone" required:"true"`
    27  	//An active-active domain
    28  	DomainID string `json:"domain_id" required:"true"`
    29  	//ID of the source VPC
    30  	SourceVpcID string `json:"source_vpc_id" required:"true"`
    31  	//Deployment model
    32  	DrType string `json:"dr_type,omitempty"`
    33  }
    34  
    35  // ToGroupCreateMap builds a create request body from CreateOpts.
    36  func (opts CreateOpts) ToGroupCreateMap() (map[string]interface{}, error) {
    37  	return golangsdk.BuildRequestBody(opts, "server_group")
    38  }
    39  
    40  // Create will create a new Group based on the values in CreateOpts.
    41  func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r JobResult) {
    42  	b, err := opts.ToGroupCreateMap()
    43  	if err != nil {
    44  		r.Err = err
    45  		return
    46  	}
    47  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
    48  	_, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt)
    49  	return
    50  }
    51  
    52  // UpdateOptsBuilder allows extensions to add additional parameters to the
    53  // Update request.
    54  type UpdateOptsBuilder interface {
    55  	ToGroupUpdateMap() (map[string]interface{}, error)
    56  }
    57  
    58  // UpdateOpts contains all the values needed to update a Group.
    59  type UpdateOpts struct {
    60  	//Group name
    61  	Name string `json:"name" required:"true"`
    62  }
    63  
    64  // ToGroupUpdateMap builds a update request body from UpdateOpts.
    65  func (opts UpdateOpts) ToGroupUpdateMap() (map[string]interface{}, error) {
    66  	return golangsdk.BuildRequestBody(opts, "server_group")
    67  }
    68  
    69  // Update accepts a UpdateOpts struct and uses the values to update a Group.The response code from api is 200
    70  func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
    71  	b, err := opts.ToGroupUpdateMap()
    72  	if err != nil {
    73  		r.Err = err
    74  		return
    75  	}
    76  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
    77  	_, r.Err = c.Put(resourceURL(c, id), b, nil, reqOpt)
    78  	return
    79  }
    80  
    81  // Get retrieves a particular Group based on its unique ID.
    82  func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
    83  	_, r.Err = c.Get(resourceURL(c, id), &r.Body, &golangsdk.RequestOpts{
    84  		MoreHeaders: RequestOpts.MoreHeaders,
    85  	})
    86  	return
    87  }
    88  
    89  // Delete will permanently delete a particular Group based on its unique ID.
    90  func Delete(c *golangsdk.ServiceClient, id string) (r JobResult) {
    91  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200},
    92  		MoreHeaders: RequestOpts.MoreHeaders}
    93  	_, r.Err = c.DeleteWithResponse(resourceURL(c, id), &r.Body, reqOpt)
    94  	return
    95  }
    96  
    97  // EnableOpts contains all the values needed to enable protection for a Group.
    98  type EnableOpts struct {
    99  	//Empty
   100  }
   101  
   102  // ToGroupEnableMap builds a create request body from EnableOpts.
   103  func (opts EnableOpts) ToGroupEnableMap() (map[string]interface{}, error) {
   104  	return golangsdk.BuildRequestBody(opts, "start-server-group")
   105  }
   106  
   107  // Enable will enable protection for a protection Group.
   108  func Enable(c *golangsdk.ServiceClient, id string) (r JobResult) {
   109  	opts := EnableOpts{}
   110  	b, err := opts.ToGroupEnableMap()
   111  	if err != nil {
   112  		r.Err = err
   113  		return
   114  	}
   115  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
   116  	_, r.Err = c.Post(actionURL(c, id), b, &r.Body, reqOpt)
   117  	return
   118  }
   119  
   120  // DisableOpts contains all the values needed to disable protection for a Group.
   121  type DisableOpts struct {
   122  	//Empty
   123  }
   124  
   125  // ToGroupDisableMap builds a create request body from DisableOpts.
   126  func (opts DisableOpts) ToGroupDisableMap() (map[string]interface{}, error) {
   127  	return golangsdk.BuildRequestBody(opts, "stop-server-group")
   128  }
   129  
   130  // Disable will disable protection for a protection Group.
   131  func Disable(c *golangsdk.ServiceClient, id string) (r JobResult) {
   132  	opts := DisableOpts{}
   133  	b, err := opts.ToGroupDisableMap()
   134  	if err != nil {
   135  		r.Err = err
   136  		return
   137  	}
   138  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
   139  	_, r.Err = c.Post(actionURL(c, id), b, &r.Body, reqOpt)
   140  	return
   141  }