github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/sharedfilesystems/v2/sharenetworks/requests.go (about)

     1  package sharenetworks
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/vnpaycloud-console/gophercloud/v2"
     7  	"github.com/vnpaycloud-console/gophercloud/v2/pagination"
     8  )
     9  
    10  // CreateOptsBuilder allows extensions to add additional parameters to the
    11  // Create request.
    12  type CreateOptsBuilder interface {
    13  	ToShareNetworkCreateMap() (map[string]any, error)
    14  }
    15  
    16  // CreateOpts contains options for creating a ShareNetwork. This object is
    17  // passed to the sharenetworks.Create function. For more information about
    18  // these parameters, see the ShareNetwork object.
    19  type CreateOpts struct {
    20  	// The UUID of the Neutron network to set up for share servers
    21  	NeutronNetID string `json:"neutron_net_id,omitempty"`
    22  	// The UUID of the Neutron subnet to set up for share servers
    23  	NeutronSubnetID string `json:"neutron_subnet_id,omitempty"`
    24  	// The UUID of the nova network to set up for share servers
    25  	NovaNetID string `json:"nova_net_id,omitempty"`
    26  	// The share network name
    27  	Name string `json:"name"`
    28  	// The share network description
    29  	Description string `json:"description"`
    30  }
    31  
    32  // ToShareNetworkCreateMap assembles a request body based on the contents of a
    33  // CreateOpts.
    34  func (opts CreateOpts) ToShareNetworkCreateMap() (map[string]any, error) {
    35  	return gophercloud.BuildRequestBody(opts, "share_network")
    36  }
    37  
    38  // Create will create a new ShareNetwork based on the values in CreateOpts. To
    39  // extract the ShareNetwork object from the response, call the Extract method
    40  // on the CreateResult.
    41  func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    42  	b, err := opts.ToShareNetworkCreateMap()
    43  	if err != nil {
    44  		r.Err = err
    45  		return
    46  	}
    47  	resp, err := client.Post(ctx, createURL(client), b, &r.Body, &gophercloud.RequestOpts{
    48  		OkCodes: []int{200, 202},
    49  	})
    50  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    51  	return
    52  }
    53  
    54  // Delete will delete the existing ShareNetwork with the provided ID.
    55  func Delete(ctx context.Context, client *gophercloud.ServiceClient, id string) (r DeleteResult) {
    56  	resp, err := client.Delete(ctx, deleteURL(client, id), nil)
    57  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    58  	return
    59  }
    60  
    61  // ListOptsBuilder allows extensions to add additional parameters to the List
    62  // request.
    63  type ListOptsBuilder interface {
    64  	ToShareNetworkListQuery() (string, error)
    65  }
    66  
    67  // ListOpts holds options for listing ShareNetworks. It is passed to the
    68  // sharenetworks.List function.
    69  type ListOpts struct {
    70  	// admin-only option. Set it to true to see all tenant share networks.
    71  	AllTenants bool `q:"all_tenants"`
    72  	// The UUID of the project where the share network was created
    73  	ProjectID string `q:"project_id"`
    74  	// The neutron network ID
    75  	NeutronNetID string `q:"neutron_net_id"`
    76  	// The neutron subnet ID
    77  	NeutronSubnetID string `q:"neutron_subnet_id"`
    78  	// The nova network ID
    79  	NovaNetID string `q:"nova_net_id"`
    80  	// The network type. A valid value is VLAN, VXLAN, GRE or flat
    81  	NetworkType string `q:"network_type"`
    82  	// The Share Network name
    83  	Name string `q:"name"`
    84  	// The Share Network description
    85  	Description string `q:"description"`
    86  	// The Share Network IP version
    87  	IPVersion gophercloud.IPVersion `q:"ip_version"`
    88  	// The Share Network segmentation ID
    89  	SegmentationID int `q:"segmentation_id"`
    90  	// List all share networks created after the given date
    91  	CreatedSince string `q:"created_since"`
    92  	// List all share networks created before the given date
    93  	CreatedBefore string `q:"created_before"`
    94  	// Limit specifies the page size.
    95  	Limit int `q:"limit"`
    96  	// Limit specifies the page number.
    97  	Offset int `q:"offset"`
    98  }
    99  
   100  // ToShareNetworkListQuery formats a ListOpts into a query string.
   101  func (opts ListOpts) ToShareNetworkListQuery() (string, error) {
   102  	q, err := gophercloud.BuildQueryString(opts)
   103  	return q.String(), err
   104  }
   105  
   106  // ListDetail returns ShareNetworks optionally limited by the conditions provided in ListOpts.
   107  func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
   108  	url := listDetailURL(client)
   109  	if opts != nil {
   110  		query, err := opts.ToShareNetworkListQuery()
   111  		if err != nil {
   112  			return pagination.Pager{Err: err}
   113  		}
   114  		url += query
   115  	}
   116  
   117  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   118  		p := ShareNetworkPage{pagination.MarkerPageBase{PageResult: r}}
   119  		p.MarkerPageBase.Owner = p
   120  		return p
   121  	})
   122  }
   123  
   124  // Get retrieves the ShareNetwork with the provided ID. To extract the ShareNetwork
   125  // object from the response, call the Extract method on the GetResult.
   126  func Get(ctx context.Context, client *gophercloud.ServiceClient, id string) (r GetResult) {
   127  	resp, err := client.Get(ctx, getURL(client, id), &r.Body, nil)
   128  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   129  	return
   130  }
   131  
   132  // UpdateOptsBuilder allows extensions to add additional parameters to the
   133  // Update request.
   134  type UpdateOptsBuilder interface {
   135  	ToShareNetworkUpdateMap() (map[string]any, error)
   136  }
   137  
   138  // UpdateOpts contain options for updating an existing ShareNetwork. This object is passed
   139  // to the sharenetworks.Update function. For more information about the parameters, see
   140  // the ShareNetwork object.
   141  type UpdateOpts struct {
   142  	// The share network name
   143  	Name *string `json:"name,omitempty"`
   144  	// The share network description
   145  	Description *string `json:"description,omitempty"`
   146  	// The UUID of the Neutron network to set up for share servers
   147  	NeutronNetID string `json:"neutron_net_id,omitempty"`
   148  	// The UUID of the Neutron subnet to set up for share servers
   149  	NeutronSubnetID string `json:"neutron_subnet_id,omitempty"`
   150  	// The UUID of the nova network to set up for share servers
   151  	NovaNetID string `json:"nova_net_id,omitempty"`
   152  }
   153  
   154  // ToShareNetworkUpdateMap assembles a request body based on the contents of an
   155  // UpdateOpts.
   156  func (opts UpdateOpts) ToShareNetworkUpdateMap() (map[string]any, error) {
   157  	return gophercloud.BuildRequestBody(opts, "share_network")
   158  }
   159  
   160  // Update will update the ShareNetwork with provided information. To extract the updated
   161  // ShareNetwork from the response, call the Extract method on the UpdateResult.
   162  func Update(ctx context.Context, client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
   163  	b, err := opts.ToShareNetworkUpdateMap()
   164  	if err != nil {
   165  		r.Err = err
   166  		return
   167  	}
   168  	resp, err := client.Put(ctx, updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
   169  		OkCodes: []int{200},
   170  	})
   171  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   172  	return
   173  }
   174  
   175  // AddSecurityServiceOptsBuilder allows extensions to add additional parameters to the
   176  // AddSecurityService request.
   177  type AddSecurityServiceOptsBuilder interface {
   178  	ToShareNetworkAddSecurityServiceMap() (map[string]any, error)
   179  }
   180  
   181  // AddSecurityServiceOpts contain options for adding a security service to an
   182  // existing ShareNetwork. This object is passed to the sharenetworks.AddSecurityService
   183  // function. For more information about the parameters, see the ShareNetwork object.
   184  type AddSecurityServiceOpts struct {
   185  	SecurityServiceID string `json:"security_service_id"`
   186  }
   187  
   188  // ToShareNetworkAddSecurityServiceMap assembles a request body based on the contents of an
   189  // AddSecurityServiceOpts.
   190  func (opts AddSecurityServiceOpts) ToShareNetworkAddSecurityServiceMap() (map[string]any, error) {
   191  	return gophercloud.BuildRequestBody(opts, "add_security_service")
   192  }
   193  
   194  // AddSecurityService will add the security service to a ShareNetwork. To extract the updated
   195  // ShareNetwork from the response, call the Extract method on the UpdateResult.
   196  func AddSecurityService(ctx context.Context, client *gophercloud.ServiceClient, id string, opts AddSecurityServiceOptsBuilder) (r UpdateResult) {
   197  	b, err := opts.ToShareNetworkAddSecurityServiceMap()
   198  	if err != nil {
   199  		r.Err = err
   200  		return
   201  	}
   202  	resp, err := client.Post(ctx, addSecurityServiceURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
   203  		OkCodes: []int{200},
   204  	})
   205  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   206  	return
   207  }
   208  
   209  // RemoveSecurityServiceOptsBuilder allows extensions to add additional parameters to the
   210  // RemoveSecurityService request.
   211  type RemoveSecurityServiceOptsBuilder interface {
   212  	ToShareNetworkRemoveSecurityServiceMap() (map[string]any, error)
   213  }
   214  
   215  // RemoveSecurityServiceOpts contain options for removing a security service from an
   216  // existing ShareNetwork. This object is passed to the sharenetworks.RemoveSecurityService
   217  // function. For more information about the parameters, see the ShareNetwork object.
   218  type RemoveSecurityServiceOpts struct {
   219  	SecurityServiceID string `json:"security_service_id"`
   220  }
   221  
   222  // ToShareNetworkRemoveSecurityServiceMap assembles a request body based on the contents of an
   223  // RemoveSecurityServiceOpts.
   224  func (opts RemoveSecurityServiceOpts) ToShareNetworkRemoveSecurityServiceMap() (map[string]any, error) {
   225  	return gophercloud.BuildRequestBody(opts, "remove_security_service")
   226  }
   227  
   228  // RemoveSecurityService will remove the security service from a ShareNetwork. To extract the updated
   229  // ShareNetwork from the response, call the Extract method on the UpdateResult.
   230  func RemoveSecurityService(ctx context.Context, client *gophercloud.ServiceClient, id string, opts RemoveSecurityServiceOptsBuilder) (r UpdateResult) {
   231  	b, err := opts.ToShareNetworkRemoveSecurityServiceMap()
   232  	if err != nil {
   233  		r.Err = err
   234  		return
   235  	}
   236  	resp, err := client.Post(ctx, removeSecurityServiceURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
   237  		OkCodes: []int{200},
   238  	})
   239  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   240  	return
   241  }