forked from yunionio/cloudmux
/
vpc.go
108 lines (87 loc) · 2.48 KB
/
vpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// 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 zstack
import (
"fmt"
api "github.com/nyl1001/cloudmux/pkg/apis/compute"
"github.com/nyl1001/cloudmux/pkg/cloudprovider"
"github.com/nyl1001/cloudmux/pkg/multicloud"
)
type SVpc struct {
multicloud.SVpc
ZStackTags
region *SRegion
iwires []cloudprovider.ICloudWire
}
func (vpc *SVpc) GetId() string {
return fmt.Sprintf("%s/vpc", vpc.region.GetGlobalId())
}
func (vpc *SVpc) GetName() string {
return fmt.Sprintf("%s-VPC", vpc.region.client.cpcfg.Name)
}
func (vpc *SVpc) GetGlobalId() string {
return vpc.GetId()
}
func (vpc *SVpc) IsEmulated() bool {
return true
}
func (vpc *SVpc) GetIsDefault() bool {
return true
}
func (vpc *SVpc) GetCidrBlock() string {
return ""
}
func (vpc *SVpc) GetStatus() string {
return api.VPC_STATUS_AVAILABLE
}
func (vpc *SVpc) Refresh() error {
return nil
}
func (vpc *SVpc) GetRegion() cloudprovider.ICloudRegion {
return vpc.region
}
func (vpc *SVpc) GetIWires() ([]cloudprovider.ICloudWire, error) {
if vpc.iwires == nil || len(vpc.iwires) == 0 {
vpc.iwires = []cloudprovider.ICloudWire{}
wires, err := vpc.region.GetWires("", "", "")
if err != nil {
return nil, err
}
for i := 0; i < len(wires); i++ {
wires[i].vpc = vpc
vpc.iwires = append(vpc.iwires, &wires[i])
}
}
return vpc.iwires, nil
}
func (vpc *SVpc) GetIWireById(wireId string) (cloudprovider.ICloudWire, error) {
wire, err := vpc.region.GetWire(wireId)
if err != nil {
return nil, err
}
wire.vpc = vpc
return wire, nil
}
func (vpc *SVpc) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, error) {
return []cloudprovider.ICloudSecurityGroup{}, nil
}
func (vpc *SVpc) GetIRouteTables() ([]cloudprovider.ICloudRouteTable, error) {
return nil, cloudprovider.ErrNotSupported
}
func (self *SVpc) GetIRouteTableById(routeTableId string) (cloudprovider.ICloudRouteTable, error) {
return nil, cloudprovider.ErrNotSupported
}
func (vpc *SVpc) Delete() error {
return nil
}