cloud

package
v0.0.0-...-686bfca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

* Copyright (c) 2023 Baidu, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. *

Index

Constants

View Source
const (
	BCCEndpointEnv = "BCC_ENDPOINT"
	BBCEndpointEnv = "BBC_ENDPOINT"
	EIPEndpointEnv = "EIP_ENDPOINT"
)
View Source
const (
	AddPrivateIP                 = "bcecloud/apis/v1/AddPrivateIP"
	DeletePrivateIP              = "bcecloud/apis/v1/DeletePrivateIP"
	BindENIPublicIP              = "bcecloud/apis/v1/BindENIPulblicIP"
	UnBindENIPublicIP            = "bcecloud/apis/v1/UnbindENIPulblicIP"
	DirectEIP                    = "bcecloud/apis/v1/DirectEIP"
	UnDirectEIP                  = "bcecloud/apis/v1/UnDirectEIP"
	ListEIPs                     = "bcecloud/apis/v1/ListEIPs"
	BatchAddPrivateIpCrossSubnet = "bcecloud/apis/v1/BatchAddPrivateIpCrossSubnet"
	BatchAddPrivateIP            = "bcecloud/apis/v1/BatchAddPrivateIP"
	BatchDeletePrivateIP         = "bcecloud/apis/v1/BatchDeletePrivateIP"

	CreateENI = "bcecloud/apis/v1/CreateENI"
	DeleteENI = "bcecloud/apis/v1/DeleteENI"
	AttachENI = "bcecloud/apis/v1/AttachENI"
	DetachENI = "bcecloud/apis/v1/DetachENI"
	StatENI   = "bcecloud/apis/v1/StatENI"
	ListENIs  = "bcecloud/apis/v1/ListENIs"
	ListERIs  = "bcecloud/apis/v1/ListERIs"

	ListRouteTable  = "bcecloud/apis/v1/ListRouteTable"
	CreateRouteRule = "bcecloud/apis/v1/CreateRouteRule"
	DeleteRouteRule = "bcecloud/apis/v1/DeleteRouteRule"

	DescribeSubnet = "bcecloud/apis/v1/DescribeSubnet"
	ListSubnets    = "bcecloud/apis/v1/ListSubnets"

	ListSecurityGroup = "bcecloud/apis/v1/ListSecurityGroup"

	GetBCCInstanceDetail = "bcecloud/apis/v1/GetBCCInstanceDetail"
	GetBBCInstanceDetail = "bcecloud/apis/v1/GetBBCInstanceDetail"
	GetBBCInstanceENI    = "bcecloud/apis/v1/GetBBCInstanceENI"

	BBCBatchAddIP            = "bcecloud/apis/v1/BBCBatchAddIP"
	BBCBatchDelIP            = "bcecloud/apis/v1/BBCBatchDelIP"
	BBCBatchAddIPCrossSubnet = "bcecloud/apis/v1/BBCBatchAddIPCrossSubnet"

	GetHPCEniID                = "bcecloud/apis/v1/GetHPCEniID"
	BatchDeleteHpcEniPrivateIP = "bcecloud/apis/v1/BatchDeleteHpcEniPrivateIP"
	BatchAddHpcEniPrivateIP    = "bcecloud/apis/v1/BatchAddHpcEniPrivateIP"

	// BCC primary interface API
	BCCListENIs   = "bcecloud/bcc/apis/v2/eni/{instanceID}"
	BCCBatchAddIP = "bcecloud/bcc/apis/v2/instance/batchAddIp"
	BCCBatchDelIP = "bcecloud/bcc/apis/v2/instance/batchDelIp"
)

Variables

