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

     1  package instances
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // CreateOpts allows to create an APIG dedicated instance using given parameters.
     9  type CreateOpts struct {
    10  	// Name of the APIG dedicated instance. The name can contains of 3 to 64 characters.
    11  	Name string `json:"instance_name" required:"true"`
    12  	// Edition of the APIG dedicated instance. Currently, the editions are support:
    13  	// (IPv4): BASIC, PROFESSIONAL, ENTERPRISE, PLATINUM
    14  	// (IPv6): BASIC_IPV6, PROFESSIONAL_IPV6, ENTERPRISE_IPV6, PLATINUM_IPV6
    15  	Edition string `json:"spec_id" required:"true"`
    16  	// VPC ID.
    17  	VpcId string `json:"vpc_id" required:"true"`
    18  	// Subnet network ID.
    19  	SubnetId string `json:"subnet_id" required:"true"`
    20  	// ID of the security group to which the APIG dedicated instance belongs to.
    21  	SecurityGroupId string `json:"security_group_id" required:"true"`
    22  	// ID of the APIG dedicated instance, which will be automatically generated if you do not specify this parameter.
    23  	Id string `json:"instance_id,omitempty"`
    24  	// Description about the APIG dedicated instance.
    25  	Description string `json:"description,omitempty"`
    26  	// Start time of the maintenance time window in the format "xx:00:00".
    27  	// The value of xx can be 02, 06, 10, 14, 18, or 22.
    28  	MaintainBegin string `json:"maintain_begin,omitempty"`
    29  	// End time of the maintenance time window in the format "xx:00:00".
    30  	// There is a 4-hour difference between the start time and end time.
    31  	MaintainEnd string `json:"maintain_end,omitempty"`
    32  	// EIP ID.
    33  	EipId string `json:"eip_id,omitempty"`
    34  	// Outbound access bandwidth. This parameter is required if public outbound access is enabled for the APIG
    35  	// dedicated instance.
    36  	// Zero means turn off the egress access.
    37  	BandwidthSize int `json:"bandwidth_size"`
    38  	// Enterprise project ID. This parameter is required if you are using an enterprise account.
    39  	EnterpriseProjectId string `json:"enterprise_project_id,omitempty"`
    40  	// AZs.
    41  	AvailableZoneIds []string `json:"available_zone_ids,omitempty"`
    42  	// Whether public access with an IPv6 address is supported.
    43  	Ipv6Enable bool `json:"ipv6_enable,omitempty"`
    44  }
    45  
    46  type CreateOptsBuilder interface {
    47  	ToInstanceCreateMap() (map[string]interface{}, error)
    48  }
    49  
    50  func (opts CreateOpts) ToInstanceCreateMap() (map[string]interface{}, error) {
    51  	return golangsdk.BuildRequestBody(opts, "")
    52  }
    53  
    54  // Create is a method by which to create function that create a APIG dedicated instance.
    55  func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    56  	reqBody, err := opts.ToInstanceCreateMap()
    57  	if err != nil {
    58  		r.Err = err
    59  		return
    60  	}
    61  	_, r.Err = client.Post(rootURL(client), reqBody, &r.Body, nil)
    62  	return
    63  }
    64  
    65  // Get is a method to obtain the specified APIG dedicated instance according to the instance Id.
    66  func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
    67  	_, r.Err = client.Get(resourceURL(client, id), &r.Body, nil)
    68  	return
    69  }
    70  
    71  // ListOpts allows to filter list data using given parameters.
    72  type ListOpts struct {
    73  	// ID of the APIG dedicated instance.
    74  	Id string `q:"instance_id"`
    75  	// Name of the APIG dedicated instance.
    76  	Name string `q:"instance_name"`
    77  	// Instance status.
    78  	Status string `q:"status"`
    79  	// Offset from which the query starts.
    80  	// If the offset is less than 0, the value is automatically converted to 0. Default to 0.
    81  	Offset int `q:"offset"`
    82  	// Number of items displayed on each page.
    83  	Limit int `q:"limit"`
    84  }
    85  
    86  type ListOptsBuilder interface {
    87  	ToInstanceListQuery() (string, error)
    88  }
    89  
    90  func (opts ListOpts) ToInstanceListQuery() (string, error) {
    91  	q, err := golangsdk.BuildQueryString(opts)
    92  	if err != nil {
    93  		return "", err
    94  	}
    95  	return q.String(), err
    96  }
    97  
    98  // List is a method to obtain an array of one or more APIG dedicated instance according to the query parameters.
    99  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
   100  	url := rootURL(client)
   101  	if opts != nil {
   102  		query, err := opts.ToInstanceListQuery()
   103  		if err != nil {
   104  			return pagination.Pager{Err: err}
   105  		}
   106  		url += query
   107  	}
   108  
   109  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   110  		return InstancePage{pagination.SinglePageBase(r)}
   111  	})
   112  }
   113  
   114  // UpdateOpts allows to update an existing APIG dedicated instance using given parameters.
   115  type UpdateOpts struct {
   116  	// Description about the APIG dedicated instance.
   117  	Description string `json:"description,omitempty"`
   118  	// Start time of the maintenance time window in the format "xx:00:00".
   119  	// The value of xx can be 02, 06, 10, 14, 18, or 22.
   120  	MaintainBegin string `json:"maintain_begin,omitempty"`
   121  	// End time of the maintenance time window in the format "xx:00:00".
   122  	// There is a 4-hour difference between the start time and end time.
   123  	MaintainEnd string `json:"maintain_end,omitempty"`
   124  	// Description about the APIG dedicated instance.
   125  	Name string `json:"instance_name,omitempty"`
   126  	// ID of the security group to which the APIG dedicated instance belongs to.
   127  	SecurityGroupId string `json:"security_group_id,omitempty"`
   128  }
   129  
   130  type UpdateOptsBuilder interface {
   131  	ToInstanceUpdateMap() (map[string]interface{}, error)
   132  }
   133  
   134  func (opts UpdateOpts) ToInstanceUpdateMap() (map[string]interface{}, error) {
   135  	return golangsdk.BuildRequestBody(opts, "")
   136  }
   137  
   138  // Update is a method by which to update an existing APIG dedicated instance.
   139  func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
   140  	reqBody, err := opts.ToInstanceUpdateMap()
   141  	if err != nil {
   142  		r.Err = err
   143  		return
   144  	}
   145  	_, r.Err = client.Put(resourceURL(client, id), reqBody, &r.Body, &golangsdk.RequestOpts{
   146  		OkCodes: []int{200},
   147  	})
   148  	return
   149  }
   150  
   151  // Delete is a method to delete an existing APIG dedicated instance
   152  func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
   153  	_, r.Err = client.Delete(resourceURL(client, id), nil)
   154  	return
   155  }
   156  
   157  // EgressAccessOpts allows the bandwidth size of an existing APIG dedicated instance to be updated with the given
   158  // parameters.
   159  type EgressAccessOpts struct {
   160  	// Outbound access bandwidth, in Mbit/s.
   161  	BandwidthSize string `json:"bandwidth_size,omitempty"`
   162  }
   163  
   164  type EgressAccessOptsBuilder interface {
   165  	ToEgressAccessMap() (map[string]interface{}, error)
   166  }
   167  
   168  func (opts EgressAccessOpts) ToEgressAccessMap() (map[string]interface{}, error) {
   169  	return golangsdk.BuildRequestBody(opts, "")
   170  }
   171  
   172  // EnableEgressAccess is a method by which to enable the egress access of an existing APIG dedicated instance.
   173  func EnableEgressAccess(client *golangsdk.ServiceClient, id string, opts EgressAccessOptsBuilder) (r EnableEgressResult) {
   174  	reqBody, err := opts.ToEgressAccessMap()
   175  	if err != nil {
   176  		r.Err = err
   177  		return
   178  	}
   179  	_, r.Err = client.Post(egressURL(client, id), reqBody, &r.Body, &golangsdk.RequestOpts{
   180  		OkCodes: []int{200, 201},
   181  	})
   182  	return
   183  }
   184  
   185  // UpdateEgressBandwidth is a method by which to update the egress bandwidth size of an existing APIG dedicated instance.
   186  func UpdateEgressBandwidth(client *golangsdk.ServiceClient, id string, opts EgressAccessOptsBuilder) (r UdpateEgressResult) {
   187  	reqBody, err := opts.ToEgressAccessMap()
   188  	if err != nil {
   189  		r.Err = err
   190  		return
   191  	}
   192  	_, r.Err = client.Put(egressURL(client, id), reqBody, &r.Body, &golangsdk.RequestOpts{
   193  		OkCodes: []int{200},
   194  	})
   195  	return
   196  }
   197  
   198  // DisableEgressAccess is a method by which to disable the egress access of an existing APIG dedicated instance.
   199  func DisableEgressAccess(client *golangsdk.ServiceClient, id string) (r DisableEgressResult) {
   200  	_, r.Err = client.Delete(egressURL(client, id), nil)
   201  	return
   202  }
   203  
   204  // IngressAccessOpts allows binding and updating the eip associated with an existing APIG dedicated instance with the
   205  // given parameters.
   206  type IngressAccessOpts struct {
   207  	// EIP ID
   208  	EipId string `json:"eip_id,omitempty"`
   209  }
   210  
   211  type IngressAccessOptsBuilder interface {
   212  	ToEnableIngressAccessMap() (map[string]interface{}, error)
   213  }
   214  
   215  func (opts IngressAccessOpts) ToEnableIngressAccessMap() (map[string]interface{}, error) {
   216  	return golangsdk.BuildRequestBody(opts, "")
   217  }
   218  
   219  // UpdateIngressAccess is a method to bind and update the eip associated with an existing APIG dedicated instance.
   220  func EnableIngressAccess(client *golangsdk.ServiceClient, id string, opts IngressAccessOptsBuilder) (r EnableIngressResult) {
   221  	reqBody, err := opts.ToEnableIngressAccessMap()
   222  	if err != nil {
   223  		r.Err = err
   224  		return
   225  	}
   226  	_, r.Err = client.Put(ingressURL(client, id), reqBody, &r.Body, &golangsdk.RequestOpts{
   227  		OkCodes: []int{200},
   228  	})
   229  	return
   230  }
   231  
   232  // DisableIngressAccess is a method to unbind the eip associated with an existing APIG dedicated instance.
   233  func DisableIngressAccess(client *golangsdk.ServiceClient, id string) (r DisableIngressResult) {
   234  	_, r.Err = client.Delete(ingressURL(client, id), &golangsdk.RequestOpts{
   235  		OkCodes: []int{200},
   236  	})
   237  	return
   238  }