github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/cse/dedicated/v2/engines/requests.go (about)

     1  package engines
     2  
     3  import "github.com/chnsz/golangsdk"
     4  
     5  // CreateOpts is the structure required by the Create method to create a new engine.
     6  type CreateOpts struct {
     7  	// The name of the dedicated microservice engine.
     8  	// The value can contain 3 to 24 characters, including letters, digits, and hyphens (-).
     9  	// It must start with a letter and cannot end with a hyphen.
    10  	Name string `json:"name" required:"true"`
    11  	// The charging mode of the dedicated microservice engine.
    12  	Payment string `json:"payment" required:"true"`
    13  	// The flavor of the dedicated microservice engine.
    14  	//   cse.s1.small2: High availability 100 instance engine.
    15  	//   cse.s1.medium2: High availability 200 instance engine.
    16  	//   cse.s1.large2: High availability 500 instance engine.
    17  	//   cse.s1.xlarge2: High availability 2000 instance engine.
    18  	Flavor string `json:"flavor" required:"true"`
    19  	// List of available zones for the current region.
    20  	AvailabilityZones []string `json:"azList" required:"true"`
    21  	// The authentication method for the dedicated microservice engine.
    22  	// The "RBAC" is security authentication, and the "NONE" is no authentication.
    23  	AuthType string `json:"authType" required:"true"`
    24  	// The VPC name.
    25  	VpcName string `json:"vpc" required:"true"`
    26  	// The network ID of the subnet.
    27  	NetworkId string `json:"networkId" required:"true"`
    28  	// The subnet CIDR.
    29  	SubnetCidr string `json:"subnetCidr" required:"true"`
    30  	// The deployment type of the dedicated microservice engine. The fixed value is "CSE2".
    31  	SpecType string `json:"specType" required:"true"`
    32  	// The description of the dedicated microservice engine. The value can contain up to 255 characters.
    33  	Description string `json:"description,omitempty"`
    34  	// The VPC ID.
    35  	VpcId string `json:"vpcId,omitempty"`
    36  	// The public access for the dedicated microservice engine.
    37  	PublicIpId string `json:"publicIpId,omitempty"`
    38  	// The dedicated microservice engine must be passed when security authentication is selected,
    39  	// including the authentication information of the engine.
    40  	AuthCred *AuthCred `json:"auth_cred,omitempty"`
    41  	// The additional parameters of the dedicated microservice engine.
    42  	Inputs map[string]interface{} `json:"inputs,omitempty"`
    43  	// The enterprise project ID to which the dedicated microservice engine.
    44  	EnterpriseProjectId string `json:"-"`
    45  }
    46  
    47  // AuthCred is an object that specifies the configuration of the security authentication.
    48  type AuthCred struct {
    49  	// The root account password that needs to be specified when selecting security authentication.
    50  	Password string `json:"pwd" required:"true"`
    51  }
    52  
    53  func buildMoreHeaderUsingEpsId(epsId string) map[string]string {
    54  	moreHeader := map[string]string{
    55  		"Content-Type": "application/json",
    56  		"X-Language":   "en-us",
    57  	}
    58  
    59  	if epsId != "" {
    60  		moreHeader["X-Enterprise-Project-ID"] = epsId
    61  	}
    62  
    63  	return moreHeader
    64  }
    65  
    66  // Create is a method to create a microservice engine using given parameters.
    67  func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*RequestResp, error) {
    68  	b, err := golangsdk.BuildRequestBody(opts, "")
    69  	if err != nil {
    70  		return nil, err
    71  	}
    72  
    73  	var r RequestResp
    74  	_, err = c.Post(rootURL(c), b, &r, &golangsdk.RequestOpts{
    75  		MoreHeaders: buildMoreHeaderUsingEpsId(opts.EnterpriseProjectId),
    76  	})
    77  	return &r, err
    78  }
    79  
    80  // Get is a method to retrieves a particular configuration based on its unique ID and enterprise project ID.
    81  func Get(c *golangsdk.ServiceClient, engineId, epsId string) (*Engine, error) {
    82  	var r Engine
    83  	_, err := c.Get(resourceURL(c, engineId), &r, &golangsdk.RequestOpts{
    84  		MoreHeaders: buildMoreHeaderUsingEpsId(epsId),
    85  	})
    86  	return &r, err
    87  }
    88  
    89  // Delete is a method to remove an existing engine using its unique ID and enterprise project ID.
    90  func Delete(c *golangsdk.ServiceClient, engineId, epsId string) (*RequestResp, error) {
    91  	var r RequestResp
    92  	_, err := c.Delete(resourceURL(c, engineId), &golangsdk.RequestOpts{
    93  		JSONResponse: &r,
    94  		MoreHeaders:  buildMoreHeaderUsingEpsId(epsId),
    95  	})
    96  	return &r, err
    97  }
    98  
    99  // GetJob is a method to obtain the job detail using engine ID and job ID.
   100  func GetJob(c *golangsdk.ServiceClient, engineId, jobId, epsId string) (*Job, error) {
   101  	var r Job
   102  	_, err := c.Get(jobURL(c, engineId, jobId), &r, &golangsdk.RequestOpts{
   103  		MoreHeaders: buildMoreHeaderUsingEpsId(epsId),
   104  	})
   105  	return &r, err
   106  }