View Source
var (
	BCCEndpoints = map[string]string{
		"bj":  "bcc.bj.baidubce.com",
		"gz":  "bcc.gz.baidubce.com",
		"su":  "bcc.su.baidubce.com",
		"hkg": "bcc.hkg.baidubce.com",
		"fwh": "bcc.fwh.baidubce.com",
		"bd":  "bcc.bd.baidubce.com",

		"sin": "bcc.sin.baidubce.com",

		"fsh":     "bcc.fsh.baidubce.com",
		"yq":      "bcc.yq.baidubce.com",
		"nj":      "bcc.nj.baidubce.com",
		"cd":      "bcc.cd.baidubce.com",
		"sandbox": "bcc.bj.qasandbox.baidu-int.com",
	}

	BBCEndpoints = map[string]string{
		"bj":  "bbc.bj.baidubce.com",
		"gz":  "bbc.gz.baidubce.com",
		"su":  "bbc.su.baidubce.com",
		"hkg": "bbc.hkg.baidubce.com",
		"fwh": "bbc.fwh.baidubce.com",
		"bd":  "bbc.bd.baidubce.com",

		"sin": "bbc.sin.baidubce.com",

		"fsh":     "bbc.fsh.baidubce.com",
		"yq":      "bbc.yq.baidubce.com",
		"nj":      "bbc.nj.baidubce.com",
		"cd":      "bbc.cd.baidubce.com",
		"sandbox": "bbc.bj.qasandbox.baidu-int.com",
	}

	EIPEndpoints = map[string]string{
		"bj":      "eip.bj.baidubce.com",
		"gz":      "eip.gz.baidubce.com",
		"su":      "eip.su.baidubce.com",
		"hkg":     "eip.hkg.baidubce.com",
		"fwh":     "eip.fwh.baidubce.com",
		"bd":      "eip.bd.baidubce.com",
		"sin":     "eip.sin.baidubce.com",
		"fsh":     "eip.fsh.baidubce.com",
		"yq":      "eip.yq.baidubce.com",
		"nj":      "eip.nj.baidubce.com",
		"cd":      "eip.cd.baidubce.com",
		"sandbox": "eip.bj.qasandbox.baidu-int.com",
	}
)

Functions

func BceServiceErrorToHTTPCode

func BceServiceErrorToHTTPCode(err error) int

func IsErrorBBCENIPrivateIPExceedLimit

func IsErrorBBCENIPrivateIPExceedLimit(err error) bool

func IsErrorBBCENIPrivateIPNotFound

func IsErrorBBCENIPrivateIPNotFound(err error) bool

func IsErrorCreateRouteRuleExceededQuota

func IsErrorCreateRouteRuleExceededQuota(err error) bool

func IsErrorENINotFound

func IsErrorENINotFound(err error) bool

func IsErrorENIPrivateIPNotFound

func IsErrorENIPrivateIPNotFound(err error) bool

IsErrorENIPrivateIPNotFound 判定删除辅助 IP 的 err 是否是因为 IP 不属于弹性网卡

func IsErrorPrivateIPInUse

func IsErrorPrivateIPInUse(err error) bool

func IsErrorQuotaLimitExceeded

func IsErrorQuotaLimitExceeded(err error) bool

func IsErrorRateLimit

func IsErrorRateLimit(err error) bool

func IsErrorReasonNoSuchObject

func IsErrorReasonNoSuchObject(err error) bool

func IsErrorRouteRuleRepeated

func IsErrorRouteRuleRepeated(err error) bool

func IsErrorSubnetHasNoMoreIP

func IsErrorSubnetHasNoMoreIP(err error) bool

func IsErrorVmMemoryCanNotAttachMoreIpException

func IsErrorVmMemoryCanNotAttachMoreIpException(err error) bool

Types

type Auth

type Auth interface {
	GetSigner(ctx context.Context) auth.Signer
	GetCredentials(ctx context.Context) *auth.BceCredentials
	GetSignOptions(ctx context.Context) *auth.SignOptions
}

func NewAccessKeyPairAuth

func NewAccessKeyPairAuth(ak, sk, token string) (Auth, error)

func NewCCEGatewayAuth

func NewCCEGatewayAuth(region, clusterID string, kubeClient kubernetes.Interface) (Auth, error)

type AuthMode

type AuthMode string
const (
	AuthModeAccessKey  AuthMode = "key"
	AuthModeCCEGateway AuthMode = "gateway"
)

type Client

type Client struct {
	// contains filtered or unexported fields
}

func (*Client) AddPrivateIP

func (c *Client) AddPrivateIP(ctx context.Context, privateIP string, eniID string, isIpv6 bool) (string, error)

