@@ -7,6 +7,18 @@ import (
|
||||
"oci-portal/internal/oci"
|
||||
)
|
||||
|
||||
// ChangeVnicPublicIP 更换指定 VNIC 的临时公网 IP,返回新地址(旧保留 IP 自动解绑)。
|
||||
func (s *OciConfigService) ChangeVnicPublicIP(ctx context.Context, id uint, region, vnicID string) (string, error) {
|
||||
if vnicID == "" {
|
||||
return "", fmt.Errorf("change vnic public ip: vnicId is required")
|
||||
}
|
||||
cred, err := s.credentialsByID(ctx, id)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return s.client.ChangeVnicPublicIP(ctx, cred, region, vnicID)
|
||||
}
|
||||
|
||||
// ChangeInstancePublicIP 更换实例主 VNIC 的临时公网 IP,返回新地址。
|
||||
func (s *OciConfigService) ChangeInstancePublicIP(ctx context.Context, id uint, region, instanceID string) (string, error) {
|
||||
cred, err := s.credentialsByID(ctx, id)
|
||||
@@ -46,7 +58,7 @@ func (s *OciConfigService) InstanceVnics(ctx context.Context, id uint, region, i
|
||||
return s.client.ListInstanceVnics(ctx, cred, region, instanceID)
|
||||
}
|
||||
|
||||
// AttachVnic 为实例附加次要 VNIC。
|
||||
// AttachVnic 为实例附加次要 VNIC;选了保留 IP 时由后台等网卡就绪后绑定。
|
||||
func (s *OciConfigService) AttachVnic(ctx context.Context, id uint, region, instanceID string, in oci.AttachVnicInput) (oci.Vnic, error) {
|
||||
if instanceID == "" || in.SubnetID == "" {
|
||||
return oci.Vnic{}, fmt.Errorf("attach vnic: instanceId and subnetId are required")
|
||||
@@ -55,7 +67,16 @@ func (s *OciConfigService) AttachVnic(ctx context.Context, id uint, region, inst
|
||||
if err != nil {
|
||||
return oci.Vnic{}, err
|
||||
}
|
||||
return s.client.AttachVnic(ctx, cred, region, instanceID, in)
|
||||
vnic, err := s.client.AttachVnic(ctx, cred, region, instanceID, in)
|
||||
if err != nil {
|
||||
return vnic, err
|
||||
}
|
||||
if in.ReservedPublicIPID != "" {
|
||||
s.goBind(func() {
|
||||
s.bindReservedIPToVnicWhenReady(cred, region, instanceID, vnic.AttachmentID, in.ReservedPublicIPID)
|
||||
})
|
||||
}
|
||||
return vnic, nil
|
||||
}
|
||||
|
||||
// DetachVnic 分离 VNIC 附加关系(主 VNIC 由 OCI 拒绝)。
|
||||
|
||||
Reference in New Issue
Block a user