github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/iec/v1/deployments/requests.go (about)

     1  package deployments
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/huaweicloud/golangsdk"
     7  	"github.com/huaweicloud/golangsdk/openstack/iec/v1/common"
     8  )
     9  
    10  // EdgeCloud 边缘业务
    11  type CreateOpts struct {
    12  	EdgeCloud EdgeCloud `json:"edgecloud"`
    13  }
    14  
    15  type EdgeCloud struct {
    16  	Name        string          `json:"name"`
    17  	Description string          `json:"description,omitempty"`
    18  	StackObj    StackDetail     `json:"stack"`
    19  	CoverageObj common.Coverage `json:"coverage"`
    20  }
    21  
    22  // StackDetail Stack详情
    23  type StackDetail struct {
    24  	//ID
    25  	ID string `json:"id"`
    26  
    27  	//NAME
    28  	Name string `json:"name"`
    29  
    30  	Resources SliceResourceOptsField `json:"resources"`
    31  }
    32  
    33  // SliceResourceOptsField A slice string field.
    34  type SliceResourceOptsField []common.ResourceOpts
    35  
    36  type CreateOptsBuilder interface {
    37  	ToDeploymentCreateMap() (map[string]interface{}, error)
    38  }
    39  
    40  func (opts CreateOpts) ToDeploymentCreateMap() (map[string]interface{}, error) {
    41  	b, err := golangsdk.BuildRequestBody(&opts, "")
    42  	if err != nil {
    43  		return nil, err
    44  	}
    45  	return b, nil
    46  }
    47  
    48  func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    49  	b, err := opts.ToDeploymentCreateMap()
    50  	if err != nil {
    51  		r.Err = err
    52  		return
    53  	}
    54  	url := CreateURL(client)
    55  	_, r.Err = client.Post(url, b, &r.Body, &golangsdk.RequestOpts{
    56  		OkCodes: []int{http.StatusOK},
    57  	})
    58  	return
    59  }
    60  
    61  func Deploy(client *golangsdk.ServiceClient, deploymentID string) (r DeployResult) {
    62  
    63  	url := DeployURL(client, deploymentID)
    64  	_, r.Err = client.Post(url, "", &r.Body, &golangsdk.RequestOpts{
    65  		OkCodes: []int{http.StatusOK},
    66  	})
    67  	return
    68  }
    69  
    70  func Expand(client *golangsdk.ServiceClient, deploymentID string) (r DeployResult) {
    71  
    72  	url := ExpandURL(client, deploymentID)
    73  	_, r.Err = client.Post(url, "", &r.Body, &golangsdk.RequestOpts{
    74  		OkCodes: []int{http.StatusOK},
    75  	})
    76  	return
    77  }
    78  
    79  func Delete(client *golangsdk.ServiceClient, deploymentID string) (r DeleteResult) {
    80  
    81  	_, r.Err = client.Delete(DeleteURL(client, deploymentID), &golangsdk.RequestOpts{
    82  		OkCodes: []int{http.StatusNoContent},
    83  	})
    84  	return
    85  }