func (*Client) AttachENI

func (c *Client) AttachENI(ctx context.Context, args *eni.EniInstance) error

func (*Client) BBCBatchAddIP

func (c *Client) BBCBatchAddIP(ctx context.Context, args *bbc.BatchAddIpArgs) (*bbc.BatchAddIpResponse, error)

func (*Client) BBCBatchAddIPCrossSubnet

func (c *Client) BBCBatchAddIPCrossSubnet(ctx context.Context, args *bbc.BatchAddIpCrossSubnetArgs) (*bbc.BatchAddIpResponse, error)

func (*Client) BBCBatchDelIP

func (c *Client) BBCBatchDelIP(ctx context.Context, args *bbc.BatchDelIpArgs) error

func (*Client) BCCBatchAddIP

func (c *Client) BCCBatchAddIP(ctx context.Context, args *bccapi.BatchAddIpArgs) (*bccapi.BatchAddIpResponse, error)

BCCBatchAddIP implements Interface.

func (*Client) BCCBatchDelIP

func (c *Client) BCCBatchDelIP(ctx context.Context, args *bccapi.BatchDelIpArgs) error

BCCBatchDelIP implements Interface.

func (*Client) BatchAddHpcEniPrivateIP

func (c *Client) BatchAddHpcEniPrivateIP(ctx context.Context, args *hpc.EniBatchPrivateIPArgs) (*hpc.BatchAddPrivateIPResult, error)

func (*Client) BatchAddPrivateIP

func (c *Client) BatchAddPrivateIP(ctx context.Context, privateIPs []string, count int, eniID string, isIpv6 bool) ([]string, error)

func (*Client) BatchAddPrivateIpCrossSubnet

func (c *Client) BatchAddPrivateIpCrossSubnet(ctx context.Context, eniID, subnetID string, privateIPs []string, count int, isIpv6 bool) ([]string, error)

func (*Client) BatchDeleteHpcEniPrivateIP

func (c *Client) BatchDeleteHpcEniPrivateIP(ctx context.Context, args *hpc.EniBatchDeleteIPArgs) error

func (*Client) BatchDeletePrivateIP

func (c *Client) BatchDeletePrivateIP(ctx context.Context, privateIPs []string, eniID string, isIpv6 bool) error

func (*Client) BindENIPublicIP

func (c *Client) BindENIPublicIP(ctx context.Context, privateIP string, publicIP string, eniID string) error

func (*Client) CreateENI

func (c *Client) CreateENI(ctx context.Context, args *eni.CreateEniArgs) (string, error)

func (*Client) CreateRouteRule

func (c *Client) CreateRouteRule(ctx context.Context, args *vpc.CreateRouteRuleArgs) (string, error)

func (*Client) DeleteENI

func (c *Client) DeleteENI(ctx context.Context, eniID string) error

func (*Client) DeletePrivateIP

func (c *Client) DeletePrivateIP(ctx context.Context, privateIP string, eniID string, isIpv6 bool) error

func (*Client) DeleteRouteRule

func (c *Client) DeleteRouteRule(ctx context.Context, routeID string) error

func (*Client) DescribeSubnet

func (c *Client) DescribeSubnet(ctx context.Context, subnetID string) (*vpc.Subnet, error)

func (*Client) DetachENI

func (c *Client) DetachENI(ctx context.Context, args *eni.EniInstance) error

func (*Client) DirectEIP

func (c *Client) DirectEIP(ctx context.Context, eip string) error

func (*Client) GetBBCInstanceDetail

func (c *Client) GetBBCInstanceDetail(ctx context.Context, instanceID string) (*bbc.InstanceModel, error)

func (*Client) GetBBCInstanceENI

func (c *Client) GetBBCInstanceENI(ctx context.Context, instanceID string) (*bbc.GetInstanceEniResult, error)

func (*Client) GetBCCInstanceDetail

func (c *Client) GetBCCInstanceDetail(ctx context.Context, instanceID string) (*bccapi.InstanceModel, error)

func (*Client) GetENIQuota

func (c *Client) GetENIQuota(ctx context.Context, instanceID string) (*eni.EniQuoteInfo, error)

