add network

This commit is contained in:
TangBin
2018-10-15 18:08:54 +08:00
parent dd04411422
commit 542dedd2d2
4 changed files with 142 additions and 9 deletions
+16 -7
View File
@@ -5,7 +5,7 @@ import (
"yunion.io/x/onecloud/pkg/cloudprovider"
"fmt"
"yunion.io/x/onecloud/pkg/compute/models"
"github.com/aws/aws-sdk-go/service/ec2"
"yunion.io/x/log"
)
type SHost struct {
@@ -153,12 +153,21 @@ func (self *SHost) GetInstanceById(instanceId string) (*SInstance, error) {
return inst, nil
}
func (self *SHost) CreateVM(name string, imgId string, sysDiskSize int, cpu int, memMB int, vswitchId string, ipAddr string, desc string,
passwd string, storageType string, diskSizes []int, publicKey string, extSecGrpId string) (cloudprovider.ICloudVM, error) {
vmId, err := self._createVM(name, imgId, sysDiskSize, cpu, memMB, vswitchId, ipAddr, desc, passwd, storageType, diskSizes, publicKey, secgroupId)
func (self *SHost) CreateVM(name, imgId string, sysDiskSize, cpu, memMB int, networkId, ipAddr, desc,
passwd, storageType string, diskSizes []int, publicKey string, secgroupId string) (cloudprovider.ICloudVM, error) {
if len(publicKey) < 0 {
return nil, fmt.Errorf("AWS instance create error: keypair required")
}
if len(passwd) > 0 {
log.Debugf("Ignored: AWS not support password.Use keypair instand")
}
vmId, err := self._createVM(name, imgId, sysDiskSize, cpu, memMB, networkId, ipAddr, desc, passwd, storageType, diskSizes, publicKey, secgroupId)
if err != nil {
return nil, err
}
vm, err := self.GetInstanceById(vmId)
if err != nil {
return nil, err
@@ -167,12 +176,12 @@ func (self *SHost) CreateVM(name string, imgId string, sysDiskSize int, cpu int,
return vm, err
}
func (self *SHost) _createVM(name string, imgId string, sysDiskSize int, cpu int, memMB int,
vswitchId string, ipAddr string, desc string, passwd string,
func (self *SHost) _createVM(name, imgId string, sysDiskSize, cpu, memMB int,
networkId, ipAddr, desc, passwd,
storageType string, diskSizes []int, publicKey string, secgroupId string) (string, error) {
// 网络配置及安全组绑定
// todo:// https://www.guru99.com/creating-amazon-ec2-instance.html
self.zone.getNetworkById(vswitchId)
self.zone.getNetworkById(networkId)
// 同步keypair
// 镜像及硬盘配置
+99
View File
@@ -0,0 +1,99 @@
package aws
import (
"time"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/cloudprovider"
)
type SNetwork struct {
wire *SWire
AvailableIpAddressCount int
CidrBlock string
CreationTime time.Time
Description string
IsDefault bool
Status string
VSwitchId string
VSwitchName string
VpcId string
ZoneId string
}
func (self *SNetwork) GetId() string {
panic("implement me")
}
func (self *SNetwork) GetName() string {
panic("implement me")
}
func (self *SNetwork) GetGlobalId() string {
panic("implement me")
}
func (self *SNetwork) GetStatus() string {
panic("implement me")
}
func (self *SNetwork) Refresh() error {
panic("implement me")
}
func (self *SNetwork) IsEmulated() bool {
panic("implement me")
}
func (self *SNetwork) GetMetadata() *jsonutils.JSONDict {
panic("implement me")
}
func (self *SNetwork) GetIWire() cloudprovider.ICloudWire {
panic("implement me")
}
func (self *SNetwork) GetIpStart() string {
panic("implement me")
}
func (self *SNetwork) GetIpEnd() string {
panic("implement me")
}
func (self *SNetwork) GetIpMask() int8 {
panic("implement me")
}
func (self *SNetwork) GetGateway() string {
panic("implement me")
}
func (self *SNetwork) GetServerType() string {
panic("implement me")
}
func (self *SNetwork) GetIsPublic() bool {
panic("implement me")
}
func (self *SNetwork) Delete() error {
panic("implement me")
}
func (self *SNetwork) GetAllocTimeoutSeconds() int {
panic("implement me")
}
func (self *SRegion) createNetwork(zoneId string, vpcId string, name string, cidr string, desc string) (string, error) {
return "", nil
}
func (self *SRegion) getNetwork(vswitchId string) (*SNetwork, error) {
return nil, nil
}
func (self *SRegion) deleteNetwork(vswitchId string) error {
return nil
}
+16
View File
@@ -4,6 +4,7 @@ import (
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/jsonutils"
"fmt"
"yunion.io/x/log"
)
type SWire struct {
@@ -72,3 +73,18 @@ func (self *SWire) CreateINetwork(name string, cidr string, desc string) (cloudp
panic("implement me")
}
func (self *SWire) getNetworkById(networkId string) *SNetwork {
networks, err := self.GetINetworks()
if err != nil {
return nil
}
log.Debugf("search for networks %d", len(networks))
for i := 0; i < len(networks); i += 1 {
log.Debugf("search %s", networks[i].GetName())
network := networks[i]
if network.GetId() == networkId {
return network.(*SNetwork)
}
}
return nil
}
+11 -2
View File
@@ -5,6 +5,7 @@ import (
"yunion.io/x/jsonutils"
"fmt"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/log"
)
type SZone struct {
@@ -42,8 +43,16 @@ func (self *SZone) GetIWires() ([]cloudprovider.ICloudWire, error) {
return self.iwires, nil
}
func (self *SZone) getNetworkById(vswitchId string) error {
// todo: implement me
func (self *SZone) getNetworkById(networkId string) error {
log.Debugf("Search in wires %d", len(self.iwires))
for i := 0; i < len(self.iwires); i += 1 {
log.Debugf("Search in wire %s", self.iwires[i].GetName())
wire := self.iwires[i].(*SWire)
net := wire.getNetworkById(networkId)
if net != nil {
return net
}
}
return nil
}