Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues for creating blb,cce #69

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions bce/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (c *BceClient) buildHttpRequest(request *BceRequest) {

// Set the BCE request headers
request.SetHeader(http.HOST, request.Host())
request.SetHeader(http.CONTENT_TYPE, "application/json;charset=UTF-8")
request.SetHeader(http.USER_AGENT, c.Config.UserAgent)
request.SetHeader(http.BCE_DATE, util.FormatISO8601Date(util.NowUTCSeconds()))

Expand Down Expand Up @@ -253,12 +254,12 @@ func NewBceClientWithAkSk(ak, sk, endPoint string) (*BceClient, error) {
HeadersToSign: auth.DEFAULT_HEADERS_TO_SIGN,
ExpireSeconds: auth.DEFAULT_EXPIRE_SECONDS}
defaultConf := &BceClientConfiguration{
Endpoint: endPoint,
Region: DEFAULT_REGION,
UserAgent: DEFAULT_USER_AGENT,
Credentials: credentials,
SignOption: defaultSignOptions,
Retry: DEFAULT_RETRY_POLICY,
Endpoint: endPoint,
Region: DEFAULT_REGION,
UserAgent: DEFAULT_USER_AGENT,
Credentials: credentials,
SignOption: defaultSignOptions,
Retry: DEFAULT_RETRY_POLICY,
ConnectionTimeoutInMillis: DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS,
RedirectDisabled: false}
v1Signer := &auth.BceV1Signer{}
Expand Down
24 changes: 23 additions & 1 deletion services/bbc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package bbc

import (
"encoding/json"

"github.com/baidubce/bce-sdk-go/auth"
"github.com/baidubce/bce-sdk-go/bce"
"github.com/baidubce/bce-sdk-go/services/bcc/api"
Expand Down Expand Up @@ -656,6 +657,28 @@ func (c *Client) ListImage(args *ListImageArgs) (*ListImageResult, error) {
return ListImage(c, args)
}

//ListImage - list Custom Flavor images
//
// PARAMS:
// - args: the arguments to list all images
// RETURNS:
// - *ListImageResult: the result of list all images
// - error: nil if success otherwise the specific error
func (c *Client) ListCustomFlavorImage(args *ListImageArgs) (*FlavorImageResult, error) {
return ListCustomFlavorImage(c, args)
}

//ListImage - list Flavor images
//
// PARAMS:
// - args: the arguments to list all images
// RETURNS:
// - *ListImageResult: the result of list all images
// - error: nil if success otherwise the specific error
func (c *Client) ListFlavorImage(args *ListImageArgs) (*FlavorImageResult, error) {
return ListFlavorImage(c, args)
}

// GetImageDetail - get an image's detail info
//
// PARAMS:
Expand Down Expand Up @@ -908,7 +931,6 @@ func (c *Client) RemoteCopyImage(imageId string, args *RemoteCopyImageArgs) erro
return RemoteCopyImage(c, imageId, args)
}


// RemoteCopyImageReturnImageIds - copy an image from other region
//
// PARAMS:
Expand Down
101 changes: 100 additions & 1 deletion services/bbc/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,98 @@ func ListImage(cli bce.Client, queryArgs *ListImageArgs) (*ListImageResult, erro
return jsonBody, nil
}

//ListImage - list custom flavor images
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - args: the arguments to list all images
// RETURNS:
// - *ListImageResult: the result of list all images
// - error: nil if success otherwise the specific error
func ListCustomFlavorImage(cli bce.Client, queryArgs *ListImageArgs) (*FlavorImageResult, error) {
// Build the request
req := &bce.BceRequest{}
req.SetUri(getCustomFlavorImageUri())
req.SetMethod(http.POST)

if queryArgs != nil {
if len(queryArgs.Marker) != 0 {
req.SetParam("marker", queryArgs.Marker)
}
if queryArgs.MaxKeys != 0 {
req.SetParam("maxKeys", strconv.Itoa(queryArgs.MaxKeys))
}
if len(queryArgs.ImageType) != 0 {
req.SetParam("imageType", queryArgs.ImageType)
}
}

if queryArgs == nil || queryArgs.MaxKeys == 0 {
req.SetParam("maxKeys", "1000")
}

// Send request and get response
resp := &bce.BceResponse{}
if err := cli.SendRequest(req, resp); err != nil {
return nil, err
}
if resp.IsFail() {
return nil, resp.ServiceError()
}

jsonBody := &FlavorImageResult{}
if err := resp.ParseJsonBody(jsonBody); err != nil {
return nil, err
}
return jsonBody, nil
}

//ListImage - list flavor images
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - args: the arguments to list all images
// RETURNS:
// - *ListImageResult: the result of list all images
// - error: nil if success otherwise the specific error
func ListFlavorImage(cli bce.Client, queryArgs *ListImageArgs) (*FlavorImageResult, error) {
// Build the request
req := &bce.BceRequest{}
req.SetUri(getFlavorImageUri())
req.SetMethod(http.POST)

if queryArgs != nil {
if len(queryArgs.Marker) != 0 {
req.SetParam("marker", queryArgs.Marker)
}
if queryArgs.MaxKeys != 0 {
req.SetParam("maxKeys", strconv.Itoa(queryArgs.MaxKeys))
}
if len(queryArgs.ImageType) != 0 {
req.SetParam("imageType", queryArgs.ImageType)
}
}

if queryArgs == nil || queryArgs.MaxKeys == 0 {
req.SetParam("maxKeys", "1000")
}

// Send request and get response
resp := &bce.BceResponse{}
if err := cli.SendRequest(req, resp); err != nil {
return nil, err
}
if resp.IsFail() {
return nil, resp.ServiceError()
}

jsonBody := &FlavorImageResult{}
if err := resp.ParseJsonBody(jsonBody); err != nil {
return nil, err
}
return jsonBody, nil
}

// GetImageDetail - get an image's detail info
//
// PARAMS:
Expand Down Expand Up @@ -449,6 +541,13 @@ func getImageUri() string {
return URI_PREFIX_V1 + REQUEST_IMAGE_URI
}

func getFlavorImageUri() string {
return URI_PREFIX_V1 + "/flavor/image"
}
func getCustomFlavorImageUri() string {
return URI_PREFIX_V1 + "/customFlavor/image"
}

func getImageUriWithId(id string) string {
return URI_PREFIX_V1 + REQUEST_IMAGE_URI + "/" + id
}
Expand All @@ -463,4 +562,4 @@ func getCustomImageUri() string {

func getImageSharedUserUri(id string) string {
return URI_PREFIX_V1 + REQUEST_IMAGE_URI + "/" + id + REQUEST_IMAGE_SHAREDUSER_URI
}
}
40 changes: 25 additions & 15 deletions services/bbc/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ type CreateInstanceArgs struct {
Tags []model.TagModel `json:"tags,omitempty"`
InternalIps []string `json:"internalIps,omitempty"`
RequestToken string `json:"requestToken"`
EnableNuma bool `json:"enableNuma"`
EnableNuma bool `json:"enableNuma,omitempty"`
EnableHt bool `json:"enableHt"`
RootPartitionType string `json:"rootPartitionType,omitempty"`
DataPartitionType string `json:"dataPartitionType,omitempty"`
KeypairId string `json:"keypairId,omitempty"`
}

const (
Expand Down Expand Up @@ -216,23 +218,23 @@ type ListRecycledInstancesResult struct {
}

type RecycledInstancesModel struct {
ServiceType string `json:"serviceType"`
ServiceName string `json:"serviceName"`
Name string `json:"name"`
Id string `json:"id"`
SerialNumber string `json:"serialNumber"`
RecycleTime string `json:"recycleTime"`
DeleteTime string `json:"deleteTime"`
PaymentTiming string `json:"paymentTiming"`
ConfigItems []string `json:"configItems"`
ConfigItem RecycleInstanceModelConfigItem `json:"configItem"`
ServiceType string `json:"serviceType"`
ServiceName string `json:"serviceName"`
Name string `json:"name"`
Id string `json:"id"`
SerialNumber string `json:"serialNumber"`
RecycleTime string `json:"recycleTime"`
DeleteTime string `json:"deleteTime"`
PaymentTiming string `json:"paymentTiming"`
ConfigItems []string `json:"configItems"`
ConfigItem RecycleInstanceModelConfigItem `json:"configItem"`
}

type RecycleInstanceModelConfigItem struct {
Cpu int `json:"cpu"`
Memory int `json:"memory"`
Type string `json:"type"`
ZoneName string `json:"zoneName"`
Cpu int `json:"cpu"`
Memory int `json:"memory"`
Type string `json:"type"`
ZoneName string `json:"zoneName"`
}

type ListInstancesResult struct {
Expand Down Expand Up @@ -304,6 +306,7 @@ type ModifyInstanceHostnameArgs struct {
type RebuildInstanceArgs struct {
ImageId string `json:"imageId"`
AdminPass string `json:"adminPass"`
KeypairId string `json:"keypairId,omitempty"`
IsPreserveData bool `json:"isPreserveData"`
RaidId string `json:"raidId,omitempty"`
SysRootSize int `json:"sysRootSize,omitempty"`
Expand Down Expand Up @@ -423,6 +426,13 @@ type ListImageResult struct {
MaxKeys int `json:"maxKeys"`
Images []ImageModel `json:"images"`
}
type FlavorImageMapping struct {
FlavorID string `json:"flavorId"`
Images []ImageModel `json:"images"`
}
type FlavorImageResult struct {
Result []FlavorImageMapping `json:"result"`
}

type ImageModel struct {
OsVersion string `json:"osVersion"`
Expand Down
27 changes: 27 additions & 0 deletions services/bcc/api/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,33 @@ func InstancePurchaseReserved(cli bce.Client, instanceId, relatedRenewFlag, clie
return nil
}

// DeletePrepaidInstanceWithRelatedResource - delete a prepaid instance with related resources
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - reqBody: request body to delete instance
// RETURNS:
// - error: nil if success otherwise the specific error
func DeletePrepaidInstanceWithRelatedResource(cli bce.Client, reqBody *bce.Body) error {
// Build the request
req := &bce.BceRequest{}
req.SetUri(getDeletePrepaidInstanceUri())
req.SetMethod(http.POST)
req.SetBody(reqBody)

// Send request and get response
resp := &bce.BceResponse{}
if err := cli.SendRequest(req, resp); err != nil {
return err
}
if resp.IsFail() {
return resp.ServiceError()
}

defer func() { resp.Body().Close() }()
return nil
}

// DeleteInstanceWithRelatedResource - delete an instance with related resources
//
// PARAMS:
Expand Down
7 changes: 7 additions & 0 deletions services/bcc/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,13 @@ type DeleteInstanceWithRelateResourceArgs struct {
DeleteRelatedEnisFlag bool `json:"deleteRelatedEnisFlag"`
}

type DeletePrepaidInstanceWithRelateResourceArgs struct {
RelatedReleaseFlag bool `json:"relatedReleaseFlag"`
DeleteCdsSnapshotFlag bool `json:"deleteCdsSnapshotFlag"`
InstanceId string `json:"instanceId"`
DeleteRelatedEnisFlag bool `json:"deleteRelatedEnisFlag"`
}

type InstanceChangeVpcArgs struct {
InstanceId string `json:"instanceId"`
SubnetId string `json:"subnetId"`
Expand Down
3 changes: 3 additions & 0 deletions services/bcc/api/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func getInstanceBySpecUri() string {
func getInstanceUriWithId(id string) string {
return URI_PREFIXV2 + REQUEST_INSTANCE_URI + "/" + id
}
func getDeletePrepaidInstanceUri() string {
return URI_PREFIXV2 + REQUEST_INSTANCE_URI + "/delete"
}

func getRecoveryInstanceUri() string {
return URI_PREFIXV2 + REQUEST_INSTANCE_URI + REQUEST_RECOVERY_URI
Expand Down
26 changes: 20 additions & 6 deletions services/bcc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (c *Client) DeleteInstance(instanceId string) error {
// - error: nil if success otherwise the specific error
func (c *Client) AutoReleaseInstance(instanceId string, releaseTime string) error {
args := &api.AutoReleaseArgs{
ReleaseTime: releaseTime,
ReleaseTime: releaseTime,
}
return api.AutoReleaseInstance(c, instanceId, args)
}
Expand Down Expand Up @@ -632,6 +632,25 @@ func (c *Client) DeleteInstanceWithRelateResource(instanceId string, args *api.D
return api.DeleteInstanceWithRelatedResource(c, instanceId, body)
}

// DeletePrepaidInstanceWithRelateResource - delete a prepaid instance and all eip/cds relate it
//
// PARAMS:
// - args: the arguments to delete instance and its relate resource
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeletePrepaidInstanceWithRelateResource(args *api.DeletePrepaidInstanceWithRelateResourceArgs) error {
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}

return api.DeletePrepaidInstanceWithRelatedResource(c, body)
}

// InstanceChangeSubnet - change an instance's subnet
//
// PARAMS:
Expand Down Expand Up @@ -1015,7 +1034,6 @@ func (c *Client) RemoteCopyImage(imageId string, args *api.RemoteCopyImageArgs)
return api.RemoteCopyImage(c, imageId, args)
}


// RemoteCopyImageReturnImageIds - copy an image from other region
//
// PARAMS:
Expand Down Expand Up @@ -1531,7 +1549,6 @@ func (c *Client) GetAvailableDiskInfo(zoneName string) (*api.GetAvailableDiskInf
return api.GetAvailableDiskInfo(c, zoneName)
}


// DeletePrepayVolume - delete the volumes for prepay
//
// PARAMS:
Expand Down Expand Up @@ -1690,6 +1707,3 @@ func (c *Client) DeleteRecycledInstance(instanceId string) error {
func (c *Client) ListInstanceByInstanceIds(args *api.ListInstanceByInstanceIdArgs) (*api.ListInstancesResult, error) {
return api.ListInstanceByInstanceIds(c, args)
}



Loading