mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #15461 from ioito/automated-cherry-pick-of-#15460-upstream-release-3.10
Automated cherry pick of #15460: fix(region): vender update
This commit is contained in:
@@ -84,7 +84,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221128022002-9a9d6ff89e79
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221129103405-4636d4b6d0e6
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
|
||||
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
|
||||
yunion.io/x/log v1.0.0
|
||||
|
||||
@@ -1176,8 +1176,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221128022002-9a9d6ff89e79 h1:PaZdEBQxu/Ag5twEecpTvQGZ6YR+OBHhf6/tZluTVoY=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221128022002-9a9d6ff89e79/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221129103405-4636d4b6d0e6 h1:sQw0C75yeObEbUJtrbu1PwWP1FSir5TLJZgQm7kXrtQ=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221129103405-4636d4b6d0e6/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -80,6 +80,9 @@ type VpcListInput struct {
|
||||
// example: 192.168.222.0/24
|
||||
CidrBlock []string `json:"cidr_block"`
|
||||
|
||||
// enmu: eip, none
|
||||
ExternalAccessMode string `json:"external_access_mode"`
|
||||
|
||||
OrderByNetworkCount string `json:"order_by_network_count"`
|
||||
}
|
||||
|
||||
|
||||
@@ -1039,6 +1039,10 @@ func (manager *SVpcManager) ListItemFilter(
|
||||
return nil, errors.Wrap(err, "SGlobalVpcResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(query.ExternalAccessMode) > 0 {
|
||||
q = q.Equals("external_access_mode", query.ExternalAccessMode)
|
||||
}
|
||||
|
||||
if len(query.DnsZoneId) > 0 {
|
||||
dnsZone, err := DnsZoneManager.FetchByIdOrName(userCred, query.DnsZoneId)
|
||||
if err != nil {
|
||||
|
||||
Vendored
+1
-1
@@ -1439,7 +1439,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221128022002-9a9d6ff89e79
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221129103405-4636d4b6d0e6
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+1
@@ -16,6 +16,7 @@ package compute
|
||||
|
||||
const (
|
||||
NETWORK_TYPE_GUEST = "guest"
|
||||
NETWORK_TYPE_EIP = "elasticip"
|
||||
|
||||
NETWORK_STATUS_PENDING = "pending"
|
||||
NETWORK_STATUS_AVAILABLE = "available"
|
||||
|
||||
+14
@@ -100,6 +100,7 @@ type SInstance struct {
|
||||
Description string
|
||||
InternetMaxBandwidthOut int
|
||||
Throughput int
|
||||
OsArch *string
|
||||
|
||||
TagSpec TagSpec
|
||||
|
||||
@@ -341,6 +342,18 @@ func (self *SInstance) GetBios() cloudprovider.TBiosType {
|
||||
}
|
||||
|
||||
func (self *SInstance) GetOsArch() string {
|
||||
if self.OsArch != nil && len(*self.OsArch) > 0 {
|
||||
switch *self.OsArch {
|
||||
case ec2.ArchitectureValuesArm64:
|
||||
return apis.OS_ARCH_AARCH64
|
||||
case ec2.ArchitectureValuesI386:
|
||||
return apis.OS_ARCH_X86
|
||||
case ec2.ArchitectureValuesX8664:
|
||||
return apis.OS_ARCH_X86_64
|
||||
default:
|
||||
return apis.OS_ARCH_X86_64
|
||||
}
|
||||
}
|
||||
img, err := self.GetImage()
|
||||
if err != nil {
|
||||
log.Errorf("GetImage fail %s", err)
|
||||
@@ -746,6 +759,7 @@ func (self *SRegion) GetInstances(zoneId string, ids []string, offset int, limit
|
||||
ProductCodes: productCodes,
|
||||
OSName: osType, // todo: 这里在model层回写OSName信息
|
||||
OSType: osType,
|
||||
OsArch: instance.Architecture,
|
||||
|
||||
TagSpec: tagspec,
|
||||
// ExpiredTime:
|
||||
|
||||
+29
-7
@@ -283,7 +283,15 @@ func (self *SRegion) GetInstancePortId(instanceId string) (string, error) {
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-vpc/zh-cn_topic_0020090596.html
|
||||
func (self *SRegion) AllocateEIP(name string, bwMbps int, chargeType TInternetChargeType, bgpType string, projectId string) (*SEip, error) {
|
||||
func (self *SRegion) AllocateEIP(name string, bwMbps int, chargeType TInternetChargeType, bgpType, subnetId string, projectId string) (*SEip, error) {
|
||||
publicip := map[string]interface{}{
|
||||
"type": bgpType,
|
||||
"ip_version": 4,
|
||||
"alias": name,
|
||||
}
|
||||
if len(subnetId) > 0 {
|
||||
publicip["subnet_id"] = subnetId
|
||||
}
|
||||
params := map[string]interface{}{
|
||||
"bandwidth": map[string]interface{}{
|
||||
"name": name,
|
||||
@@ -291,11 +299,7 @@ func (self *SRegion) AllocateEIP(name string, bwMbps int, chargeType TInternetCh
|
||||
"share_type": "PER",
|
||||
"charge_mode": chargeType,
|
||||
},
|
||||
"publicip": map[string]interface{}{
|
||||
"type": bgpType,
|
||||
"ip_version": 4,
|
||||
"alias": name,
|
||||
},
|
||||
"publicip": publicip,
|
||||
}
|
||||
if len(projectId) > 0 {
|
||||
params["enterprise_project_id"] = projectId
|
||||
@@ -407,6 +411,24 @@ func (self *SRegion) CreateEIP(eip *cloudprovider.SEip) (cloudprovider.ICloudEIP
|
||||
ctype = InternetChargeByBandwidth
|
||||
}
|
||||
|
||||
if len(eip.NetworkExternalId) > 0 {
|
||||
net, err := self.GetExternalNetwork(eip.NetworkExternalId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetExternalNetwork(%s)", eip.NetworkExternalId)
|
||||
}
|
||||
exts, err := self.GetExternalVpcs()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetExternalVpcs")
|
||||
}
|
||||
for i := range exts {
|
||||
if exts[i].Id == net.NetworkId {
|
||||
eip.BGPType = exts[i].Name
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// todo: 如何避免hardcode。集成到cloudmeta服务中?
|
||||
if len(eip.BGPType) == 0 {
|
||||
types, err := self.GetEipTypes()
|
||||
@@ -423,7 +445,7 @@ func (self *SRegion) CreateEIP(eip *cloudprovider.SEip) (cloudprovider.ICloudEIP
|
||||
eip.Name = eip.Name[:64]
|
||||
}
|
||||
|
||||
ieip, err := self.AllocateEIP(eip.Name, eip.BandwidthMbps, ctype, eip.BGPType, eip.ProjectId)
|
||||
ieip, err := self.AllocateEIP(eip.Name, eip.BandwidthMbps, ctype, eip.BGPType, eip.NetworkExternalId, eip.ProjectId)
|
||||
ieip.region = self
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// 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.
|
||||
|
||||
package hcs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
"yunion.io/x/onecloud/pkg/util/rbacutils"
|
||||
)
|
||||
|
||||
type SBucketAllocationPools struct {
|
||||
End string `json:"end"`
|
||||
Start string `json:"start"`
|
||||
}
|
||||
|
||||
type SExternalNetwork struct {
|
||||
multicloud.SResourceBase
|
||||
HcsTags
|
||||
wire *SExternalWire
|
||||
|
||||
BucketAllocationPools []SBucketAllocationPools `json:"allocation_pools"`
|
||||
Cidr string `json:"cidr"`
|
||||
Description string `json:"description"`
|
||||
DnsNameservers []string `json:"dns_nameservers"`
|
||||
EnableDhcp bool `json:"enable_dhcp"`
|
||||
EnableInternet bool `json:"enable_internet"`
|
||||
EnableMulticast string `json:"enable_multicast"`
|
||||
External string `json:"external"`
|
||||
GatewayIp string `json:"gateway_ip"`
|
||||
HostRoutes []string `json:"host_routes"`
|
||||
Id string `json:"id"`
|
||||
IpVersion int `json:"ip_version"`
|
||||
Ipv6AddressMode string `json:"ipv6_address_mode"`
|
||||
Ipv6RaMode string `json:"ipv6_ra_mode"`
|
||||
McastStatus string `json:"mcast_status"`
|
||||
Name string `json:"name"`
|
||||
NetworkId string `json:"network_id"`
|
||||
Routed string `json:"routed"`
|
||||
SegmentId string `json:"segment_id"`
|
||||
Tags []string `json:"tags"`
|
||||
TenantId string `json:"tenant_id"`
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetId() string {
|
||||
return self.Id
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetName() string {
|
||||
if len(self.Name) == 0 {
|
||||
return self.Id
|
||||
}
|
||||
return self.Name
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetGlobalId() string {
|
||||
return self.Id
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetStatus() string {
|
||||
return api.NETWORK_STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) Refresh() error {
|
||||
ret, err := self.wire.region.GetExternalNetwork(self.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jsonutils.Update(self, ret)
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetIWire() cloudprovider.ICloudWire {
|
||||
return self.wire
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetIpStart() string {
|
||||
for _, pool := range self.BucketAllocationPools {
|
||||
return pool.Start
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetIpEnd() string {
|
||||
for _, pool := range self.BucketAllocationPools {
|
||||
return pool.End
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetIpMask() int8 {
|
||||
return 8
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetGateway() string {
|
||||
return self.GetIpStart()
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetServerType() string {
|
||||
return api.NETWORK_TYPE_EIP
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetIsPublic() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetPublicScope() rbacutils.TRbacScope {
|
||||
return rbacutils.ScopeDomain
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) Delete() error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetAllocTimeoutSeconds() int {
|
||||
return 120 // 2 minutes
|
||||
}
|
||||
|
||||
func (self *SRegion) GetExternalNetwork(id string) (*SExternalNetwork, error) {
|
||||
ret := &SExternalNetwork{}
|
||||
res := fmt.Sprintf("subnets/%s", id)
|
||||
return ret, self.get("vpc", "v2.0", res, ret)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetExternalNetworks(netId string) ([]SExternalNetwork, error) {
|
||||
ret := []SExternalNetwork{}
|
||||
params := url.Values{}
|
||||
params.Set("network_id", netId)
|
||||
return ret, self.list("vpc", "v2.0", "subnets", params, &ret)
|
||||
}
|
||||
|
||||
func (self *SExternalNetwork) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// 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.
|
||||
|
||||
package hcs
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
|
||||
type SExternalVpc struct {
|
||||
multicloud.SVpc
|
||||
HcsTags
|
||||
|
||||
region *SRegion
|
||||
|
||||
Id string
|
||||
Name string
|
||||
CIDR string
|
||||
Status string
|
||||
Subnets []string
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) GetId() string {
|
||||
return self.Id
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) GetName() string {
|
||||
if len(self.Name) > 0 {
|
||||
return self.Name
|
||||
}
|
||||
return self.Id
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) GetGlobalId() string {
|
||||
return self.Id
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) GetStatus() string {
|
||||
return api.VPC_STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) GetRegion() cloudprovider.ICloudRegion {
|
||||
return self.region
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) GetIsDefault() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) GetCidrBlock() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
wire := &SExternalWire{region: self.region, vpc: self}
|
||||
return []cloudprovider.ICloudWire{wire}, nil
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) GetIWireById(id string) (cloudprovider.ICloudWire, error) {
|
||||
wires, err := self.GetIWires()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range wires {
|
||||
if wires[i].GetGlobalId() == id {
|
||||
return wires[i], nil
|
||||
}
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) GetIRouteTables() ([]cloudprovider.ICloudRouteTable, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) GetIRouteTableById(routeTableId string) (cloudprovider.ICloudRouteTable, error) {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SExternalVpc) Delete() error {
|
||||
return cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SRegion) GetExternalVpcs() ([]SExternalVpc, error) {
|
||||
ret := []SExternalVpc{}
|
||||
params := url.Values{}
|
||||
params.Set("router:external", "True")
|
||||
params.Set("service_type", "Intranet")
|
||||
return ret, self.list("vpc", "v2.0", "networks", params, &ret)
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// 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.
|
||||
|
||||
package hcs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
|
||||
// 华为云的子网有点特殊。子网在整个region可用。
|
||||
type SExternalWire struct {
|
||||
multicloud.SResourceBase
|
||||
HcsTags
|
||||
region *SRegion
|
||||
vpc *SExternalVpc
|
||||
}
|
||||
|
||||
func (self *SExternalWire) GetId() string {
|
||||
return fmt.Sprintf("%s-%s", self.vpc.GetId(), self.region.GetId())
|
||||
}
|
||||
|
||||
func (self *SExternalWire) GetName() string {
|
||||
return self.GetId()
|
||||
}
|
||||
|
||||
func (self *SExternalWire) GetGlobalId() string {
|
||||
return fmt.Sprintf("%s-%s", self.vpc.GetGlobalId(), self.region.GetGlobalId())
|
||||
}
|
||||
|
||||
func (self *SExternalWire) IsEmulated() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SExternalWire) GetStatus() string {
|
||||
return api.WIRE_STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (self *SExternalWire) GetIVpc() cloudprovider.ICloudVpc {
|
||||
return self.vpc
|
||||
}
|
||||
|
||||
func (self *SExternalWire) GetIZone() cloudprovider.ICloudZone {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SExternalWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) {
|
||||
nets, err := self.region.GetExternalNetworks(self.vpc.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []cloudprovider.ICloudNetwork{}
|
||||
for i := range nets {
|
||||
nets[i].wire = self
|
||||
ret = append(ret, &nets[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SExternalWire) GetBandwidth() int {
|
||||
return 10000
|
||||
}
|
||||
|
||||
func (self *SExternalWire) GetINetworkById(id string) (cloudprovider.ICloudNetwork, error) {
|
||||
net, err := self.region.GetExternalNetwork(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
net.wire = self
|
||||
return net, nil
|
||||
}
|
||||
|
||||
func (self *SExternalWire) CreateINetwork(opts *cloudprovider.SNetworkCreateOptions) (cloudprovider.ICloudNetwork, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
}
|
||||
+7
-3
@@ -261,8 +261,8 @@ func (self *SHcsClient) request(method httputils.THttpMethod, url string, query
|
||||
if len(self.projectId) > 0 && !strings.Contains(url, "v3/regions") {
|
||||
header.Set("X-Project-Id", self.projectId)
|
||||
}
|
||||
if len(self.domainId) > 0 {
|
||||
//header.Set("X-Domain-Id", self.domainId)
|
||||
if len(self.domainId) > 0 && strings.Contains(url, "/peering") {
|
||||
header.Set("X-Domain-Id", self.domainId)
|
||||
}
|
||||
cli := httputils.NewJsonClient(client)
|
||||
req := httputils.NewJsonRequest(method, url, body)
|
||||
@@ -485,7 +485,7 @@ func (self *SHcsClient) _url(product, version, regionId string, resource string)
|
||||
for _, prefix := range []string{
|
||||
"images", "cloudimages", "nat_gateways",
|
||||
"lbaas", "products", "snat_rules",
|
||||
"dnat_rules", "vpc/peerings",
|
||||
"dnat_rules", "networks",
|
||||
"ports",
|
||||
} {
|
||||
if strings.HasPrefix(resource, prefix) {
|
||||
@@ -493,6 +493,9 @@ func (self *SHcsClient) _url(product, version, regionId string, resource string)
|
||||
break
|
||||
}
|
||||
}
|
||||
if version == "v2.0" && strings.HasPrefix(resource, "subnets") {
|
||||
url = fmt.Sprintf("%s.%s.%s/%s/%s", product, regionId, self.authUrl, version, resource)
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
@@ -532,6 +535,7 @@ func (self *SHcsClient) _list(product, version, regionId string, resource string
|
||||
strings.Contains(strings.ReplaceAll(resource, "-", "_"), k) ||
|
||||
utils.IsInStringArray(k, []string{
|
||||
"availabilityZoneInfo",
|
||||
"vpc_peering_connections",
|
||||
}) {
|
||||
objs, err := v.GetArray()
|
||||
if err != nil {
|
||||
|
||||
+2
@@ -50,6 +50,8 @@ type SRegion struct {
|
||||
ZhCN string `json:"zh-cn"`
|
||||
}
|
||||
ParentRegionId string
|
||||
|
||||
peers []SVpcPeering
|
||||
}
|
||||
|
||||
func (self *SRegion) GetClient() *SHcsClient {
|
||||
|
||||
+23
-98
@@ -82,6 +82,10 @@ func (self *SVpc) GetCidrBlock() string {
|
||||
return self.CIDR
|
||||
}
|
||||
|
||||
func (self *SVpc) GetExternalAccessMode() string {
|
||||
return api.VPC_EXTERNAL_ACCESS_MODE_NONE
|
||||
}
|
||||
|
||||
func (self *SVpc) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
wire := &SWire{region: self.region, vpc: self}
|
||||
return []cloudprovider.ICloudWire{wire}, nil
|
||||
@@ -152,65 +156,6 @@ func (self *SVpc) GetINatGateways() ([]cloudprovider.ICloudNatGateway, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetICloudVpcPeeringConnections() ([]cloudprovider.ICloudVpcPeeringConnection, error) {
|
||||
svpcPCs, err := self.getVpcPeeringConnections()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "self.getVpcPeeringConnections()")
|
||||
}
|
||||
ivpcPCs := []cloudprovider.ICloudVpcPeeringConnection{}
|
||||
for i := range svpcPCs {
|
||||
ivpcPCs = append(ivpcPCs, &svpcPCs[i])
|
||||
}
|
||||
return ivpcPCs, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetICloudAccepterVpcPeeringConnections() ([]cloudprovider.ICloudVpcPeeringConnection, error) {
|
||||
svpcPCs, err := self.getAccepterVpcPeeringConnections()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "self.getAccepterVpcPeeringConnections()")
|
||||
}
|
||||
ivpcPCs := []cloudprovider.ICloudVpcPeeringConnection{}
|
||||
for i := range svpcPCs {
|
||||
ivpcPCs = append(ivpcPCs, &svpcPCs[i])
|
||||
}
|
||||
return ivpcPCs, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetICloudVpcPeeringConnectionById(id string) (cloudprovider.ICloudVpcPeeringConnection, error) {
|
||||
svpcPC, err := self.getVpcPeeringConnectionById(id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "self.getVpcPeeringConnectionById(%s)", id)
|
||||
}
|
||||
return svpcPC, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) CreateICloudVpcPeeringConnection(opts *cloudprovider.VpcPeeringConnectionCreateOptions) (cloudprovider.ICloudVpcPeeringConnection, error) {
|
||||
svpcPC, err := self.region.CreateVpcPeering(self.GetId(), opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "self.region.CreateVpcPeering(%s,%s)", self.GetId(), jsonutils.Marshal(opts).String())
|
||||
}
|
||||
svpcPC.vpc = self
|
||||
return svpcPC, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) AcceptICloudVpcPeeringConnection(id string) error {
|
||||
vpcPC, err := self.getVpcPeeringConnectionById(id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "self.getVpcPeeringConnectionById(%s)", id)
|
||||
}
|
||||
if vpcPC.GetStatus() == api.VPC_PEERING_CONNECTION_STATUS_ACTIVE {
|
||||
return nil
|
||||
}
|
||||
if vpcPC.GetStatus() == api.VPC_PEERING_CONNECTION_STATUS_UNKNOWN {
|
||||
return errors.Wrapf(cloudprovider.ErrInvalidStatus, "vpcPC: %s", jsonutils.Marshal(vpcPC).String())
|
||||
}
|
||||
err = self.region.AcceptVpcPeering(id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "self.region.AcceptVpcPeering(%s)", id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetAuthorityOwnerId() string {
|
||||
return self.region.client.projectId
|
||||
}
|
||||
@@ -260,57 +205,37 @@ func (self *SRegion) GetIVpcs() ([]cloudprovider.ICloudVpc, error) {
|
||||
vpcs[i].region = self
|
||||
ret = append(ret, &vpcs[i])
|
||||
}
|
||||
extVpcs, err := self.GetExternalVpcs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range extVpcs {
|
||||
extVpcs[i].region = self
|
||||
ret = append(ret, &extVpcs[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIVpcById(id string) (cloudprovider.ICloudVpc, error) {
|
||||
vpc, err := self.GetVpc(id)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
extVpcs, err := self.GetExternalVpcs()
|
||||
if err == nil {
|
||||
for i := range extVpcs {
|
||||
if extVpcs[i].Id == id {
|
||||
extVpcs[i].region = self
|
||||
return &extVpcs[i], nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
vpc.region = self
|
||||
return vpc, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) getVpcPeeringConnections() ([]SVpcPeering, error) {
|
||||
svpcPeerings, err := self.region.GetVpcPeerings(self.GetId())
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "self.region.GetVpcPeerings(%s)", self.GetId())
|
||||
}
|
||||
vpcPCs := []SVpcPeering{}
|
||||
for i := range svpcPeerings {
|
||||
if svpcPeerings[i].GetVpcId() == self.GetId() {
|
||||
svpcPeerings[i].vpc = self
|
||||
vpcPCs = append(vpcPCs, svpcPeerings[i])
|
||||
}
|
||||
}
|
||||
return vpcPCs, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) getAccepterVpcPeeringConnections() ([]SVpcPeering, error) {
|
||||
svpcPeerings, err := self.region.GetVpcPeerings(self.GetId())
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "self.region.GetVpcPeerings(%s)", self.GetId())
|
||||
}
|
||||
vpcPCs := []SVpcPeering{}
|
||||
for i := range svpcPeerings {
|
||||
if svpcPeerings[i].GetPeerVpcId() == self.GetId() {
|
||||
svpcPeerings[i].vpc = self
|
||||
vpcPCs = append(vpcPCs, svpcPeerings[i])
|
||||
}
|
||||
}
|
||||
return vpcPCs, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) getVpcPeeringConnectionById(id string) (*SVpcPeering, error) {
|
||||
svpcPC, err := self.region.GetVpcPeering(id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "self.region.GetVpcPeering(%s)", id)
|
||||
}
|
||||
svpcPC.vpc = self
|
||||
return svpcPC, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateIVpc(opts *cloudprovider.VpcCreateOptions) (cloudprovider.ICloudVpc, error) {
|
||||
return self.CreateVpc(opts.NAME, opts.CIDR, opts.Desc)
|
||||
}
|
||||
|
||||
+103
-29
@@ -42,54 +42,52 @@ type SVpcPeering struct {
|
||||
huawei.HuaweiTags
|
||||
vpc *SVpc
|
||||
|
||||
RequestVpcInfo RequestVpcInfo `json:"request_vpc_info"`
|
||||
AcceptVpcInfo AcceptVpcInfo `json:"accept_vpc_info"`
|
||||
RequestVpcInfo RequestVpcInfo `json:"requesterVpcInfo"`
|
||||
AcceptVpcInfo AcceptVpcInfo `json:"accepterVpcInfo"`
|
||||
Name string `json:"name"`
|
||||
Id string `json:"id"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func (self *SRegion) GetVpcPeerings(vpcId string) ([]SVpcPeering, error) {
|
||||
params := url.Values{}
|
||||
if len(vpcId) > 0 {
|
||||
params.Set("vpc_id", vpcId)
|
||||
}
|
||||
func (self *SRegion) GetVpcPeerings() ([]SVpcPeering, error) {
|
||||
ret := []SVpcPeering{}
|
||||
return ret, self.list("vpc", "v2.0", "vpc/peerings", params, &ret)
|
||||
return ret, self.list("vpc", "v1", "vpcpeering", nil, &ret)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetVpcPeering(id string) (*SVpcPeering, error) {
|
||||
ret := SVpcPeering{}
|
||||
resource := fmt.Sprintf("vpc/peerings/%s", id)
|
||||
return &ret, self.get("vpc", "v2.0", resource, &ret)
|
||||
ret := []SVpcPeering{}
|
||||
params := url.Values{}
|
||||
params.Set("peering_id", id)
|
||||
err := self.list("vpc", "v1", "vpcpeering", params, &ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range ret {
|
||||
if ret[i].Id == id {
|
||||
return &ret[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateVpcPeering(vpcId string, opts *cloudprovider.VpcPeeringConnectionCreateOptions) (*SVpcPeering, error) {
|
||||
params := map[string]interface{}{
|
||||
"peering": map[string]interface{}{
|
||||
"name": opts.Name,
|
||||
"request_vpc_info": map[string]interface{}{
|
||||
"vpc_id": vpcId,
|
||||
"tenant_id": self.client.projectId,
|
||||
},
|
||||
"accept_vpc_info": map[string]interface{}{
|
||||
"vpc_id": opts.PeerVpcId,
|
||||
"tenant_id": opts.PeerAccountId,
|
||||
},
|
||||
},
|
||||
"name": opts.Name,
|
||||
"local_vpc_id": vpcId,
|
||||
"peer_vpc_id": opts.PeerVpcId,
|
||||
}
|
||||
ret := &SVpcPeering{}
|
||||
return ret, self.create("vpc", "v2.0", "vpc/peerings", params, ret)
|
||||
return ret, self.create("vpc", "v1", "vpcpeering", params, ret)
|
||||
}
|
||||
|
||||
func (self *SRegion) AcceptVpcPeering(id string) error {
|
||||
res := fmt.Sprintf("vpc/peerings/%s/accept", id)
|
||||
return self.update("vpc", "v2.0", res, nil)
|
||||
res := fmt.Sprintf("vpcpeering/%s/accept", id)
|
||||
return self.update("vpc", "v1", res, nil)
|
||||
}
|
||||
|
||||
func (self *SRegion) DeleteVpcPeering(id string) error {
|
||||
res := fmt.Sprintf("vpc/peerings/%s", id)
|
||||
return self.delete("vpc", "v2.0", res)
|
||||
res := fmt.Sprintf("vpcpeering/%s", id)
|
||||
return self.delete("vpc", "v1", res)
|
||||
}
|
||||
|
||||
func (self *SVpcPeering) GetId() string {
|
||||
@@ -106,9 +104,9 @@ func (self *SVpcPeering) GetGlobalId() string {
|
||||
|
||||
func (self *SVpcPeering) GetStatus() string {
|
||||
switch self.Status {
|
||||
case "PENDING_ACCEPTANCE":
|
||||
case "pending_acceptance":
|
||||
return api.VPC_PEERING_CONNECTION_STATUS_PENDING_ACCEPT
|
||||
case "ACTIVE":
|
||||
case "active":
|
||||
return api.VPC_PEERING_CONNECTION_STATUS_ACTIVE
|
||||
default:
|
||||
return api.VPC_PEERING_CONNECTION_STATUS_UNKNOWN
|
||||
@@ -142,3 +140,79 @@ func (self *SVpcPeering) GetEnabled() bool {
|
||||
func (self *SVpcPeering) Delete() error {
|
||||
return self.vpc.region.DeleteVpcPeering(self.Id)
|
||||
}
|
||||
|
||||
func (self *SVpc) GetICloudVpcPeeringConnections() ([]cloudprovider.ICloudVpcPeeringConnection, error) {
|
||||
peers, err := self.region.GetVpcPeeringConnections()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetVpcPeeringConnections")
|
||||
}
|
||||
ret := []cloudprovider.ICloudVpcPeeringConnection{}
|
||||
for i := range peers {
|
||||
if peers[i].RequestVpcInfo.VpcId != self.Id {
|
||||
continue
|
||||
}
|
||||
peers[i].vpc = self
|
||||
ret = append(ret, &peers[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetICloudAccepterVpcPeeringConnections() ([]cloudprovider.ICloudVpcPeeringConnection, error) {
|
||||
peers, err := self.region.GetVpcPeeringConnections()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetVpcPeeringConnections")
|
||||
}
|
||||
ret := []cloudprovider.ICloudVpcPeeringConnection{}
|
||||
for i := range peers {
|
||||
if peers[i].AcceptVpcInfo.VpcId != self.Id {
|
||||
continue
|
||||
}
|
||||
peers[i].vpc = self
|
||||
ret = append(ret, &peers[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetICloudVpcPeeringConnectionById(id string) (cloudprovider.ICloudVpcPeeringConnection, error) {
|
||||
ret, err := self.region.GetVpcPeering(id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetVpcPeering(%s)", id)
|
||||
}
|
||||
ret.vpc = self
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) CreateICloudVpcPeeringConnection(opts *cloudprovider.VpcPeeringConnectionCreateOptions) (cloudprovider.ICloudVpcPeeringConnection, error) {
|
||||
ret, err := self.region.CreateVpcPeering(self.GetId(), opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "self.region.CreateVpcPeering(%s,%s)", self.GetId(), jsonutils.Marshal(opts).String())
|
||||
}
|
||||
ret.vpc = self
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) AcceptICloudVpcPeeringConnection(id string) error {
|
||||
peer, err := self.region.GetVpcPeering(id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetVpcPeering%s)", id)
|
||||
}
|
||||
if peer.GetStatus() == api.VPC_PEERING_CONNECTION_STATUS_ACTIVE {
|
||||
return nil
|
||||
}
|
||||
if peer.GetStatus() == api.VPC_PEERING_CONNECTION_STATUS_UNKNOWN {
|
||||
return errors.Wrapf(cloudprovider.ErrInvalidStatus, "vpcPC: %s", jsonutils.Marshal(peer).String())
|
||||
}
|
||||
return self.region.AcceptVpcPeering(id)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetVpcPeeringConnections() ([]SVpcPeering, error) {
|
||||
if len(self.peers) > 0 {
|
||||
return self.peers, nil
|
||||
}
|
||||
var err error
|
||||
self.peers, err = self.GetVpcPeerings()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetVpcPeerings()")
|
||||
}
|
||||
return self.peers, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user