github.com/gophercloud/gophercloud@v1.11.0/openstack/sharedfilesystems/v2/sharenetworks/requests.go (about)

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