EIP实例
申请EIP
- 申请一个EIP,可用于绑定到任意BCC、BLB等实例
- 创建EIP需要实名认证,若未通过实名认证可以前往百度开放云官网控制台中的安全认证下的实名认证中进行认证。
函数声明
1type CreateEipArgs struct {
2 Name string `json:"name,omitempty"`
3 BandWidthInMbps int `json:"bandwidthInMbps"`
4 Billing *Billing `json:"billing"`
5 Tags []model.TagModel `json:"tags"`
6 AutoRenewTimeUnit string `json:"autoRenewTimeUnit,omitempty"`
7 AutoRenewTime int `json:"autoRenewTime,omitempty"`
8 RouteType string `json:"routeType,omitempty"`
9 Idc string `json:"idc,omitempty"`
10 ClientToken string `json:"-"`
11}
12
13type CreateEipResult struct {
14 Eip string `json:"eip"`
15}
16
17func (c *Client) CreateEip(args *CreateEipArgs) (*CreateEipResult, error)
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/Wjwvz30fv
返回值
操作成功:
1{
2 "eip":"180.181.3.133"
3}
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_create_eip.go
EIP带宽扩缩容
- 用于指定EIP的带宽扩缩容
- 通过查询EIP列表查看EIP扩缩容状态是否完成
函数声明
1type ResizeEipArgs struct {
2 NewBandWidthInMbps int `json:"newBandwidthInMbps"`
3 ClientToken string `json:"-"`
4}
5
6func (c *Client) ResizeEip(eip string, args *ResizeEipArgs) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/Hjwvz325u
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_resize_eip.go
绑定EIP
- 绑定EIP到某个实例
- 只有available状态的EIP支持绑定操作
- 被绑定的实例不能存在任何已有EIP绑定关系
- 被绑定的实例不能处于欠费状态
函数声明
1type BindEipArgs struct {
2 InstanceType string `json:"instanceType"`
3 InstanceId string `json:"instanceId"`
4 ClientToken string `json:"-"`
5}
6
7func (c *Client) BindEip(eip string, args *BindEipArgs) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/9jwvz31gn
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_bind_eip.go
解绑EIP
- 解除指定EIP的绑定关系
- 被解绑的EIP必须已经绑定到任意实例
函数声明
1func (c *Client) UnBindEip(eip, clientToken string) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/Djwvz314s
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_unbind_eip.go
释放EIP
- 释放指定EIP,被释放的EIP无法找回
- 如果EIP被绑定到任意实例,需要先解绑才能释放
函数声明
1func (c *Client) DeleteEip(eip, clientToken string) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/Rjwvz32ig
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_delete_eip.go
查询EIP列表
- 可根据多重条件查询EIP列表。
- 如只需查询单个EIP的详情,只需提供eip参数即可。
- 如只需查询绑定到指定类型实例上的EIP,提供instanceType参数即可。
- 如只需查询指定实例上绑定的EIP的详情,提供instanceType及instanceId参数即可。
- 若不提供查询条件,则默认查询覆盖所有EIP。
- 返回结果为多重条件交集的查询结果,即提供多重条件的情况下,返回同时满足所有条件的EIP。
- 以上查询结果支持marker分页,分页大小默认为1000,可通过maxKeys参数指定。
函数声明
1type ListEipArgs struct {
2 Eip string
3 InstanceType string
4 InstanceId string
5 Marker string
6 MaxKeys int
7 Status string
8}
9
10type ListEipResult struct {
11 Marker string `json:"marker"`
12 MaxKeys int `json:"maxKeys"`
13 NextMarker string `json:"nextMarker"`
14 IsTruncated bool `json:"isTruncated"`
15 EipList []EipModel `json:"eipList"`
16}
17
18type EipModel struct {
19 Name string `json:"name"`
20 Eip string `json:"eip"`
21 EipId string `json:"eipId"`
22 Status string `json:"status"`
23 EipInstanceType string `json:"eipInstanceType"`
24 InstanceType string `json:"instanceType"`
25 InstanceId string `json:"instanceId"`
26 ShareGroupId string `json:"shareGroupId"`
27 ClusterId string `json:"clusterId"`
28 BandWidthInMbps int `json:"bandwidthInMbps"`
29 PaymentTiming string `json:"paymentTiming"`
30 BillingMethod string `json:"billingMethod"`
31 CreateTime string `json:"createTime"`
32 ExpireTime string `json:"expireTime"`
33 Tags []model.TagModel `json:"tags"`
34}
35
36func (c *Client) ListEip(args *ListEipArgs) (*ListEipResult, error)
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/Pjwvz30qy
返回值
操作成功:
1{
2 "marker": "ip-xxxxxxxx",
3 "maxKeys": 1000,
4 "nextMarker": "",
5 "isTruncated": false,
6 "eipList": [
7 {
8 "name": "xxxx",
9 "eip": "x.x.x.x",
10 "eipId": "ip-xxxxxxxx",
11 "status": "available",
12 "eipInstanceType": "shared",
13 "instanceType": "",
14 "instanceId": "",
15 "shareGroupId": "eg-xxxxxxxx",
16 "clusterId": "",
17 "bandwidthInMbps": 100,
18 "paymentTiming": "share",
19 "billingMethod": "share",
20 "createTime": "2023-11-23T07:25:34Z",
21 "expireTime": "",
22 "tags": null
23 },
24 {
25 "name": "yyyy",
26 "eip": "y.y.y.y",
27 "eipId": "ip-yyyyyyyy",
28 "status": "available",
29 "eipInstanceType": "shared",
30 "instanceType": "",
31 "instanceId": "",
32 "shareGroupId": "eg-yyyyyyyy",
33 "clusterId": "",
34 "bandwidthInMbps": 100,
35 "paymentTiming": "share",
36 "billingMethod": "share",
37 "createTime": "2023-11-23T07:25:34Z",
38 "expireTime": "",
39 "tags": null
40 }
41 ]
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_list_eips.go
EIP续费
- 针对指定EIP的续费操作,延长过期时长
- EIP扩缩容期间不能进行续费操作。
函数声明
1type PurchaseReservedEipArgs struct {
2 Billing *Billing `json:"billing"`
3 ClientToken string `json:"clientToken"`
4}
5
6func (c *Client) PurchaseReservedEip(eip string,
7 args *PurchaseReservedEipArgs) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/Yjwvz31ty
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_purchase_reserved_eip.go
EIP开启自动续费
- EIP 计费方式为预付费类型
- EIP 无计费变更任务
- EIP 未开通自动续费
函数声明
1type StartAutoRenewArgs struct {
2 AutoRenewTimeUnit string `json:"autoRenewTimeUnit,omitempty"`
3 AutoRenewTime int `json:"autoRenewTime,omitempty"`
4 ClientToken string `json:"-"`
5}
6
7func (c *Client) StartAutoRenew(eip string, args *StartAutoRenewArgs) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/Sk9gykbek
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_start_auto_renew.go
EIP关闭自动续费
- 需要EIP已经开通自动续费
函数声明
1func (c *Client) StopAutoRenew(eip string, clientToken string) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/Sk9gykbek
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_stop_auto_renew.go
开启EIP直通
- 开启EIP直通
- EIP必须绑定到某个BCC、DCC、ENI、BLB等实例
函数声明
1func (c *Client) DirectEip(eip, clientToken string) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/aknohnbq1
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_direct_eip.go
关闭EIP直通
- 关闭EIP直通
- EIP必须已经开启直通功能
函数声明
1func (c *Client) UnDirectEip(eip, clientToken string) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/Pknohwcdb
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_undirect_eip.go
查询回收站内EIP列表
- 查询用户账号下回收站内EIP信息
- 支持按EIP的eip、name进行查询,eip、name 均支持模糊搜索
- 若不提供查询条件,则默认查询覆盖所有EIP
- 返回结果是多重条件交集的查询结果,即提供多重条件的情况下,返回同时满足所有条件的EIP
- 结果支持marker分页,分页大小默认为1000,可通过maxKeys参数指定
函数声明
1type ListRecycleEipArgs struct {
2 Eip string
3 Name string
4 Marker string
5 MaxKeys int
6}
7
8type ListRecycleEipResult struct {
9 Marker string `json:"marker"`
10 MaxKeys int `json:"maxKeys"`
11 NextMarker string `json:"nextMarker"`
12 IsTruncated bool `json:"isTruncated"`
13 EipList []RecycleEipModel `json:"eipList"`
14}
15
16type RecycleEipModel struct {
17 Name string `json:"name"`
18 Eip string `json:"eip"`
19 EipId string `json:"eipId"`
20 Status string `json:"status"`
21 RouteType string `json:"routeType"`
22 BandWidthInMbps int `json:"bandwidthInMbps"`
23 PaymentTiming string `json:"paymentTiming"`
24 BillingMethod string `json:"billingMethod"`
25 RecycleTime string `json:"recycleTime"`
26 ScheduledDeleteTime string `json:"scheduledDeleteTime"`
27}
28
29func (c *Client) ListRecycleEip(args *ListRecycleEipArgs) (
30 *ListRecycleEipResult, error)
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/dl0anm1j8
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_list_recycle_eip.go
选择性释放EIP
- 选择将指定EIP直接释放或放入回收站内,默认直接释放
- 预付费已到期、后付费-按流量、后付费-按带宽状态的 EIP 实例可以选择放入回收站或直接释放
- 释放指定EIP,被释放的EIP无法找回
- 回收站内EIP实例保留7天,超过7天则自动释放不可恢复;7天内可以手动选择恢复或删除指定EIP
- EIP实例如果被绑定到任意实例,需要先解绑才能直接释放
- EIP实例进入回收站后,强制解除绑定关系,恢复实例后需重新配置
- 在回收站的EIP有配额限制,默认在每个地域回收站保留10个EIP,按时间倒序。当回收站内EIP数额达到10个时,新进入的EIP会挤走之前的EIP
- 若EIP实例为后付费已欠费,无论何种选择系统都将直接释放EIP实例
函数声明
1func (c *Client) OptionalDeleteEip(eip string, clientToken string,
2 releaseToRecycle bool) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/zl0anqxgo
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_optional_delete_eip.go
释放回收站内EIP
- 释放回收站内指定的EIP
函数声明
1func (c *Client) DeleteRecycleEip(eip string, clientToken string) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/sl0anla1w
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_delete_recycle_eip.go
恢复回收站内EIP
- 恢复回收站内指定EIP计费
- 若EIP付款方式为预付费,则通过续费操作恢复计费,续费时长为1个月
- 若EIP付款方式为后付费,则恢复原有计费方式
函数声明
1func (c *Client) RestoreRecycleEip(eip string, clientToken string) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/Gl0anfp4g
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_restore_recycle_eip.go
预付费EIP退订
- 预付费EIP释放并退款。
- 只有预付费EIP支持退订,后付费EIP不支持退订,后付费EIP可调用释放EIP接口直接释放。
- 正在封禁中的EIP不支持退订,可在解封后再操作。
- 绑定了VPN、NAT的EIP不支持退订,可在解除绑定后再操作。
- 绑有带宽包的EIP不支持退订,可将带宽包释放后再操作。
- 共享带宽中的EIP不支持退订,可直接退订共享带宽或者将EIP移出共享带宽后释放。
- EIP退款有惩罚机制,退款金额 = max(0, 总金额 - 已消费金额 * 1.5)。
函数声明
1func (c *Client) RefundEip(eip, clientToken string) error
参数含义
请参考OpenAPI文档:https://cloud.baidu.com/doc/EIP/s/1lxk6gbpk
返回值
操作成功:
无特殊返回参数
操作失败:
抛出异常,异常列表参考:https://cloud.baidu.com/doc/EIP/s/nkcu555a4
代码示例
具体代码示例参考:example_eip_refund_eip.go