Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions openstack/swr/v2/namespaces/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package namespaces

import (
"github.com/huaweicloud/golangsdk"
)

var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{
MoreHeaders: map[string]string{"Content-Type": "application/json"},
}

// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToNamespaceCreateMap() (map[string]interface{}, error)
}

// CreateOpts contains all the values needed to create a new network
type CreateOpts struct {
Namespace string `json:"namespace" required:"true"`
}

// ToNamespaceCreateMap builds a create request body from CreateOpts.
func (opts CreateOpts) ToNamespaceCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "")
}

// Create accepts a CreateOpts struct and uses the values to create a new namespace.
func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToNamespaceCreateMap()
if err != nil {
r.Err = err
return
}
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{201}}
_, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt)
return
}

// Get retrieves a particular network based on its unique ID.
func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
_, r.Err = c.Get(resourceURL(c, id), &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: RequestOpts.MoreHeaders, JSONBody: nil,
})
return
}

// Delete will permanently delete a particular network based on its unique ID.
func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) {
_, r.Err = c.Delete(resourceURL(c, id), &golangsdk.RequestOpts{
OkCodes: []int{204},
MoreHeaders: RequestOpts.MoreHeaders, JSONBody: nil,
})
return
}
42 changes: 42 additions & 0 deletions openstack/swr/v2/namespaces/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package namespaces

import (
"github.com/huaweicloud/golangsdk"
)

type Namespace struct {
// Name of the Namespace
Name string `json:"name"`
// Creator Name of the Namespace
CreatorName string `json:"creator_name"`
// Auth permission of the Namespace
Auth int `json:"auth"`
}

type commonResult struct {
golangsdk.Result
}

// Extract is a function that accepts a result and extracts a namespace.
func (r commonResult) Extract() (*Namespace, error) {
var s Namespace
err := r.ExtractInto(&s)
return &s, err
}

// CreateResult represents the result of a create operation.
type CreateResult struct {
golangsdk.ErrResult
}

// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Network.
type GetResult struct {
commonResult
}

// DeleteResult represents the result of a delete operation. Call its ExtractErr
// method to determine if the request succeeded or failed.
type DeleteResult struct {
golangsdk.ErrResult
}
11 changes: 11 additions & 0 deletions openstack/swr/v2/namespaces/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package namespaces

import "github.com/huaweicloud/golangsdk"

func rootURL(client *golangsdk.ServiceClient) string {
return client.ServiceURL("manage", "namespaces")
}

func resourceURL(client *golangsdk.ServiceClient, name string) string {
return client.ServiceURL("manage", "namespaces", name)
}