GetENIQuota implements Interface.

func (*Client) GetHPCEniID

func (c *Client) GetHPCEniID(ctx context.Context, instanceID string) (*hpc.EniList, error)

func (*Client) ListBCCInstanceEni

func (c *Client) ListBCCInstanceEni(ctx context.Context, instanceID string) ([]bccapi.Eni, error)

ListBCCInstanceEni implements Interface.

func (*Client) ListEIPs

func (c *Client) ListEIPs(_ context.Context, args eip.ListEipArgs) ([]eip.EipModel, error)

func (*Client) ListENIs

func (c *Client) ListENIs(_ context.Context, args eni.ListEniArgs) ([]eni.Eni, error)

func (*Client) ListERIs

func (c *Client) ListERIs(_ context.Context, args eni.ListEniArgs) ([]eni.Eni, error)

func (*Client) ListRouteTable

func (c *Client) ListRouteTable(ctx context.Context, vpcID, routeTableID string) ([]vpc.RouteRule, error)

func (*Client) ListSecurityGroup

func (c *Client) ListSecurityGroup(ctx context.Context, vpcID, instanceID string) ([]bccapi.SecurityGroupModel, error)

func (*Client) ListSubnets

func (c *Client) ListSubnets(ctx context.Context, args *vpc.ListSubnetArgs) ([]vpc.Subnet, error)

func (*Client) StatENI

func (c *Client) StatENI(ctx context.Context, eniID string) (*eni.Eni, error)

func (*Client) UnBindENIPublicIP

func (c *Client) UnBindENIPublicIP(ctx context.Context, publicIP string, eniID string) error

func (*Client) UnDirectEIP

func (c *Client) UnDirectEIP(ctx context.Context, eip string) error

type ErrorReason

type ErrorReason string
const (
	ErrorReasonUnknown                             ErrorReason = "Unknown"
	ErrorReasonENIPrivateIPNotFound                ErrorReason = "ENIPrivateIPNotFound"
	ErrorReasonENINotFound                         ErrorReason = "ENINotFound"
	ErrorReasonSubnetHasNoMoreIP                   ErrorReason = "SubnetHasNoMoreIP"
	ErrorReasonRateLimit                           ErrorReason = "RateLimit"
	ErrorReasonPrivateIPInUse                      ErrorReason = "PrivateIPInUse"
	ErrorReasonVmMemoryCanNotAttachMoreIpException ErrorReason = "VmMemoryCanNotAttachMoreIpException"
	ErrorReasonBBCENIPrivateIPNotFound             ErrorReason = "BBCENIPrivateIPNotFound"
	ErrorReasonBBCENIPrivateIPExceedLimit          ErrorReason = "BBCENIPrivateIPExceedLimit"
	ErrorReasonRouteRuleRepeated                   ErrorReason = "RouteRuleRepeated"
	ErrorReasonQuotaLimitExceeded                  ErrorReason = "QuotaLimitExceeded"
	ErrorReasonNoSuchObject                        ErrorReason = "NoSuchObject"
	ErrorReasonNoSRouteRuleExceedQuota             ErrorReason = "RouteRuleExceedQuota"
)

func ReasonForError

func ReasonForError(err error) ErrorReason

type Interface

