diff --git a/pkg/util/aws/aws.go b/pkg/util/aws/aws.go index da044b068b..0645793e39 100644 --- a/pkg/util/aws/aws.go +++ b/pkg/util/aws/aws.go @@ -69,7 +69,10 @@ func (self *SAwsClient) fetchRegions() error { regions := make([]SRegion, 0) // empty iregions - self.iregions = self.iregions[:0] + if self.iregions != nil { + self.iregions = self.iregions[:0] + } + for _, region := range result.Regions { name := *region.RegionName endpoint := *region.Endpoint diff --git a/pkg/util/aws/host.go b/pkg/util/aws/host.go new file mode 100644 index 0000000000..a1f9c0e3be --- /dev/null +++ b/pkg/util/aws/host.go @@ -0,0 +1 @@ +package aws diff --git a/pkg/util/aws/instance.go b/pkg/util/aws/instance.go new file mode 100644 index 0000000000..a1f9c0e3be --- /dev/null +++ b/pkg/util/aws/instance.go @@ -0,0 +1 @@ +package aws diff --git a/pkg/util/aws/region.go b/pkg/util/aws/region.go index 95c9b2f095..7f244d4c96 100644 --- a/pkg/util/aws/region.go +++ b/pkg/util/aws/region.go @@ -3,6 +3,8 @@ package aws import ( "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/jsonutils" + "fmt" + "yunion.io/x/onecloud/pkg/compute/models" ) type SRegion struct { @@ -18,44 +20,61 @@ type SRegion struct { RegionId string // 这里为保持一致沿用阿里云RegionId的叫法, 与AWS RegionName字段对应 } +///////////////////////////////////////////////////////////////////////////// +/* todo: 请不要使用这个client(AWS_DEFAULT_REGION)跨region查信息.有可能导致查询返回的信息为空。比如DescribeAvailabilityZones*/ +func (self *SRegion) GetClient() (*SAwsClient) { + return self.client +} + +///////////////////////////////////////////////////////////////////////////// +func (self *SRegion) fetchInfrastructure() error { + // todo: implement me + return nil +} + func (self *SRegion) GetId() string { - panic("implement me") + return self.RegionId } func (self *SRegion) GetName() string { - panic("implement me") + return fmt.Sprintf("%s %s", CLOUD_PROVIDER_AWS_CN, self.RegionId) } func (self *SRegion) GetGlobalId() string { - panic("implement me") + return fmt.Sprintf("%s/%s", CLOUD_PROVIDER_AWS, self.RegionId) } func (self *SRegion) GetStatus() string { - panic("implement me") + return models.CLOUD_REGION_STATUS_INSERVER } func (self *SRegion) Refresh() error { - panic("implement me") + return nil } func (self *SRegion) IsEmulated() bool { - panic("implement me") + return false } func (self *SRegion) GetMetadata() *jsonutils.JSONDict { - panic("implement me") + return nil } func (self *SRegion) GetLatitude() float32 { - panic("implement me") + return 0.0 } func (self *SRegion) GetLongitude() float32 { - panic("implement me") + return 0.0 } func (self *SRegion) GetIZones() ([]cloudprovider.ICloudZone, error) { - panic("implement me") + if self.izones == nil { + if err := self.fetchInfrastructure(); err != nil { + return nil, err + } + } + return self.izones, nil } func (self *SRegion) GetIVpcs() ([]cloudprovider.ICloudVpc, error) { diff --git a/pkg/util/aws/zone.go b/pkg/util/aws/zone.go new file mode 100644 index 0000000000..a1f9c0e3be --- /dev/null +++ b/pkg/util/aws/zone.go @@ -0,0 +1 @@ +package aws