diff --git a/go.mod b/go.mod index 51d9496..a28aaf4 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/sirupsen/logrus v1.6.0 github.com/spf13/cobra v1.7.0 github.com/ucloud/go-lockfile v0.1.0 - github.com/ucloud/ucloud-sdk-go v0.21.46 + github.com/ucloud/ucloud-sdk-go v0.22.30 github.com/vishvananda/netlink v1.2.1-beta.2 github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f google.golang.org/grpc v1.56.3 diff --git a/go.sum b/go.sum index bcf7a1e..a787d06 100644 --- a/go.sum +++ b/go.sum @@ -162,6 +162,8 @@ github.com/ucloud/go-lockfile v0.1.0 h1:Mzb1/OZc8Gween/p1cA4t6qBTiE9JnZntZpRTdII github.com/ucloud/go-lockfile v0.1.0/go.mod h1:OCM7zfa82qicE2nW5pVtSDEMmPvjYvProNQ/f2YHEkw= github.com/ucloud/ucloud-sdk-go v0.21.46 h1:LwrTxERZjQJPjVILoIfjy8PTgYkckah5ms2eq4ECgT0= github.com/ucloud/ucloud-sdk-go v0.21.46/go.mod h1:dyLmFHmUfgb4RZKYQP9IArlvQ2pxzFthfhwxRzOEPIw= +github.com/ucloud/ucloud-sdk-go v0.22.30 h1:CZQWo+LLLYMVgf/Mq9JoFVNyIM7jLFpwvnctsUwXV3k= +github.com/ucloud/ucloud-sdk-go v0.22.30/go.mod h1:dyLmFHmUfgb4RZKYQP9IArlvQ2pxzFthfhwxRzOEPIw= github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= github.com/vishvananda/netlink v1.2.1-beta.2 h1:Llsql0lnQEbHj0I1OuKyp8otXp0r3q0mPkuhwHfStVs= github.com/vishvananda/netlink v1.2.1-beta.2/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= diff --git a/pkg/uapi/client.go b/pkg/uapi/client.go index 70f8a7d..d504b70 100644 --- a/pkg/uapi/client.go +++ b/pkg/uapi/client.go @@ -151,11 +151,16 @@ func NewClient() (*ApiClient, error) { zoneId: meta.AvailabilityZone, cfg: &cfg, } - // Get vpcId and subnetId - if len(meta.UHost.NetworkInterfaces) > 0 { - uApi.vpcId = meta.UHost.NetworkInterfaces[0].VpcId - uApi.subnetId = meta.UHost.NetworkInterfaces[0].SubnetId - } else { + + for _, iface := range meta.UHost.NetworkInterfaces { + if iface.Default { + uApi.vpcId = iface.VpcId + uApi.subnetId = iface.SubnetId + break + } + } + + if uApi.vpcId == "" || uApi.subnetId == "" { uApi.vpcId = os.Getenv("UCLOUD_VPC_ID") uApi.subnetId = os.Getenv("UCLOUD_SUBNET_ID") }