diff --git a/pkg/util/aws/disk.go b/pkg/util/aws/disk.go index 8c59b497b0..ba4ac661b5 100644 --- a/pkg/util/aws/disk.go +++ b/pkg/util/aws/disk.go @@ -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 +} \ No newline at end of file diff --git a/pkg/util/aws/eip.go b/pkg/util/aws/eip.go index f11513db8b..5920d48da5 100644 --- a/pkg/util/aws/eip.go +++ b/pkg/util/aws/eip.go @@ -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 +} \ No newline at end of file diff --git a/pkg/util/aws/image.go b/pkg/util/aws/image.go index a34bdabc1c..50e0b875d9 100644 --- a/pkg/util/aws/image.go +++ b/pkg/util/aws/image.go @@ -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 +} \ No newline at end of file diff --git a/pkg/util/aws/instance.go b/pkg/util/aws/instance.go index 596bc57556..fb425176bc 100644 --- a/pkg/util/aws/instance.go +++ b/pkg/util/aws/instance.go @@ -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 +} \ No newline at end of file diff --git a/pkg/util/aws/instancenic.go b/pkg/util/aws/instancenic.go new file mode 100644 index 0000000000..6a3ca44d3d --- /dev/null +++ b/pkg/util/aws/instancenic.go @@ -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 +} \ No newline at end of file diff --git a/pkg/util/aws/instancetype.go b/pkg/util/aws/instancetype.go index 5e71c60d21..5016e658c9 100644 --- a/pkg/util/aws/instancetype.go +++ b/pkg/util/aws/instancetype.go @@ -15,4 +15,8 @@ type SInstanceType struct { InstanceBandwidthTx int InstancePpsRx int InstancePpsTx int +} + +func (self *SRegion) GetInstanceTypes() ([]SInstanceType, error) { + return nil, nil } \ No newline at end of file diff --git a/pkg/util/aws/keypair.go b/pkg/util/aws/keypair.go index 5650f88fb4..7a182b8ace 100644 --- a/pkg/util/aws/keypair.go +++ b/pkg/util/aws/keypair.go @@ -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 } \ No newline at end of file diff --git a/pkg/util/aws/region.go b/pkg/util/aws/region.go index 7879463910..d7c93548de 100644 --- a/pkg/util/aws/region.go +++ b/pkg/util/aws/region.go @@ -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 { diff --git a/pkg/util/aws/snapshot.go b/pkg/util/aws/snapshot.go index 51854768af..8d3601d946 100644 --- a/pkg/util/aws/snapshot.go +++ b/pkg/util/aws/snapshot.go @@ -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") +} diff --git a/pkg/util/aws/storagecache.go b/pkg/util/aws/storagecache.go index 99abdc4fd1..1c196d3614 100644 --- a/pkg/util/aws/storagecache.go +++ b/pkg/util/aws/storagecache.go @@ -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 +} \ No newline at end of file