more sregion method

This commit is contained in:
TangBin
2018-10-15 12:03:31 +08:00
parent 37eed88871
commit 0fa48fd9e8
10 changed files with 316 additions and 83 deletions
+24
View File
@@ -158,3 +158,27 @@ func (self *SDisk) Resize(newSize int64) error {
func (self *SDisk) Reset(snapshotId string) error {
panic("implement me")
}
func (self *SRegion) GetDisks(instanceId string, zoneId string, category string, diskIds []string, offset int, limit int) ([]SDisk, int, error) {
return nil, 0, nil
}
func (self *SRegion) GetDisk(diskId string) (*SDisk, error) {
return nil, nil
}
func (self *SRegion) DeleteDisk(diskId string) error {
return nil
}
func (self *SRegion) resizeDisk(diskId string, size int64) error {
return nil
}
func (self *SRegion) resetDisk(diskId, snapshotId string) error {
return nil
}
func (self *SRegion) CreateSnapshot(diskId, name, desc string) (string, error) {
return "", nil
}
+39
View File
@@ -4,6 +4,7 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/onecloud/pkg/cloudprovider"
)
type SEipAddress struct {
@@ -120,3 +121,41 @@ func (region *SRegion) GetEips(eipId string) ([]SEipAddress, int, error) {
return eips, len(eips), nil
}
func (region *SRegion) GetEip(eipId string) (*SEipAddress, error) {
return nil, nil
}
func (region *SRegion) AllocateEIP(bwMbps int) (*SEipAddress, error) {
return nil, nil
}
func (self *SRegion) CreateEIP(name string, bwMbps int) (cloudprovider.ICloudEIP, error) {
eip, err := self.ec2Client.AllocateAddress(&ec2.AllocateAddressInput{})
if err != nil {
log.Errorf("AllocateEipAddress fail %s", err)
return nil, err
}
err = self.fetchInfrastructure()
if err != nil {
return nil, err
}
return self.GetIEipById(*eip.AllocationId)
}
func (region *SRegion) DeallocateEIP(eipId string) error {
return nil
}
func (region *SRegion) AssociateEip(eipId string, instanceId string) error {
return nil
}
func (region *SRegion) DissociateEip(eipId string, instanceId string) error {
return nil
}
func (region *SRegion) UpdateEipBandwidth(eipId string, bw int) error {
return nil
}
+81 -13
View File
@@ -4,17 +4,33 @@ import (
"time"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/compute/models"
)
type ImageStatusType string
const (
ImageStatusCreating ImageStatusType = "Creating"
ImageStatusAvailable ImageStatusType = "Available"
ImageStatusUnAvailable ImageStatusType = "UnAvailable"
ImageStatusCreateFailed ImageStatusType = "CreateFailed"
ImageStatusCreating ImageStatusType = "pending"
ImageStatusAvailable ImageStatusType = "available"
ImageStatusCreateFailed ImageStatusType = "failed"
)
type ImageOwnerType string
const (
ImageOwnerSystem ImageOwnerType = "system"
ImageOwnerSelf ImageOwnerType = "self"
ImageOwnerOthers ImageOwnerType = "others"
ImageOwnerMarketplace ImageOwnerType = "marketplace"
)
type ImageImportTask struct {
ImageId string
RegionId string
// RequestId string
TaskId string
}
type SImage struct {
storageCache *SStoragecache
@@ -34,37 +50,89 @@ type SImage struct {
}
func (self *SImage) GetId() string {
panic("implement me")
return self.ImageId
}
func (self *SImage) GetName() string {
panic("implement me")
return self.ImageName
}
func (self *SImage) GetGlobalId() string {
panic("implement me")
return self.ImageId
}
func (self *SImage) GetStatus() string {
panic("implement me")
switch self.Status {
case ImageStatusCreating:
return models.IMAGE_STATUS_QUEUED
case ImageStatusAvailable:
return models.IMAGE_STATUS_ACTIVE
case ImageStatusCreateFailed:
return models.IMAGE_STATUS_KILLED
default:
return models.IMAGE_STATUS_KILLED
}
}
func (self *SImage) Refresh() error {
panic("implement me")
// todo: GetImage
new, err := self.storageCache.region.GetImage(self.ImageId)
if err != nil {
return err
}
return jsonutils.Update(self, new)
}
func (self *SImage) IsEmulated() bool {
panic("implement me")
return false
}
func (self *SImage) GetMetadata() *jsonutils.JSONDict {
panic("implement me")
data := jsonutils.NewDict()
if len(self.Architecture) > 0 {
data.Add(jsonutils.NewString(self.Architecture), "os_arch")
}
if len(self.OSType) > 0 {
data.Add(jsonutils.NewString(self.OSType), "os_name")
}
if len(self.Platform) > 0 {
data.Add(jsonutils.NewString(self.Platform), "os_distribution")
}
if len(self.OSName) > 0 {
data.Add(jsonutils.NewString(self.OSName), "os_version")
}
return data
}
func (self *SImage) Delete() error {
panic("implement me")
// todo: implement meßß
return self.storageCache.region.DeleteImage(self.ImageId)
}
func (self *SImage) GetIStoragecache() cloudprovider.ICloudStoragecache {
panic("implement me")
return self.storageCache
}
func (self *SRegion) ImportImage(name string, osArch string, osType string, osDist string, bucket string, key string) (*ImageImportTask, error) {
return nil, nil
}
func (self *SRegion) GetImage(imageId string) (*SImage, error) {
return nil, nil
}
func (self *SRegion) GetImageByName(name string) (*SImage, error) {
return nil, nil
}
func (self *SRegion) GetImageStatus(imageId string) (ImageStatusType, error) {
return "",nil
}
func (self *SRegion) GetImages(status ImageStatusType, owner ImageOwnerType, imageId []string, name string, offset int, limit int) ([]SImage, int, error) {
return nil,0, nil
}
func (self *SRegion) DeleteImage(imageId string) error {
return nil
}
+92 -50
View File
@@ -111,56 +111,6 @@ type SInstance struct {
ZoneId string
}
func (self *SRegion) GetInstances(zoneId string, ids []string, offset int, limit int) ([]SInstance, int, error) {
params := &ec2.DescribeInstancesInput{}
filters := make([]*ec2.Filter, 0)
if len(zoneId) > 0 {
name := "availability-zone"
filters = append(filters, &ec2.Filter{Name: &name, Values: []*string{&zoneId}})
}
if len(ids) > 0 {
_ids := make([]*string, len(ids))
for _, id := range ids {
_ids = append(_ids, &id)
}
params = params.SetInstanceIds(_ids)
}
params = params.SetFilters(filters)
res, err := self.ec2Client.DescribeInstances(params)
if err != nil {
log.Errorf("GetInstances fail %s", err)
return nil, 0, err
}
instances := make([]SInstance, 0)
for _, reservation := range res.Reservations {
for _, instance := range reservation.Instances {
// todo :implement me later
instances = append(instances, SInstance{
InstanceId: *instance.InstanceId,
ImageId: *instance.ImageId,
InnerIpAddress: SIpAddress{[]string{*instance.PrivateIpAddress}},
PublicIpAddress: SIpAddress{[]string{*instance.PublicIpAddress}},
})
}
}
return instances, len(instances), nil
}
func (self *SRegion) GetInstance(instanceId string) (*SInstance, error) {
instances, _, err := self.GetInstances("", []string{instanceId}, 0, 1)
if err != nil {
return nil, err
}
if len(instances) == 0 {
return nil, cloudprovider.ErrNotFound
}
return &instances[0], nil
}
func (self *SInstance) GetId() string {
panic("implement me")
}
@@ -300,3 +250,95 @@ func (self *SInstance) AttachDisk(diskId string) error {
func (self *SInstance) DetachDisk(diskId string) error {
panic("implement me")
}
func (self *SRegion) GetInstances(zoneId string, ids []string, offset int, limit int) ([]SInstance, int, error) {
params := &ec2.DescribeInstancesInput{}
filters := make([]*ec2.Filter, 0)
if len(zoneId) > 0 {
name := "availability-zone"
filters = append(filters, &ec2.Filter{Name: &name, Values: []*string{&zoneId}})
}
if len(ids) > 0 {
_ids := make([]*string, len(ids))
for _, id := range ids {
_ids = append(_ids, &id)
}
params = params.SetInstanceIds(_ids)
}
params = params.SetFilters(filters)
res, err := self.ec2Client.DescribeInstances(params)
if err != nil {
log.Errorf("GetInstances fail %s", err)
return nil, 0, err
}
instances := make([]SInstance, 0)
for _, reservation := range res.Reservations {
for _, instance := range reservation.Instances {
// todo :implement me later
instances = append(instances, SInstance{
InstanceId: *instance.InstanceId,
ImageId: *instance.ImageId,
InnerIpAddress: SIpAddress{[]string{*instance.PrivateIpAddress}},
PublicIpAddress: SIpAddress{[]string{*instance.PublicIpAddress}},
})
}
}
return instances, len(instances), nil
}
func (self *SRegion) GetInstance(instanceId string) (*SInstance, error) {
instances, _, err := self.GetInstances("", []string{instanceId}, 0, 1)
if err != nil {
return nil, err
}
if len(instances) == 0 {
return nil, cloudprovider.ErrNotFound
}
return &instances[0], nil
}
func (self *SRegion) CreateInstance(name string, imageId string, instanceType string, securityGroupId string,
zoneId string, desc string, passwd string, disks []SDisk, vSwitchId string, ipAddr string,
keypair string) (string, error) {
return "", nil
}
func (self *SRegion) StartVM(instanceId string) error {
return nil
}
func (self *SRegion) StopVM(instanceId string, isForce bool) error {
return nil
}
func (self *SRegion) DeleteVM(instanceId string) error {
return nil
}
func (self *SRegion) DeployVM(instanceId string, name string, password string, keypairName string, deleteKeypair bool, description string) error {
return nil
}
func (self *SRegion) UpdateVM(instanceId string, hostname string) error {
return nil
}
func (self *SRegion) ReplaceSystemDisk(instanceId string, imageId string, passwd string, keypairName string, sysDiskSizeGB int) (string, error) {
return "", nil
}
func (self *SRegion) ChangeVMConfig(zoneId string, instanceId string, ncpu int, vmem int, disks []*SDisk) error {
return nil
}
func (self *SRegion) DetachDisk(instanceId string, diskId string) error {
return nil
}
func (self *SRegion) AttachDisk(instanceId string, diskId string) error {
return nil
}
+24
View File
@@ -0,0 +1,24 @@
package aws
import "yunion.io/x/onecloud/pkg/cloudprovider"
type SInstanceNic struct {
instance *SInstance
ipAddr string
}
func (self *SInstanceNic) GetIP() string {
return ""
}
func (self *SInstanceNic) GetMAC() string {
return ""
}
func (self *SInstanceNic) GetDriver() string {
return ""
}
func (self *SInstanceNic) GetINetwork() cloudprovider.ICloudNetwork {
return nil
}
+4
View File
@@ -15,4 +15,8 @@ type SInstanceType struct {
InstanceBandwidthTx int
InstancePpsRx int
InstancePpsTx int
}
func (self *SRegion) GetInstanceTypes() ([]SInstanceType, error) {
return nil, nil
}
+28
View File
@@ -3,4 +3,32 @@ package aws
type SKeypair struct {
KeyPairFingerPrint string
KeyPairName string
}
func (self *SRegion) GetKeypairs(finger string, name string, offset int, limit int) ([]SKeypair, int, error) {
return nil, 0, nil
}
func (self *SRegion) ImportKeypair(name string, pubKey string) (*SKeypair, error) {
return nil, nil
}
func (self *SRegion) AttachKeypair(instanceId string, name string) error {
return nil
}
func (self *SRegion) DetachKeyPair(instanceId string, name string) error {
return nil
}
func (self *SRegion) lookUpAwsKeypair(publicKey string) (string, error) {
return "", nil
}
func (self *SRegion) importAwsKeypair(publicKey string) (string, error) {
return "", nil
}
func (self *SRegion) syncKeypair(publicKey string) (string, error) {
return "", nil
}
-19
View File
@@ -3,7 +3,6 @@ package aws
import (
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"fmt"
"yunion.io/x/onecloud/pkg/compute/models"
sdk "github.com/aws/aws-sdk-go/aws"
@@ -180,10 +179,6 @@ func (self *SRegion) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) {
return nil, httperrors.NewNotImplementedError("not implement")
}
func (self *SRegion) GetISnapshotById(snapshotId string) (cloudprovider.ICloudSnapshot, error) {
return nil, httperrors.NewNotImplementedError("not implement")
}
func (self *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
izones, err := self.GetIZones()
if err != nil {
@@ -271,20 +266,6 @@ func (self *SRegion) CreateIVpc(name string, desc string, cidr string) (cloudpro
return self.GetIVpcById(*vpc.Vpc.VpcId)
}
func (self *SRegion) CreateEIP(name string, bwMbps int, chargeType string) (cloudprovider.ICloudEIP, error) {
eip, err := self.ec2Client.AllocateAddress(&ec2.AllocateAddressInput{})
if err != nil {
log.Errorf("AllocateEipAddress fail %s", err)
return nil, err
}
err = self.fetchInfrastructure()
if err != nil {
return nil, err
}
return self.GetIEipById(*eip.AllocationId)
}
func (self *SRegion) GetIEipById(eipId string) (cloudprovider.ICloudEIP, error) {
eips, total, err := self.GetEips(eipId)
if err != nil {
+12 -1
View File
@@ -1,6 +1,10 @@
package aws
import "yunion.io/x/jsonutils"
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/httperrors"
)
type SnapshotStatusType string
@@ -71,3 +75,10 @@ func (self *SSnapshot) GetRegionId() string {
panic("implement me")
}
func (self *SRegion) GetSnapshots(instanceId string, diskId string, snapshotName string, snapshotIds []string, offset int, limit int) ([]SSnapshot, int, error) {
return nil, 0 , nil
}
func (self *SRegion) GetISnapshotById(snapshotId string) (cloudprovider.ICloudSnapshot, error) {
return nil, httperrors.NewNotImplementedError("not implement")
}
+12
View File
@@ -4,6 +4,7 @@ import (
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
type SStoragecache struct {
@@ -60,3 +61,14 @@ func (self *SStoragecache) UploadImage(userCred mcclient.TokenCredential, imageI
panic("implement me")
}
func (self *SRegion) CheckBucket(bucketName string) (*oss.Bucket, error) {
return self.checkBucket(bucketName)
}
func (self *SRegion) checkBucket(bucketName string) (*oss.Bucket, error) {
return nil, nil
}
func (self *SRegion) createIImage(snapshoutId, imageName, imageDesc string) (string, error) {
return "", nil
}