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

     1  package drill
     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  	ToDrillCreateMap() (map[string]interface{}, error)
    15  }
    16  
    17  // CreateOpts contains all the values needed to create a new dr-drill.
    18  type CreateOpts struct {
    19  	// Protection Group ID
    20  	GroupID string `json:"server_group_id" required:"true"`
    21  	// Drill vpc id
    22  	DrillVpcID string `json:"drill_vpc_id" required:"true"`
    23  	//DR-Drill Name
    24  	Name string `json:"name" required:"true"`
    25  }
    26  
    27  // ToDrillCreateMap builds a create request body from CreateOpts.
    28  func (opts CreateOpts) ToDrillCreateMap() (map[string]interface{}, error) {
    29  	return golangsdk.BuildRequestBody(opts, "disaster_recovery_drill")
    30  }
    31  
    32  // Create will create a new DR-Drill based on the values in CreateOpts.
    33  func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r JobResult) {
    34  	b, err := opts.ToDrillCreateMap()
    35  	if err != nil {
    36  		r.Err = err
    37  		return
    38  	}
    39  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
    40  	_, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt)
    41  	return
    42  }
    43  
    44  // UpdateOptsBuilder allows extensions to add additional parameters to the
    45  // Update request.
    46  type UpdateOptsBuilder interface {
    47  	ToDrillUpdateMap() (map[string]interface{}, error)
    48  }
    49  
    50  // UpdateOpts contains all the values needed to update a dr-drill.
    51  type UpdateOpts struct {
    52  	// DR-Drill name
    53  	Name string `json:"name" required:"true"`
    54  }
    55  
    56  // ToDrillUpdateMap builds a update request body from UpdateOpts.
    57  func (opts UpdateOpts) ToDrillUpdateMap() (map[string]interface{}, error) {
    58  	return golangsdk.BuildRequestBody(opts, "disaster_recovery_drill")
    59  }
    60  
    61  // Update accepts a UpdateOpts struct and uses the values to update a dr-drill.
    62  // The response code from api is 200
    63  func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
    64  	b, err := opts.ToDrillUpdateMap()
    65  	if err != nil {
    66  		r.Err = err
    67  		return
    68  	}
    69  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
    70  	_, r.Err = c.Put(resourceURL(c, id), b, nil, reqOpt)
    71  	return
    72  }
    73  
    74  // Get retrieves a particular dr-drill based on its unique ID.
    75  func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
    76  	_, r.Err = c.Get(resourceURL(c, id), &r.Body, &golangsdk.RequestOpts{
    77  		MoreHeaders: requestOpts.MoreHeaders,
    78  	})
    79  	return
    80  }
    81  
    82  // Delete will permanently delete a particular dr-drill based on its unique ID.
    83  func Delete(c *golangsdk.ServiceClient, id string) (r JobResult) {
    84  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
    85  	_, r.Err = c.DeleteWithResponse(resourceURL(c, id), &r.Body, reqOpt)
    86  	return
    87  }