github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/drs/v2/replicationconsistencygroups/requests.go (about)

     1  package replicationconsistencygroups
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // CreateOpsBuilder is used for creating replication consistency group parameters.
     9  // any struct providing the parameters should implement this interface
    10  type CreateOpsBuilder interface {
    11  	ToReplicationConsistencyGroupCreateMap() (map[string]interface{}, error)
    12  }
    13  
    14  // CreateOps is a struct that contains all the parameters.
    15  type CreateOps struct {
    16  	// The name of the replication consistency group.
    17  	// The name can contain a maximum of 255 bytes.
    18  	Name string `json:"name,omitempty"`
    19  
    20  	// The description of the replication consistency group.
    21  	// The description can contain a maximum of 255 bytes.
    22  	Description string `json:"description,omitempty"`
    23  
    24  	// The IDs of the EVS replication pairs used to
    25  	// create the replication consistency group.
    26  	ReplicationIDs []string `json:"replication_ids" required:"true"`
    27  
    28  	// The primary AZ of the replication consistency group.
    29  	// That is the AZ where the production disk belongs.
    30  	PriorityStation string `json:"priority_station" required:"true"`
    31  
    32  	// The type of the created replication consistency group.
    33  	// Currently only type hypermetro is supported.
    34  	ReplicationModel string `json:"replication_model" required:"true"`
    35  }
    36  
    37  // ToReplicationConsistencyGroupCreateMap is used for type convert
    38  func (ops CreateOps) ToReplicationConsistencyGroupCreateMap() (map[string]interface{}, error) {
    39  	return golangsdk.BuildRequestBody(ops, "replication_consistency_group")
    40  }
    41  
    42  // Create a replication consistency group with given parameters.
    43  func Create(client *golangsdk.ServiceClient, ops CreateOpsBuilder) (r CreateResult) {
    44  	b, err := ops.ToReplicationConsistencyGroupCreateMap()
    45  	if err != nil {
    46  		r.Err = err
    47  		return
    48  	}
    49  
    50  	_, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{
    51  		OkCodes: []int{202},
    52  	})
    53  
    54  	return
    55  }
    56  
    57  // Delete a replication consistency group by id
    58  func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
    59  	_, r.Err = client.Delete(deleteURL(client, id), nil)
    60  	return
    61  }
    62  
    63  // Get a replication consistency group with detailed information by id
    64  func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
    65  	_, r.Err = client.Get(getURL(client, id), &r.Body, nil)
    66  	return
    67  }
    68  
    69  // ListOptsBuilder is an interface by which can be able to
    70  // build the query string of the list function
    71  type ListOptsBuilder interface {
    72  	ToReplicationConsistencyGroupListQuery() (string, error)
    73  }
    74  
    75  // ListOpts is a struct that contains all the parameters.
    76  type ListOpts struct {
    77  	Marker          string `q:"marker"`
    78  	Limit           int    `q:"limit"`
    79  	SortKey         string `q:"sort_key"`
    80  	SortDir         string `q:"sort_dir"`
    81  	Offset          int    `q:"offset"`
    82  	ChangesSince    string `q:"changes-since"`
    83  	Name            string `q:"name"`
    84  	Status          string `q:"status"`
    85  	PriorityStation string `q:"priority_station"`
    86  	VolumeID        string `q:"volume_id"`
    87  }
    88  
    89  // ToReplicationConsistencyGroupListQuery formats a ListOpts into a query string.
    90  func (opts ListOpts) ToReplicationConsistencyGroupListQuery() (string, error) {
    91  	q, err := golangsdk.BuildQueryString(opts)
    92  	return q.String(), err
    93  }
    94  
    95  // List all the replication consistency groups
    96  func List(client *golangsdk.ServiceClient, ops ListOptsBuilder) pagination.Pager {
    97  	url := listURL(client)
    98  	if ops != nil {
    99  		q, err := ops.ToReplicationConsistencyGroupListQuery()
   100  		if err != nil {
   101  			return pagination.Pager{Err: err}
   102  		}
   103  		url += q
   104  	}
   105  
   106  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   107  		return ReplicationConsistencyGroupPage{pagination.SinglePageBase(r)}
   108  	})
   109  }
   110  
   111  //UpdateOptsBuilder is an interface which can build the map paramter of update function
   112  type UpdateOptsBuilder interface {
   113  	ToReplicationConsistencyGroupUpdateMap() (map[string]interface{}, error)
   114  }
   115  
   116  //UpdateOpts is a struct which represents the parameters of update function
   117  type UpdateOpts struct {
   118  	// The name of the replication consistency group.
   119  	// The name can contain a maximum of 255 bytes.
   120  	Name string `json:"name,omitempty"`
   121  
   122  	// The description of the replication consistency group.
   123  	// The description can contain a maximum of 255 bytes.
   124  	Description string `json:"description,omitempty"`
   125  
   126  	// The type of the created replication consistency group.
   127  	// Currently only type hypermetro is supported.
   128  	ReplicationModel string `json:"replication_model,omitempty"`
   129  
   130  	// The IDs of the EVS replication pairs to be added.
   131  	AddReplicationIDs []string `json:"add_replication_ids,omitempty"`
   132  
   133  	// The IDs of the EVS replication pairs to be removeed.
   134  	RemoveReplicationIDs []string `json:"remove_replication_ids,omitempty"`
   135  }
   136  
   137  // ToReplicationConsistencyGroupUpdateMap is used for type convert
   138  func (opts UpdateOpts) ToReplicationConsistencyGroupUpdateMap() (map[string]interface{}, error) {
   139  	return golangsdk.BuildRequestBody(opts, "replication_consistency_group")
   140  }
   141  
   142  // Update is a method which can be able to update the replication consistency group
   143  // via accessing to the service with Put method and parameters
   144  func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
   145  	body, err := opts.ToReplicationConsistencyGroupUpdateMap()
   146  	if err != nil {
   147  		r.Err = err
   148  		return
   149  	}
   150  
   151  	_, r.Err = client.Put(updateURL(client, id), body, &r.Body, &golangsdk.RequestOpts{
   152  		OkCodes: []int{202},
   153  	})
   154  	return
   155  }
   156  
   157  const (
   158  	// OsFailoverReplicationConsistencyGroup is performing a failover for a replication consistency group.
   159  	OsFailoverReplicationConsistencyGroup = "os-failover-replication-consistency-group"
   160  
   161  	// OsSyncReplicationConsistencyGroup is synchronizing a replication consistency group.
   162  	OsSyncReplicationConsistencyGroup = "os-sync-replication-consistency-group"
   163  
   164  	// OsReverseReplicationConsistencyGroup is performing a primary/secondary switchover for a replication consistency group.
   165  	OsReverseReplicationConsistencyGroup = "os-reverse-replication-consistency-group"
   166  
   167  	// OsStopReplicationConsistencyGroup is pausing a replication consistency group.
   168  	OsStopReplicationConsistencyGroup = "os-stop-replication-consistency-group"
   169  
   170  	// OsReprotectReplicationConsistencyGroup is reprotecting a replication consistency group.
   171  	OsReprotectReplicationConsistencyGroup = "os-reprotect-replication-consistency-group"
   172  
   173  	// OsExtendReplicationVolume is expanding EVS disks in a replication consistency group.
   174  	OsExtendReplicationVolume = "os-extend-replication-volumes"
   175  )
   176  
   177  // FailOver is performing a failover for a replication consistency group.
   178  func FailOver(client *golangsdk.ServiceClient, id string) (r ActionResult) {
   179  	_, r.Err = client.Post(
   180  		actionURL(client, id),
   181  		map[string]interface{}{OsFailoverReplicationConsistencyGroup: nil},
   182  		nil,
   183  		&golangsdk.RequestOpts{
   184  			OkCodes: []int{200},
   185  		})
   186  
   187  	return
   188  }
   189  
   190  // Sync is synchronizing a replication consistency group.
   191  func Sync(client *golangsdk.ServiceClient, id string) (r ActionResult) {
   192  	_, r.Err = client.Post(
   193  		actionURL(client, id),
   194  		map[string]interface{}{OsSyncReplicationConsistencyGroup: nil},
   195  		nil,
   196  		&golangsdk.RequestOpts{
   197  			OkCodes: []int{200},
   198  		})
   199  
   200  	return
   201  }
   202  
   203  // Reverse is performing a primary/secondary switchover for a replication consistency group.
   204  func Reverse(client *golangsdk.ServiceClient, id string) (r ActionResult) {
   205  	_, r.Err = client.Post(
   206  		actionURL(client, id),
   207  		map[string]interface{}{OsReverseReplicationConsistencyGroup: nil},
   208  		nil,
   209  		&golangsdk.RequestOpts{
   210  			OkCodes: []int{200},
   211  		})
   212  
   213  	return
   214  }
   215  
   216  // Stop is pausing a replication consistency group.
   217  func Stop(client *golangsdk.ServiceClient, id string) (r ActionResult) {
   218  	_, r.Err = client.Post(
   219  		actionURL(client, id),
   220  		map[string]interface{}{OsStopReplicationConsistencyGroup: nil},
   221  		nil,
   222  		&golangsdk.RequestOpts{
   223  			OkCodes: []int{200},
   224  		})
   225  
   226  	return
   227  }
   228  
   229  // Reprotect is reprotecting a replication consistency group.
   230  func Reprotect(client *golangsdk.ServiceClient, id string) (r ActionResult) {
   231  	_, r.Err = client.Post(
   232  		actionURL(client, id),
   233  		map[string]interface{}{OsReprotectReplicationConsistencyGroup: nil},
   234  		nil,
   235  		&golangsdk.RequestOpts{
   236  			OkCodes: []int{200},
   237  		})
   238  
   239  	return
   240  }
   241  
   242  // ExtendReplicationVolumesOpsBuilder is used for expanding
   243  // EVS disks in a replication consistency group parameters.
   244  // any struct providing the parameters should implement this interface
   245  type ExtendReplicationVolumesOpsBuilder interface {
   246  	ToExtendReplicationVolumesMap() (map[string]interface{}, error)
   247  }
   248  
   249  // ReplicationsOps specifies the expansion information
   250  // of one or multiple EVS replication pairs.
   251  type ReplicationsOps struct {
   252  	// The IDs of EVS replication pairs
   253  	ID string `json:"id" required:"true"`
   254  
   255  	// The disk capacity after expansion in the EVS replication pair.
   256  	// The unit is GB.
   257  	NewSize int `json:"new_size" required:"true"`
   258  }
   259  
   260  // ExtendReplicationVolumesOps is a struct that contains all the parameters.
   261  type ExtendReplicationVolumesOps struct {
   262  	// The expansion information of one or multiple EVS replication pairs.
   263  	Replications []ReplicationsOps `json:"replications" required:"true"`
   264  }
   265  
   266  // ToExtendReplicationVolumesMap is used for type convert
   267  func (ops ReplicationsOps) ToExtendReplicationVolumesMap() (map[string]interface{}, error) {
   268  	return golangsdk.BuildRequestBody(ops, OsExtendReplicationVolume)
   269  }
   270  
   271  // Extend is expanding EVS disks in a replication consistency group.
   272  func Extend(client *golangsdk.ServiceClient, id string, ops ExtendReplicationVolumesOpsBuilder) (r ActionResult) {
   273  	b, err := ops.ToExtendReplicationVolumesMap()
   274  	if err != nil {
   275  		r.Err = err
   276  		return
   277  	}
   278  
   279  	_, r.Err = client.Post(actionURL(client, id), b, nil, &golangsdk.RequestOpts{
   280  		OkCodes: []int{200},
   281  	})
   282  
   283  	return
   284  }