type Interface interface {
	ListENIs(ctx context.Context, args eni.ListEniArgs) ([]eni.Eni, error)
	ListERIs(ctx context.Context, args eni.ListEniArgs) ([]eni.Eni, error)
	AddPrivateIP(ctx context.Context, privateIP string, eniID string, isIpv6 bool) (string, error)
	DeletePrivateIP(ctx context.Context, privateIP string, eniID string, isIpv6 bool) error

	BindENIPublicIP(ctx context.Context, privateIP string, publicIP string, eniID string) error
	UnBindENIPublicIP(ctx context.Context, publicIP string, eniID string) error
	DirectEIP(ctx context.Context, eip string) error
	UnDirectEIP(ctx context.Context, eip string) error
	ListEIPs(ctx context.Context, args eip.ListEipArgs) ([]eip.EipModel, error)

	// BatchAddPrivateIpCrossSubnet
	// Assign IP addresses to Eni across subnets.
	// Note that this feature needs to initiate a work order in advance to
	// enable the cross subnet IP allocation function
	BatchAddPrivateIpCrossSubnet(ctx context.Context, eniID, subnetID string, privateIPs []string, count int, isIpv6 bool) ([]string, error)
	BatchAddPrivateIP(ctx context.Context, privateIPs []string, count int, eniID string, isIpv6 bool) ([]string, error)
	BatchDeletePrivateIP(ctx context.Context, privateIPs []string, eniID string, isIpv6 bool) error
	CreateENI(ctx context.Context, args *eni.CreateEniArgs) (string, error)
	DeleteENI(ctx context.Context, eniID string) error
	AttachENI(ctx context.Context, args *eni.EniInstance) error
	DetachENI(ctx context.Context, args *eni.EniInstance) error
	StatENI(ctx context.Context, eniID string) (*eni.Eni, error)
	GetENIQuota(ctx context.Context, instanceID string) (*eni.EniQuoteInfo, error)

	// ListBCCInstanceEni Query the list of BCC eni network interface.
	// Unlike the VPC interface, this interface can query the primaty network interface of BCC/EBC
	// However, the `ListENIs“ and `StatENI“ interfaces of VPC cannot retrieve relevant information
	// about the primary network interface of BCC/EBC.
	ListBCCInstanceEni(ctx context.Context, instanceID string) ([]bccapi.Eni, error)

	// BCCBatchAddIP batch add secondary IP to primary interface of BCC/EBC
	BCCBatchAddIP(ctx context.Context, args *bccapi.BatchAddIpArgs) (*bccapi.BatchAddIpResponse, error)

	// BCCBatchDelIP batch delete secondary IP to primary interface of BCC/EBC
	// Waring: Do not mistakenly delete the primary IP address of the main network card
	BCCBatchDelIP(ctx context.Context, args *bccapi.BatchDelIpArgs) error

	ListRouteTable(ctx context.Context, vpcID, routeTableID string) ([]vpc.RouteRule, error)
	CreateRouteRule(ctx context.Context, args *vpc.CreateRouteRuleArgs) (string, error)
	DeleteRouteRule(ctx context.Context, routeID string) error

	DescribeSubnet(ctx context.Context, subnetID string) (*vpc.Subnet, error)
	ListSubnets(ctx context.Context, args *vpc.ListSubnetArgs) ([]vpc.Subnet, error)

	ListSecurityGroup(ctx context.Context, vpcID, instanceID string) ([]bccapi.SecurityGroupModel, error)

	GetBCCInstanceDetail(ctx context.Context, instanceID string) (*bccapi.InstanceModel, error)

	GetBBCInstanceDetail(ctx context.Context, instanceID string) (*bbc.InstanceModel, error)
	GetBBCInstanceENI(ctx context.Context, instanceID string) (*bbc.GetInstanceEniResult, error)
	BBCBatchAddIP(ctx context.Context, args *bbc.BatchAddIpArgs) (*bbc.BatchAddIpResponse, error)
	BBCBatchDelIP(ctx context.Context, args *bbc.BatchDelIpArgs) error
	BBCBatchAddIPCrossSubnet(ctx context.Context, args *bbc.BatchAddIpCrossSubnetArgs) (*bbc.BatchAddIpResponse, error)

	GetHPCEniID(ctx context.Context, instanceID string) (*hpc.EniList, error)
	BatchDeleteHpcEniPrivateIP(ctx context.Context, args *hpc.EniBatchDeleteIPArgs) error
	BatchAddHpcEniPrivateIP(ctx context.Context, args *hpc.EniBatchPrivateIPArgs) (*hpc.BatchAddPrivateIPResult, error)
}

func New

func New(
	region string,
	clusterID string,
	accessKeyID string,
	secretAccessKey string,
	kubeClient kubernetes.Interface,
	debug bool,
) (Interface, error)

func NewFlowControlClient

func NewFlowControlClient(client Interface, qps float64, burst int, timeout time.Duration) (Interface, error)

NewFlowControlClient returns a client with flow control.

Directories

Path Synopsis
Package testing is a generated GoMock package.
Package testing is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL