4 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
8 // ListOpts filters the Tenants that are returned by the List call.
10 // Marker is the ID of the last Tenant on the previous page.
11 Marker string `q:"marker"`
13 // Limit specifies the page size.
17 // List enumerates the Tenants to which the current token has access.
18 func List(client *gophercloud.ServiceClient, opts *ListOpts) pagination.Pager {
19 url := listURL(client)
21 q, err := gophercloud.BuildQueryString(opts)
23 return pagination.Pager{Err: err}
27 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
28 return TenantPage{pagination.LinkedPageBase{PageResult: r}}
32 // CreateOpts represents the options needed when creating new tenant.
33 type CreateOpts struct {
34 // Name is the name of the tenant.
35 Name string `json:"name" required:"true"`
37 // Description is the description of the tenant.
38 Description string `json:"description,omitempty"`
40 // Enabled sets the tenant status to enabled or disabled.
41 Enabled *bool `json:"enabled,omitempty"`
44 // CreateOptsBuilder enables extensions to add additional parameters to the
46 type CreateOptsBuilder interface {
47 ToTenantCreateMap() (map[string]interface{}, error)
50 // ToTenantCreateMap assembles a request body based on the contents of
52 func (opts CreateOpts) ToTenantCreateMap() (map[string]interface{}, error) {
53 return gophercloud.BuildRequestBody(opts, "tenant")
56 // Create is the operation responsible for creating new tenant.
57 func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
58 b, err := opts.ToTenantCreateMap()
63 _, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
64 OkCodes: []int{200, 201},
69 // Get requests details on a single tenant by ID.
70 func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
71 _, r.Err = client.Get(getURL(client, id), &r.Body, nil)
75 // UpdateOptsBuilder allows extensions to add additional parameters to the
77 type UpdateOptsBuilder interface {
78 ToTenantUpdateMap() (map[string]interface{}, error)
81 // UpdateOpts specifies the base attributes that may be updated on an existing
83 type UpdateOpts struct {
84 // Name is the name of the tenant.
85 Name string `json:"name,omitempty"`
87 // Description is the description of the tenant.
88 Description *string `json:"description,omitempty"`
90 // Enabled sets the tenant status to enabled or disabled.
91 Enabled *bool `json:"enabled,omitempty"`
94 // ToTenantUpdateMap formats an UpdateOpts structure into a request body.
95 func (opts UpdateOpts) ToTenantUpdateMap() (map[string]interface{}, error) {
96 return gophercloud.BuildRequestBody(opts, "tenant")
99 // Update is the operation responsible for updating exist tenants by their TenantID.
100 func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
101 b, err := opts.ToTenantUpdateMap()
106 _, r.Err = client.Put(updateURL(client, id), &b, &r.Body, &gophercloud.RequestOpts{
112 // Delete is the operation responsible for permanently deleting a tenant.
113 func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
114 _, r.Err = client.Delete(deleteURL(client, id), nil)