diff --git a/cmd/climc/shell/compute/app.go b/cmd/climc/shell/compute/app.go index b5ce9610cb..c49dced06d 100644 --- a/cmd/climc/shell/compute/app.go +++ b/cmd/climc/shell/compute/app.go @@ -25,6 +25,10 @@ func init() { cmd.List(&compute.AppListOptions{}) cmd.Show(&compute.AppIdOptions{}) cmd.Perform("syncstatus", &compute.AppIdOptions{}) + cmd.Get("hybird-connections", &compute.AppIdOptions{}) + cmd.Get("certificates", &compute.AppIdOptions{}) + cmd.Get("backups", &compute.AppIdOptions{}) + cmd.Get("domains", &compute.AppIdOptions{}) cmd1 := shell.NewResourceCmd(&modules.AppEnvironments) cmd1.List(&compute.AppEnvironmentListOptions{}) diff --git a/go.mod b/go.mod index 6cc267a0f7..9580e064ed 100644 --- a/go.mod +++ b/go.mod @@ -93,12 +93,12 @@ require ( k8s.io/cri-api v0.22.17 k8s.io/klog/v2 v2.2.0 moul.io/http2curl/v2 v2.3.0 - yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240509034528-f8a254dbdebe + yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240514110418-588882cc7ff0 yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 yunion.io/x/jsonutils v1.0.1-0.20240203102553-4096f103b401 yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91 yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 - yunion.io/x/pkg v1.10.1-0.20240508102846-e4ad08e1f410 + yunion.io/x/pkg v1.10.1-0.20240510032728-8203b24857a2 yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e yunion.io/x/sqlchemy v1.1.3-0.20240417115142-4f4271cd8305 yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c diff --git a/go.sum b/go.sum index 3c074acfa4..f7675e6e35 100644 --- a/go.sum +++ b/go.sum @@ -1225,8 +1225,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= -yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240509034528-f8a254dbdebe h1:wWwojWeLu+0qrQFLIxldXb+ar27ho9aF2Fe4UCFu1u0= -yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240509034528-f8a254dbdebe/go.mod h1:PkfAKJcu5mic7jyJpT4GxZ8BKIVMa+6eyOP2G94VKAs= +yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240514110418-588882cc7ff0 h1:KJN+gnBaA+AXdnE2M5FNnkrhZtyaYYaBmlJlFGj9akI= +yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240514110418-588882cc7ff0/go.mod h1:quoJjGTJ2PjAY0+3YeN5JuN136whECKmfkJQwIsXKjM= yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug= yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws= yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634= @@ -1240,8 +1240,8 @@ yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 h1:Hu/4ERvoWaN6aiFs4h4/yvVB yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900/go.mod h1:0vLkNEhlmA64HViPBAnSTUMrx5QP1CLsxXmxDKQ80tc= yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E= yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E= -yunion.io/x/pkg v1.10.1-0.20240508102846-e4ad08e1f410 h1:ytervMn5lW8X4iHytK14t5FZlvB4boKNcQsFFGonQRM= -yunion.io/x/pkg v1.10.1-0.20240508102846-e4ad08e1f410/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk= +yunion.io/x/pkg v1.10.1-0.20240510032728-8203b24857a2 h1:UWVod1oFuoscPf86G3YdKyKaWr0URuA9ubt4mYwhQyY= +yunion.io/x/pkg v1.10.1-0.20240510032728-8203b24857a2/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk= yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo= yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo= yunion.io/x/sqlchemy v1.1.3-0.20240417115142-4f4271cd8305 h1:TIXzc634+YSAs2+3A+TyPmKAGd6HtAYU3M4cKwzUuo0= diff --git a/pkg/apis/compute/app.go b/pkg/apis/compute/app.go index 5699445003..544f3bff3e 100644 --- a/pkg/apis/compute/app.go +++ b/pkg/apis/compute/app.go @@ -14,7 +14,11 @@ package compute -import "yunion.io/x/onecloud/pkg/apis" +import ( + "time" + + "yunion.io/x/onecloud/pkg/apis" +) const ( APP_TYPE_WEB = "web" @@ -38,6 +42,9 @@ type AppDetails struct { apis.VirtualResourceDetails ManagedResourceInfo CloudregionResourceInfo + Network string + VpcId string + Vpc string } type AppEnvironmentListInput struct { @@ -51,3 +58,56 @@ type AppEnvironmentListInput struct { type AppEnvironmentDetails struct { apis.VirtualResourceDetails } + +type AppHybirdConnection struct { + Id string + Name string + Hostname string + Namespace string + Port int +} + +type AppHybirdConnectionOutput struct { + Data []AppHybirdConnection +} + +type AppBackup struct { + Id string + Name string + Type string +} + +type AppBackupOutput struct { + Data []AppBackup + BackupConfig struct { + Enabled bool + FrequencyInterval int + FrequencyUnit string + RetentionPeriodInDays int + } +} + +type AppCertificate struct { + Id string + Name string + SubjectName string + Issuer string + IssueDate time.Time + Thumbprint string + ExpireTime time.Time +} + +type AppCertificateOutput struct { + Data []AppCertificate +} + +type AppDomain struct { + Id string + Name string + Status string + SslState string +} + +type AppDomainOutput struct { + Data []AppDomain +} diff --git a/pkg/compute/models/app.go b/pkg/compute/models/app.go index 94b79c2a65..762a2adb92 100644 --- a/pkg/compute/models/app.go +++ b/pkg/compute/models/app.go @@ -46,6 +46,7 @@ type SAppManager struct { SManagedResourceBaseManager SCloudregionResourceBaseManager + SNetworkResourceBaseManager } type SApp struct { @@ -55,10 +56,14 @@ type SApp struct { SManagedResourceBase SCloudregionResourceBase + SNetworkResourceBase - Type string `width:"16" charset:"ascii" nullable:"false" get:"user" list:"user"` - TechStack string `width:"64" charset:"ascii" nullable:"false" get:"user" list:"user"` - Kind string `width:"64" charset:"ascii" nullable:"false" get:"user" list:"user"` + TechStack string `width:"64" charset:"ascii" nullable:"false" get:"user" list:"user"` + OsType string `width:"12" charset:"ascii" nullable:"true" get:"user" list:"user"` + IpAddr string `width:"32" charset:"ascii" nullable:"true" list:"user"` + Hostname string `width:"256" charset:"utf8" nullable:"true" list:"user"` + ServerFarm string `width:"64" charset:"utf8" nullable:"true" list:"user"` + PublicNetworkAccess string `width:"32" charset:"utf8" nullable:"true" list:"user"` } var AppManager *SAppManager @@ -75,10 +80,6 @@ func init() { AppManager.SetVirtualObject(AppManager) } -func (am *SAppManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { - return true -} - func (am *SAppManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.AppListInput) (*sqlchemy.SQuery, error) { q, err := am.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput) if err != nil { @@ -277,11 +278,29 @@ func (self *SCloudregion) newFromCloudApp(ctx context.Context, userCred mcclient app.ManagerId = provider.Id app.IsEmulated = ext.IsEmulated() app.Status = ext.GetStatus() - app.Type = ext.GetType() - app.Kind = ext.GetKind() app.TechStack = ext.GetTechStack() app.Name = ext.GetName() app.Enabled = tristate.True + app.OsType = string(ext.GetOsType()) + app.IpAddr = ext.GetIpAddress() + app.Hostname = ext.GetHostname() + app.ServerFarm = ext.GetServerFarm() + app.PublicNetworkAccess = ext.GetPublicNetworkAccess() + + if netId := ext.GetNetworkId(); len(netId) > 0 { + network, err := db.FetchByExternalIdAndManagerId(NetworkManager, netId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery { + wire := WireManager.Query().SubQuery() + vpc := VpcManager.Query().SubQuery() + return q.Join(wire, sqlchemy.Equals(wire.Field("id"), q.Field("wire_id"))). + Join(vpc, sqlchemy.Equals(vpc.Field("id"), wire.Field("vpc_id"))). + Filter(sqlchemy.Equals(vpc.Field("manager_id"), provider.Id)) + }) + if err != nil { + log.Errorf("fetch network %s error: %v", netId, err) + } else { + app.NetworkId = network.GetId() + } + } err := AppManager.TableSpec().Insert(ctx, &app) if err != nil { @@ -321,6 +340,10 @@ func (am *SAppManager) purgeAll(ctx context.Context, userCred mcclient.TokenCred return nil } +func (a *SApp) GetChangeOwnerCandidateDomainIds() []string { + return nil +} + func (a *SApp) purge(ctx context.Context, userCred mcclient.TokenCredential) error { aes, err := a.GetAppEnvironments() if err != nil { @@ -351,9 +374,28 @@ func (a *SApp) SyncWithCloudApp(ctx context.Context, userCred mcclient.TokenCred diff, err := db.UpdateWithLock(ctx, a, func() error { a.ExternalId = ext.GetGlobalId() a.Status = ext.GetStatus() - a.Type = ext.GetType() - a.Kind = ext.GetKind() a.TechStack = ext.GetTechStack() + a.OsType = string(ext.GetOsType()) + a.IpAddr = ext.GetIpAddress() + a.Hostname = ext.GetHostname() + a.ServerFarm = ext.GetServerFarm() + a.PublicNetworkAccess = ext.GetPublicNetworkAccess() + + if netId := ext.GetNetworkId(); len(netId) > 0 && len(a.NetworkId) == 0 { + network, err := db.FetchByExternalIdAndManagerId(NetworkManager, netId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery { + wire := WireManager.Query().SubQuery() + vpc := VpcManager.Query().SubQuery() + return q.Join(wire, sqlchemy.Equals(wire.Field("id"), q.Field("wire_id"))). + Join(vpc, sqlchemy.Equals(vpc.Field("id"), wire.Field("vpc_id"))). + Filter(sqlchemy.Equals(vpc.Field("manager_id"), provider.Id)) + }) + if err != nil { + log.Errorf("fetch network %s error: %v", netId, err) + } else { + a.NetworkId = network.GetId() + } + } + return nil }) if err != nil { @@ -384,10 +426,14 @@ func (am *SAppManager) FetchCustomizeColumns(ctx context.Context, userCred mccli virtRows := am.SVirtualResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList) manRows := am.SManagedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList) regRows := am.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList) + netRows := am.SNetworkResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList) for i := range rows { rows[i].VirtualResourceDetails = virtRows[i] rows[i].ManagedResourceInfo = manRows[i] rows[i].CloudregionResourceInfo = regRows[i] + rows[i].Network = netRows[i].Network + rows[i].VpcId = netRows[i].VpcId + rows[i].Vpc = netRows[i].Vpc } return rows } @@ -406,7 +452,7 @@ func (a *SApp) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCre } func (a *SApp) GetIRegion(ctx context.Context) (cloudprovider.ICloudRegion, error) { - region, err := a.GetRegion() + region, err := a.SCloudregionResourceBase.GetRegion() if err != nil { return nil, errors.Wrap(err, "GetRegion") } @@ -459,3 +505,107 @@ func (self *SApp) OnMetadataUpdated(ctx context.Context, userCred mcclient.Token log.Errorf("StartRemoteUpdateTask fail: %s", err) } } + +// 获取混合连接 +func (self *SApp) GetDetailsHybirdConnections(ctx context.Context, userCred mcclient.TokenCredential, input jsonutils.JSONObject) (*api.AppHybirdConnectionOutput, error) { + iApp, err := self.GetIApp(ctx) + if err != nil { + return nil, err + } + ret := &api.AppHybirdConnectionOutput{ + Data: []api.AppHybirdConnection{}, + } + connections, err := iApp.GetHybirdConnections() + if err != nil { + return nil, err + } + for _, conn := range connections { + ret.Data = append(ret.Data, api.AppHybirdConnection{ + Id: conn.GetGlobalId(), + Name: conn.GetName(), + Hostname: conn.GetHostname(), + Namespace: conn.GetNamespace(), + Port: conn.GetPort(), + }) + } + return ret, nil +} + +// 获取备份列表 +func (self *SApp) GetDetailsBackups(ctx context.Context, userCred mcclient.TokenCredential, input jsonutils.JSONObject) (*api.AppBackupOutput, error) { + iApp, err := self.GetIApp(ctx) + if err != nil { + return nil, err + } + ret := &api.AppBackupOutput{ + Data: []api.AppBackup{}, + } + + backups, err := iApp.GetBackups() + if err != nil { + return nil, err + } + for _, backup := range backups { + ret.Data = append(ret.Data, api.AppBackup{ + Id: backup.GetGlobalId(), + Name: backup.GetName(), + Type: backup.GetType(), + }) + } + opts := iApp.GetBackupConfig() + jsonutils.Update(&ret.BackupConfig, opts) + return ret, nil +} + +// 获取证书列表 +func (self *SApp) GetDetailsCertificates(ctx context.Context, userCred mcclient.TokenCredential, input jsonutils.JSONObject) (*api.AppCertificateOutput, error) { + iApp, err := self.GetIApp(ctx) + if err != nil { + return nil, err + } + ret := &api.AppCertificateOutput{ + Data: []api.AppCertificate{}, + } + + certs, err := iApp.GetCertificates() + if err != nil { + return nil, err + } + for _, cert := range certs { + ret.Data = append(ret.Data, api.AppCertificate{ + Id: cert.GetGlobalId(), + Name: cert.GetName(), + SubjectName: cert.GetSubjectName(), + Issuer: cert.GetIssuer(), + IssueDate: cert.GetIssueDate(), + Thumbprint: cert.GetThumbprint(), + ExpireTime: cert.GetExpireTime(), + }) + } + return ret, nil +} + +// 获取自定义域列表 +func (self *SApp) GetDetailsDomains(ctx context.Context, userCred mcclient.TokenCredential, input jsonutils.JSONObject) (*api.AppDomainOutput, error) { + iApp, err := self.GetIApp(ctx) + if err != nil { + return nil, err + } + ret := &api.AppDomainOutput{ + Data: []api.AppDomain{}, + } + + domains, err := iApp.GetDomains() + if err != nil { + return nil, err + } + for _, domain := range domains { + ret.Data = append(ret.Data, api.AppDomain{ + Id: domain.GetGlobalId(), + Name: domain.GetName(), + Status: domain.GetStatus(), + SslState: domain.GetSslState(), + }) + } + return ret, nil +} diff --git a/pkg/compute/models/app_environment.go b/pkg/compute/models/app_environment.go index d9c3c95637..563180e37d 100644 --- a/pkg/compute/models/app_environment.go +++ b/pkg/compute/models/app_environment.go @@ -39,9 +39,7 @@ type SAppEnvironment struct { db.SVirtualResourceBase db.SExternalizedResourceBase - AppId string `width:"36" charset:"ascii" index:"true"` - InstanceType string `width:"16" charset:"ascii" index:"true" get:"user" list:"user"` - InstanceNumber int `get:"user" list:"user"` + AppId string `width:"36" charset:"ascii" index:"true"` } var AppEnvironmentManager *SAppEnvironmentManager @@ -163,15 +161,6 @@ func (a *SApp) newFromCloudAppEnvironment(ctx context.Context, userCred mcclient appEnvironment.ExternalId = ext.GetGlobalId() appEnvironment.IsEmulated = ext.IsEmulated() appEnvironment.Status = ext.GetStatus() - appEnvironment.InstanceType, err = ext.GetInstanceType() - if err != nil { - return nil, errors.Wrap(err, "unable to GetInsntaceType") - } - - appEnvironment.InstanceNumber, err = ext.GetInstanceNumber() - if err != nil { - return nil, errors.Wrap(err, "unable to GetInstanceNumber") - } appEnvironment.Name = ext.GetName() appEnvironment.AppId = a.Id @@ -191,17 +180,8 @@ func (ae *SAppEnvironment) syncRemoveCloudAppEnvironment(ctx context.Context, us func (ae *SAppEnvironment) SyncWithCloudAppEnvironment(ctx context.Context, userCred mcclient.TokenCredential, ext cloudprovider.ICloudAppEnvironment) error { _, err := db.UpdateWithLock(ctx, ae, func() error { - var err error ae.ExternalId = ext.GetGlobalId() ae.Status = ext.GetStatus() - ae.InstanceType, err = ext.GetInstanceType() - if err != nil { - return err - } - ae.InstanceNumber, err = ext.GetInstanceNumber() - if err != nil { - return err - } return nil }) if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index b7c2692a96..9bdd153848 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1508,7 +1508,7 @@ sigs.k8s.io/structured-merge-diff/v4/value # sigs.k8s.io/yaml v1.2.0 ## explicit; go 1.12 sigs.k8s.io/yaml -# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240509034528-f8a254dbdebe +# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240514110418-588882cc7ff0 ## explicit; go 1.18 yunion.io/x/cloudmux/pkg/apis yunion.io/x/cloudmux/pkg/apis/billing @@ -1605,7 +1605,7 @@ yunion.io/x/log/hooks yunion.io/x/ovsdb/cli_util yunion.io/x/ovsdb/schema/ovn_nb yunion.io/x/ovsdb/types -# yunion.io/x/pkg v1.10.1-0.20240508102846-e4ad08e1f410 +# yunion.io/x/pkg v1.10.1-0.20240510032728-8203b24857a2 ## explicit; go 1.18 yunion.io/x/pkg/appctx yunion.io/x/pkg/errors diff --git a/vendor/yunion.io/x/cloudmux/pkg/cloudprovider/resources.go b/vendor/yunion.io/x/cloudmux/pkg/cloudprovider/resources.go index 27c7923dee..9cb7c3272f 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/cloudprovider/resources.go +++ b/vendor/yunion.io/x/cloudmux/pkg/cloudprovider/resources.go @@ -1571,19 +1571,63 @@ type ICloudKafka interface { Delete() error } +type AppBackupConfig struct { + Enabled bool + FrequencyInterval int + FrequencyUnit string + RetentionPeriodInDays int +} + type ICloudApp interface { IVirtualResource GetEnvironments() ([]ICloudAppEnvironment, error) GetTechStack() string - GetType() string - GetKind() string GetOsType() TOsType + GetIpAddress() string + GetHostname() string + GetServerFarm() string + GetBackups() ([]IAppBackup, error) + GetPublicNetworkAccess() string + GetNetworkId() string + GetHybirdConnections() ([]IAppHybirdConnection, error) + GetCertificates() ([]IAppCertificate, error) + GetBackupConfig() AppBackupConfig + GetDomains() ([]IAppDomain, error) +} + +type IAppDomain interface { + GetGlobalId() string + GetName() string + GetStatus() string + GetSslState() string +} + +type IAppCertificate interface { + GetGlobalId() string + GetName() string + GetSubjectName() string + GetIssuer() string + GetIssueDate() time.Time + GetThumbprint() string + GetExpireTime() time.Time +} + +type IAppHybirdConnection interface { + GetGlobalId() string + GetName() string + GetHostname() string + GetNamespace() string + GetPort() int +} + +type IAppBackup interface { + GetGlobalId() string + GetName() string + GetType() string } type ICloudAppEnvironment interface { IVirtualResource - GetInstanceType() (string, error) - GetInstanceNumber() (int, error) } type ICloudDBInstanceSku interface { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/app_service_plan.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/app_service_plan.go deleted file mode 100644 index 69a3e7f016..0000000000 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/app_service_plan.go +++ /dev/null @@ -1,197 +0,0 @@ -// 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 azure - -import ( - "fmt" - "net/url" - - "yunion.io/x/pkg/errors" -) - -type SAppServicePlan struct { - AzureTags - region *SRegion - - Properties SAppServicePlanProperties - ID string - Kind string - Location string - Name string - Type string - Sku SSkuDescription -} - -type SAppServicePlanProperties struct { - FreeOfferExpirationTime string - GeoRegion string - HostingEnvironmentProfile SHostingEnvironmentProfile - HyperV bool - IsSpot bool - MaximumElasticWorkerCount int - MaximumNumberOfWorkers int - NumberOfSites int - PerSiteScaling bool - // 应用服务环境的预配状态 - ProvisioningState string - Reserved bool - ResourceGroup string - SpotExpirationTime string - // Creating Pending Ready - Status string - Subscription string - TargetWorkerCount int - TargetWorkerSizeId int - WorkerTierName string -} - -type SHostingEnvironmentProfile struct { - ID string - Name string - Type string -} - -type SSkuDescription struct { - Capabilities []SCapability - Capacity int - Family string - locations []string - Name string - Size string - SkuCapacity SSkuCapacity - Tier string -} - -type SCapability struct { - Name string - Reason string - Value string -} - -type SSkuCapacity struct { - Default int - Maximum int - Minimum int - ScaleType string -} - -func (r *SRegion) GetAppServicePlanWithCache(id string) (*SAppServicePlan, error) { - if r.appServicePlans == nil { - plans, err := r.GetAppServicePlans() - if err != nil { - return nil, err - } - appServicePlans := make(map[string]*SAppServicePlan, len(plans)) - for i := range plans { - appServicePlans[plans[i].ID] = &plans[i] - } - r.appServicePlans = appServicePlans - } - if ret, ok := r.appServicePlans[id]; ok { - return ret, nil - } - return r.GetAppServicePlan(id) -} - -func (r *SRegion) GetAppServicePlans() ([]SAppServicePlan, error) { - result := []SAppServicePlan{} - resource := "Microsoft.Web/serverfarms" - err := r.list(resource, url.Values{"api-version": []string{"2019-08-01"}}, &result) - if err != nil { - return nil, err - } - for i := range result { - result[i].region = r - } - return result, nil -} - -func (r *SRegion) GetAppServicePlan(planId string) (*SAppServicePlan, error) { - asp := &SAppServicePlan{region: r} - params := url.Values{"api-version": []string{"2019-08-01"}} - return asp, r.get(planId, params, asp) -} - -type SServerFarmSku struct { - ResourceType string - Sku SSkuSpec - Capacity SSkuCapacity -} - -type SSkuSpec struct { - Name string - Tier string -} - -func (asp *SAppServicePlan) GetSkus() ([]SServerFarmSku, error) { - result := []SServerFarmSku{} - resource := fmt.Sprintf("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/serverfarms/%s/skus", asp.region.client._subscriptionId(), asp.Properties.ResourceGroup, asp.Name) - err := asp.region.client.list(resource, url.Values{"api-version": []string{"2019-08-01"}}, &result) - if err != nil { - return nil, err - } - return result, nil -} - -type SAppServicePlanVnet struct { - Id string - Name string - Properties SASPVnetProperties -} - -type SASPVnetProperties struct { - VnetResourceId string -} - -func (asp *SAppServicePlan) GetNetworks() ([]SNetwork, error) { - vnets, err := asp.GetVnets() - if err != nil { - return nil, errors.Wrap(err, "unable to get Vnets") - } - networks := make([]SNetwork, 0, len(vnets)) - for i := range vnets { - network, err := asp.region.GetNetwork(vnets[i].Properties.VnetResourceId) - if err != nil { - return nil, errors.Wrap(err, "unable to get Network") - } - networks = append(networks, *network) - } - return networks, nil -} - -func (asp *SAppServicePlan) GetVnets() ([]SAppServicePlanVnet, error) { - result := []SAppServicePlanVnet{} - resource := fmt.Sprintf("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/serverfarms/%s/virtualNetworkConnections", asp.region.client._subscriptionId(), asp.Properties.ResourceGroup, asp.Name) - err := asp.region.client.list(resource, url.Values{"api-version": []string{"2019-08-01"}}, &result) - if err != nil { - return nil, err - } - return result, nil -} - -type SSkuInfos struct { - ResourceType string - Skus []SResourceSku -} - -func (r *SRegion) GetAppServiceSkus() ([]SSkuInfos, error) { - result := []SSkuInfos{} - resource := "Microsoft.Web/skus" - err := r.client.list(resource, url.Values{"api-version": []string{"2019-08-01"}}, &result) - if err != nil { - return nil, err - } - return result, err -} diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/azure.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/azure.go index cdec020ed0..c41c7c2243 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/azure.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/azure.go @@ -81,8 +81,6 @@ type SAzureClient struct { tokenMap map[string]*Token httpClient *http.Client - ressourceGroups []SResourceGroup - regions []SRegion iBuckets []cloudprovider.ICloudBucket @@ -153,10 +151,6 @@ func NewAzureClient(cfg *AzureClientConfig) (*SAzureClient, error) { for i := range client.regions { client.regions[i].client = &client } - client.ressourceGroups, err = client.ListResourceGroups() - if err != nil { - return nil, errors.Wrapf(err, "ListResourceGroups") - } return &client, nil } @@ -807,9 +801,16 @@ func _jsonRequest(client *autorest.Client, method, domain, path string, body jso } func (self *SAzureClient) ListRegions() ([]SRegion, error) { + resp, err := self.list_v2("locations", "2014-02-26", nil) + if err != nil { + return nil, err + } regions := []SRegion{} - err := self.list("locations", url.Values{}, ®ions) - return regions, err + err = resp.Unmarshal(®ions, "value") + if err != nil { + return nil, err + } + return regions, nil } func (self *SAzureClient) GetRegions() []SRegion { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/azure_v2.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/azure_v2.go index f32ef67dcf..93204e088f 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/azure_v2.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/azure_v2.go @@ -132,7 +132,58 @@ func (self *SAzureClient) list_v2(resource, apiVersion string, params url.Values return self._list_v2(SERVICE_MANAGEMENT, resource, apiVersion, params) } +func (self *SAzureClient) post_v2(resource, apiVersion string, body map[string]interface{}) (jsonutils.JSONObject, error) { + return self._post_v2(SERVICE_MANAGEMENT, resource, apiVersion, body) +} + func (self *SAzureClient) _list_v2(service string, resource, apiVersion string, params url.Values) (jsonutils.JSONObject, error) { + return self._request_v2(service, httputils.GET, resource, apiVersion, params, nil) +} + +func (self *SAzureClient) _post_v2(service string, resource, apiVersion string, body map[string]interface{}) (jsonutils.JSONObject, error) { + return self._request_v2(service, httputils.POST, resource, apiVersion, nil, body) +} + +func (self *SAzureClient) _request_v2(service string, method httputils.THttpMethod, resource, apiVersion string, params url.Values, body map[string]interface{}) (jsonutils.JSONObject, error) { + value := []jsonutils.JSONObject{} + for { + resp, err := self.__request_v2(service, method, resource, apiVersion, params, body) + if err != nil { + return nil, err + } + if !resp.Contains("value") { + return resp, nil + } + part := struct { + Value []jsonutils.JSONObject + NextLink string + }{} + err = resp.Unmarshal(&part) + if err != nil { + return nil, errors.Wrapf(err, "resp.Unmarshal") + } + value = append(value, part.Value...) + if len(part.Value) == 0 || len(part.NextLink) == 0 { + break + } + link, err := url.Parse(part.NextLink) + if err != nil { + return nil, errors.Wrapf(err, "url.Parse(%s)", part.NextLink) + } + token := "" + for _, key := range []string{"$skipToken", "$skiptoken"} { + _token := link.Query().Get(key) + if len(_token) > 0 { + token = _token + } + params.Del(key) + } + params.Set("$skipToken", token) + } + return jsonutils.Marshal(map[string]interface{}{"value": value}), nil +} + +func (self *SAzureClient) __request_v2(service string, method httputils.THttpMethod, resource, apiVersion string, params url.Values, body map[string]interface{}) (jsonutils.JSONObject, error) { if params == nil { params = url.Values{} } @@ -146,10 +197,10 @@ func (self *SAzureClient) _list_v2(service string, resource, apiVersion string, switch resource { case "subscriptions": case "locations", "resourcegroups", "resources": - url = fmt.Sprintf("%s/subscriptions/%s/%s", strings.TrimSuffix(domain, "/"), self.subscriptionId, resource) + url = fmt.Sprintf("%s/subscriptions/%s/%s", strings.TrimSuffix(domain, "/"), self._subscriptionId(), resource) default: if !strings.HasPrefix(resource, "/") { - url = fmt.Sprintf("%s/subscriptions/%s/providers/%s", strings.TrimSuffix(domain, "/"), self.subscriptionId, resource) + url = fmt.Sprintf("%s/subscriptions/%s/providers/%s", strings.TrimSuffix(domain, "/"), self._subscriptionId(), resource) } } } @@ -161,21 +212,11 @@ func (self *SAzureClient) _list_v2(service string, resource, apiVersion string, } url += fmt.Sprintf("?%s", params.Encode()) } - _, resp, err := httputils.JSONRequest(self, self.ctx, httputils.GET, url, nil, nil, self.debug) - return resp, err -} - -func (self *SAzureClient) post_v2(resource, apiVersion string, body map[string]interface{}) (jsonutils.JSONObject, error) { - return self._post_v2("", resource, apiVersion, body) -} - -func (self *SAzureClient) _post_v2(service string, resource, apiVersion string, body map[string]interface{}) (jsonutils.JSONObject, error) { - domain := azServices[service][self.envName] - url := fmt.Sprintf("%s/%s", domain, resource) - if len(apiVersion) > 0 { - url += fmt.Sprintf("?api-version=%s", apiVersion) + var input jsonutils.JSONObject = nil + if body != nil { + input = jsonutils.Marshal(body) } - _, resp, err := httputils.JSONRequest(self, self.ctx, httputils.POST, url, nil, jsonutils.Marshal(body), self.debug) + _, resp, err := httputils.JSONRequest(self, self.ctx, method, url, nil, input, self.debug) return resp, err } diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/loadbalancercert.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/loadbalancercert.go index 91fdfafe9c..f60b6c975c 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/loadbalancercert.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/loadbalancercert.go @@ -139,7 +139,7 @@ func (self *SLoadbalancerCert) GetPrivateKey() string { func (self *SRegion) GetLoadbalancerCertificates() ([]SLoadbalancerCert, error) { params := url.Values{} - resp, err := self.client.list_v2("Microsoft.Network/applicationGateways", "2023-09-01", params) + resp, err := self.list_resources("Microsoft.Network/applicationGateways", "2023-09-01", params) if err != nil { return nil, err } diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/region.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/region.go index 29486c6b42..3c4518566e 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/region.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/region.go @@ -44,8 +44,7 @@ type SRegion struct { multicloud.SRegion client *SAzureClient - storageCache *SStoragecache - appServicePlans map[string]*SAppServicePlan + storageCache *SStoragecache ID string Name string @@ -650,7 +649,7 @@ func (self *SRegion) list(resource string, params url.Values, retVal interface{} return jsonutils.Update(retVal, ret) } -func (self *SRegion) list_v2(resource string, apiVersion string, params url.Values) (jsonutils.JSONObject, error) { +func (self *SRegion) list_resources(resource string, apiVersion string, params url.Values) (jsonutils.JSONObject, error) { if gotypes.IsNil(params) { params = url.Values{} } @@ -659,6 +658,17 @@ func (self *SRegion) list_v2(resource string, apiVersion string, params url.Valu return self.client.list_v2("resources", apiVersion, params) } +func (self *SRegion) list_v2(resource string, apiVersion string, params url.Values) (jsonutils.JSONObject, error) { + if gotypes.IsNil(params) { + params = url.Values{} + } + return self.client.list_v2(resource, apiVersion, params) +} + +func (self *SRegion) post_v2(resource string, apiVersion string, body map[string]interface{}) (jsonutils.JSONObject, error) { + return self.client.post_v2(resource, apiVersion, body) +} + func (self *SRegion) show(resource string, apiVersion string) (jsonutils.JSONObject, error) { return self.client.list_v2(resource, apiVersion, nil) } diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/subscription.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/subscription.go index a7fd5ea286..cb60bbcbc1 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/subscription.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/subscription.go @@ -15,15 +15,13 @@ package azure import ( - "net/url" - api "yunion.io/x/cloudmux/pkg/apis/compute" ) type SSubscription struct { - SubscriptionId string `json:"subscriptionId"` + SubscriptionId string State string - DisplayName string `json:"displayName"` + DisplayName string } func (self *SSubscription) GetHealthStatus() string { @@ -34,7 +32,14 @@ func (self *SSubscription) GetHealthStatus() string { } func (self *SAzureClient) ListSubscriptions() ([]SSubscription, error) { + resp, err := self.list_v2("subscriptions", "2014-02-26", nil) + if err != nil { + return nil, err + } result := []SSubscription{} - err := self.list("subscriptions", url.Values{}, &result) - return result, err + err = resp.Unmarshal(&result, "value") + if err != nil { + return nil, err + } + return result, nil } diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app.go index 61470a8437..51784ee916 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app.go @@ -16,12 +16,13 @@ package azure import ( "fmt" - "net/url" "strings" "yunion.io/x/log" "yunion.io/x/pkg/errors" + "yunion.io/x/pkg/utils" + "yunion.io/x/cloudmux/pkg/apis" "yunion.io/x/cloudmux/pkg/cloudprovider" "yunion.io/x/cloudmux/pkg/multicloud" ) @@ -29,56 +30,58 @@ import ( type SAppSite struct { multicloud.SResourceBase AzureTags - region *SRegion - appServicePlan *SAppServicePlan + region *SRegion - Properties SAppSiteProperties + Properties *SAppSiteProperties Id string Name string Kind string Location string Type string + stack string +} - stack *string +type HostNameSslState struct { + Name string + SslState string + Status string +} + +func (self *HostNameSslState) GetGlobalId() string { + return self.Name +} + +func (self *HostNameSslState) GetName() string { + return self.Name +} + +func (self *HostNameSslState) GetStatus() string { + return self.Status +} + +func (self *HostNameSslState) GetSslState() string { + return self.SslState } type SAppSiteProperties struct { - AvailabilityState string - DefaultHostName string - Enabled bool - EnabledHostNames []string - HostNameSslStates []SHostNameSslState - HostNames []string - HttpsOnly bool - OutboundIpAddresses string - ResourceGroup string - ServerFarmId string - SiteConfig SSiteConfig - State string -} - -type SSiteConfig struct { - // TODO -} - -type SHostNameSslState struct { - HostType string - Name string - SslState string - Thumbprint string - ToUpdate bool - VirtualIP string + DefaultHostName string + InboundIpAddress string + ServerFarmId string + PublicNetworkAccess string + VirtualNetworkSubnetId string + HostNames []string + HostNameSslStates []HostNameSslState } func (r *SRegion) GetAppSites() ([]SAppSite, error) { - result := []SAppSite{} - resource := "Microsoft.Web/sites" - err := r.list(resource, url.Values{"api-version": []string{"2019-08-01"}}, &result) + resp, err := r.list_resources("Microsoft.Web/sites", "2019-08-01", nil) if err != nil { return nil, err } - for i := range result { - result[i].region = r + result := []SAppSite{} + err = resp.Unmarshal(&result, "value") + if err != nil { + return nil, err } return result, nil } @@ -90,9 +93,8 @@ func (r *SRegion) GetICloudApps() ([]cloudprovider.ICloudApp, error) { } apps := make([]cloudprovider.ICloudApp, 0, len(ass)) for i := range ass { - apps = append(apps, &SApp{ - SAppSite: ass[i], - }) + ass[i].region = r + apps = append(apps, &ass[i]) } return apps, nil } @@ -102,103 +104,130 @@ func (r *SRegion) GetICloudAppById(id string) (cloudprovider.ICloudApp, error) { if err != nil { return nil, err } - return &SApp{ - SAppSite: *as, - }, nil -} - -func (as *SAppSite) GetSlots() ([]SAppSite, error) { - result := []SAppSite{} - resource := fmt.Sprintf("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/sites/%s/slots", as.region.client.subscriptionId, as.Properties.ResourceGroup, as.Name) - err := as.region.list(resource, url.Values{"api-version": []string{"2019-08-01"}}, &result) - if err != nil { - return nil, err - } - return result, nil + return as, nil } func (r *SRegion) GetAppSite(siteId string) (*SAppSite, error) { - as := &SAppSite{region: r} - params := url.Values{"api-version": []string{"2019-08-01"}} - return as, r.get(siteId, params, as) -} - -func (as *SAppSite) GetAppServicePlan() (*SAppServicePlan, error) { - if as.appServicePlan != nil { - return as.appServicePlan, nil - } - plan, err := as.region.GetAppServicePlanWithCache(as.Properties.ServerFarmId) - if err != nil { - return nil, errors.Wrap(err, "unable to get AppServicePlan") - } - as.appServicePlan = plan - return plan, nil -} - -type SDeployment struct { - ID string - Name string - Kind string - Type string - Properties SDeploymentProperties -} - -type SDeploymentProperties struct { - Active bool - Author string - AuthorEmail string - Deployer string - Details string - EndTime string - Message string - StartTime string - Status string -} - -func (as *SAppSite) GetDeployments() ([]SDeployment, error) { - result := []SDeployment{} - resource := fmt.Sprintf("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/sites/%s/deployments", as.region.client._subscriptionId(), as.Properties.ResourceGroup, as.Name) - err := as.region.client.list(resource, url.Values{"api-version": []string{"2019-08-01"}}, &result) + resp, err := r.show(siteId, "2023-12-01") if err != nil { return nil, err } - return result, nil -} - -type SStringDictionary struct { - Id string - Kind string - Name string - Type string - Properties map[string]string + as := &SAppSite{region: r} + err = resp.Unmarshal(as) + if err != nil { + return nil, err + } + return as, nil } func (as *SAppSite) GetStack() (string, error) { - if as.stack != nil { - return *as.stack, nil + if len(as.stack) > 0 { + return as.stack, nil } - // result := SStringDictionary{} - resource := fmt.Sprintf("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/sites/%s/config/metadata", as.region.client.subscriptionId, as.Properties.ResourceGroup, as.Name) - - params := url.Values{} - params.Set("api-version", "2019-08-01") - path := resource + "/list" - response, err := as.region.client.jsonRequest("POST", path, nil, params, true) + res := fmt.Sprintf("%s/config/metadata", as.Id) + resp, err := as.region.post_v2(res, "2023-12-01", nil) if err != nil { - return "", err + return "", nil } - stack, err := response.GetString("properties", "CURRENT_STACK") + ret := struct { + Properties struct { + CurrentStack string + } + }{} + err = resp.Unmarshal(&ret) if err != nil { - return "", errors.Wrapf(err, "unable to parse response correctly, response: %s", response) + return "", nil } - as.stack = &stack - return stack, nil + as.stack = ret.Properties.CurrentStack + return ret.Properties.CurrentStack, nil } func (as *SAppSite) GetId() string { return as.Id } +func (as *SAppSite) GetProperties() (*SAppSiteProperties, error) { + if as.Properties != nil { + return as.Properties, nil + } + app, err := as.region.GetAppSite(as.Id) + if err != nil { + return nil, err + } + as.Properties = app.Properties + return as.Properties, nil +} + +func (as *SAppSite) GetIpAddress() string { + properties, err := as.GetProperties() + if err != nil { + return "" + } + return properties.InboundIpAddress +} + +func (as *SAppSite) GetHostname() string { + properties, err := as.GetProperties() + if err != nil { + return "" + } + return properties.DefaultHostName +} + +func (as *SAppSite) GetPublicNetworkAccess() string { + properties, err := as.GetProperties() + if err != nil { + return "" + } + return properties.PublicNetworkAccess +} + +func (as *SAppSite) GetServerFarm() string { + properties, err := as.GetProperties() + if err != nil { + return "" + } + if len(properties.ServerFarmId) == 0 { + return "" + } + farm, err := as.region.GetServicePlan(properties.ServerFarmId) + if err != nil { + return "" + } + return fmt.Sprintf("%s(%s:%d)", farm.Name, farm.Sku.Name, farm.Sku.Capacity) +} + +func (as *SAppSite) GetBackups() ([]cloudprovider.IAppBackup, error) { + backups, err := as.region.GetAppBackups(as.Id) + if err != nil { + return nil, err + } + ret := []cloudprovider.IAppBackup{} + for i := range backups { + backups[i].Type = "manual" + ret = append(ret, &backups[i]) + } + snapshots, err := as.region.GetAppSnapshots(as.Id) + if err != nil { + return nil, err + } + + for i := range snapshots { + snapshots[i].Type = "auto" + ret = append(ret, &snapshots[i]) + } + + return ret, nil +} + +func (as *SAppSite) GetNetworkId() string { + properties, err := as.GetProperties() + if err != nil { + return "" + } + return strings.ToLower(properties.VirtualNetworkSubnetId) +} + func (as *SAppSite) GetName() string { return as.Name } @@ -212,51 +241,7 @@ func (as *SAppSite) GetStatus() string { } func (as *SAppSite) GetProjectId() string { - return strings.ToLower(as.Properties.ResourceGroup) -} - -type SApp struct { - SAppSite -} - -type SAppEnvironment struct { - multicloud.SResourceBase - AzureTags - SAppSite -} - -func (ae *SAppEnvironment) GetInstanceType() (string, error) { - asp, err := ae.SAppSite.GetAppServicePlan() - if err != nil { - return "", err - } - return asp.Sku.Name, nil -} - -func (ae *SAppEnvironment) GetInstanceNumber() (int, error) { - asp, err := ae.SAppSite.GetAppServicePlan() - if err != nil { - return 0, err - } - return asp.Sku.Capacity, nil -} - -func (a *SApp) GetEnvironments() ([]cloudprovider.ICloudAppEnvironment, error) { - sites, err := a.SAppSite.GetSlots() - if err != nil { - return nil, err - } - aes := make([]cloudprovider.ICloudAppEnvironment, 0, len(sites)+1) - aes = append(aes, &SAppEnvironment{ - SAppSite: a.SAppSite, - }) - for i := range sites { - sites[i].region = a.region - aes = append(aes, &SAppEnvironment{ - SAppSite: sites[i], - }) - } - return aes, nil + return getResourceGroup(as.Id) } var techStacks = map[string]string{ @@ -271,8 +256,8 @@ var techStacks = map[string]string{ "javacontainers": "Jave Containers", } -func (a *SApp) GetTechStack() string { - if strings.Contains(a.SAppSite.Kind, "container") { +func (a *SAppSite) GetTechStack() string { + if strings.Contains(a.Kind, "container") { return "Docker container" } stack, err := a.GetStack() @@ -285,22 +270,14 @@ func (a *SApp) GetTechStack() string { return stack } -func (a *SApp) GetType() string { - return "web" -} - -func (a *SApp) GetKind() string { - return a.Kind -} - -func (a *SApp) GetOsType() cloudprovider.TOsType { - if strings.Contains(a.Kind, "linux") { - return cloudprovider.OsTypeLinux +func (a *SAppSite) GetOsType() cloudprovider.TOsType { + if strings.Contains(strings.ToLower(a.GetTechStack()), "net") { + return cloudprovider.OsTypeWindows } - return cloudprovider.OsTypeWindows + return cloudprovider.OsTypeLinux } -func (self *SApp) SetTags(tags map[string]string, replace bool) error { +func (self *SAppSite) SetTags(tags map[string]string, replace bool) error { if !replace { for k, v := range self.Tags { if _, ok := tags[k]; !ok { @@ -314,3 +291,45 @@ func (self *SApp) SetTags(tags map[string]string, replace bool) error { } return nil } + +func (self *SAppSite) GetDomains() ([]cloudprovider.IAppDomain, error) { + properties, err := self.GetProperties() + if err != nil { + return nil, err + } + ret := []cloudprovider.IAppDomain{} + for i := range properties.HostNameSslStates { + domain := properties.HostNameSslStates[i] + if !utils.IsInStringArray(domain.Name, properties.HostNames) { + continue + } + domain.Status = "no_bind" + if domain.Name == properties.DefaultHostName { + domain.Status = apis.STATUS_AVAILABLE + } + ret = append(ret, &domain) + } + return ret, nil +} + +type SAppServicePlan struct { + Id string + Name string + Sku struct { + Name string + Capacity int + } +} + +func (self *SRegion) GetServicePlan(farmId string) (*SAppServicePlan, error) { + resp, err := self.show(farmId, "2023-12-01") + if err != nil { + return nil, err + } + ret := &SAppServicePlan{} + err = resp.Unmarshal(ret) + if err != nil { + return nil, err + } + return ret, nil +} diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app_backup.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app_backup.go new file mode 100644 index 0000000000..921a1a8852 --- /dev/null +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app_backup.go @@ -0,0 +1,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 azure + +import ( + "fmt" + "strings" + + "yunion.io/x/cloudmux/pkg/cloudprovider" +) + +type SAppBackup struct { + Id string + Name string + Type string +} + +func (self *SAppBackup) GetGlobalId() string { + return strings.ToLower(self.Id) +} + +func (self *SAppBackup) GetName() string { + return self.Name +} + +func (self *SAppBackup) GetType() string { + return self.Type +} + +func (self *SRegion) GetAppSnapshots(appId string) ([]SAppBackup, error) { + res := fmt.Sprintf("%s/snapshots", appId) + resp, err := self.list_v2(res, "2023-12-01", nil) + if err != nil { + return nil, err + } + ret := []SAppBackup{} + err = resp.Unmarshal(&ret, "value") + if err != nil { + return nil, err + } + return ret, nil +} + +func (self *SRegion) GetAppBackups(appId string) ([]SAppBackup, error) { + res := fmt.Sprintf("%s/backups", appId) + resp, err := self.list_v2(res, "2023-12-01", nil) + if err != nil { + return nil, err + } + ret := []SAppBackup{} + err = resp.Unmarshal(&ret, "value") + if err != nil { + return nil, err + } + return ret, nil +} + +type SAppBackupConfig struct { + Id string + Name string + Properties struct { + Enabled bool + BackupSchedule struct { + FrequencyInterval int + FrequencyUnit string + RetentionPeriodInDays int + } + } +} + +func (self *SRegion) GetAppBackupConfig(appId string) (*SAppBackupConfig, error) { + res := fmt.Sprintf("%s/config/backup/list", appId) + resp, err := self.post_v2(res, "2023-12-01", nil) + if err != nil { + return nil, err + } + ret := &SAppBackupConfig{} + err = resp.Unmarshal(ret) + if err != nil { + return nil, err + } + return ret, nil +} + +func (self *SAppSite) GetBackupConfig() cloudprovider.AppBackupConfig { + ret := cloudprovider.AppBackupConfig{} + opts, err := self.region.GetAppBackupConfig(self.Id) + if err != nil { + return ret + } + ret.Enabled = opts.Properties.Enabled + ret.FrequencyInterval = opts.Properties.BackupSchedule.FrequencyInterval + ret.FrequencyUnit = opts.Properties.BackupSchedule.FrequencyUnit + ret.RetentionPeriodInDays = opts.Properties.BackupSchedule.RetentionPeriodInDays + return ret +} diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app_certificate.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app_certificate.go new file mode 100644 index 0000000000..f2a9d6602b --- /dev/null +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app_certificate.go @@ -0,0 +1,97 @@ +// 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 azure + +import ( + "fmt" + "net/url" + "strings" + "time" + + "yunion.io/x/cloudmux/pkg/cloudprovider" +) + +type SAppCertificate struct { + Id string + Name string + Type string + Properties struct { + SubjectName string + Issuer string + IssueDate time.Time + Thumbprint string + ExpirationDate time.Time + } +} + +func (self *SAppCertificate) GetGlobalId() string { + return strings.ToLower(self.Id) +} + +func (self *SAppCertificate) GetName() string { + return self.Name +} + +func (self *SAppCertificate) GetSubjectName() string { + return self.Properties.SubjectName +} + +func (self *SAppCertificate) GetIssuer() string { + return self.Properties.Issuer +} + +func (self *SAppCertificate) GetIssueDate() time.Time { + return self.Properties.IssueDate +} + +func (self *SAppCertificate) GetThumbprint() string { + return self.Properties.Thumbprint +} + +func (self *SAppCertificate) GetExpireTime() time.Time { + return self.Properties.ExpirationDate +} + +func (self *SRegion) GetAppCertificates(farmId string) ([]SAppCertificate, error) { + res := fmt.Sprintf("Microsoft.Web/certificates") + params := url.Values{} + params.Set("$filter", fmt.Sprintf("ServerFarmId eq '%s'", farmId)) + resp, err := self.list_v2(res, "2023-12-01", params) + if err != nil { + return nil, err + } + ret := []SAppCertificate{} + err = resp.Unmarshal(&ret, "value") + if err != nil { + return nil, err + } + return ret, nil +} + +func (self *SAppSite) GetCertificates() ([]cloudprovider.IAppCertificate, error) { + properties, err := self.GetProperties() + if err != nil { + return nil, err + } + certs, err := self.region.GetAppCertificates(properties.ServerFarmId) + if err != nil { + return nil, err + } + ret := []cloudprovider.IAppCertificate{} + for i := range certs { + ret = append(ret, &certs[i]) + } + return ret, nil +} diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app_environment.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app_environment.go new file mode 100644 index 0000000000..97c7d1c67b --- /dev/null +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app_environment.go @@ -0,0 +1,79 @@ +// 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 azure + +import ( + "fmt" + "strings" + + "yunion.io/x/cloudmux/pkg/cloudprovider" + "yunion.io/x/cloudmux/pkg/multicloud" +) + +type SAppEnvironment struct { + multicloud.SResourceBase + AzureTags + region *SRegion + + Id string + Name string +} + +func (ae *SAppEnvironment) GetId() string { + return ae.Id +} + +func (ae *SAppEnvironment) GetGlobalId() string { + return strings.ToLower(ae.Id) +} + +func (ae *SAppEnvironment) GetName() string { + return ae.Name +} + +func (ae *SAppEnvironment) GetProjectId() string { + return getResourceGroup(ae.Id) +} + +func (ae *SAppEnvironment) GetStatus() string { + return "ready" +} + +func (a *SAppSite) GetEnvironments() ([]cloudprovider.ICloudAppEnvironment, error) { + sites, err := a.region.GetSlots(a.Id) + if err != nil { + return nil, err + } + aes := []cloudprovider.ICloudAppEnvironment{} + for i := range sites { + sites[i].region = a.region + aes = append(aes, &sites[i]) + } + return aes, nil +} + +func (self *SRegion) GetSlots(appId string) ([]SAppEnvironment, error) { + resource := fmt.Sprintf("%s/slots", appId) + resp, err := self.list_v2(resource, "2023-12-01", nil) + if err != nil { + return nil, err + } + ret := []SAppEnvironment{} + err = resp.Unmarshal(&ret, "value") + if err != nil { + return nil, err + } + return ret, nil +} diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app_hybrid_connection.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app_hybrid_connection.go new file mode 100644 index 0000000000..aed0bcb04d --- /dev/null +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/web_app_hybrid_connection.go @@ -0,0 +1,80 @@ +// 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 azure + +import ( + "fmt" + "strings" + + "yunion.io/x/cloudmux/pkg/cloudprovider" +) + +type SAppHybirdConnection struct { + Id string + Name string + Type string + Properties struct { + ServiceBusNamespace string + RelayName string + Hostname string + Port int + } +} + +func (self *SAppHybirdConnection) GetGlobalId() string { + return strings.ToLower(self.Id) +} + +func (self *SAppHybirdConnection) GetName() string { + return self.Name +} + +func (self *SAppHybirdConnection) GetHostname() string { + return self.Properties.Hostname +} + +func (self *SAppHybirdConnection) GetNamespace() string { + return self.Properties.ServiceBusNamespace +} + +func (self *SAppHybirdConnection) GetPort() int { + return self.Properties.Port +} + +func (self *SRegion) GetAppHybirConnections(appId string) ([]SAppHybirdConnection, error) { + res := fmt.Sprintf("%s/hybridConnectionRelays", appId) + resp, err := self.list_v2(res, "2023-12-01", nil) + if err != nil { + return nil, err + } + ret := []SAppHybirdConnection{} + err = resp.Unmarshal(&ret, "value") + if err != nil { + return nil, err + } + return ret, nil +} + +func (self *SAppSite) GetHybirdConnections() ([]cloudprovider.IAppHybirdConnection, error) { + connections, err := self.region.GetAppHybirConnections(self.Id) + if err != nil { + return nil, err + } + ret := []cloudprovider.IAppHybirdConnection{} + for i := range connections { + ret = append(ret, &connections[i]) + } + return ret, nil +} diff --git a/vendor/yunion.io/x/pkg/util/imagetools/imagetools.go b/vendor/yunion.io/x/pkg/util/imagetools/imagetools.go index e5ae930fe2..97e6c5d79b 100644 --- a/vendor/yunion.io/x/pkg/util/imagetools/imagetools.go +++ b/vendor/yunion.io/x/pkg/util/imagetools/imagetools.go @@ -114,6 +114,8 @@ func normalizeOsDistribution(osDist string, imageName string) string { return "Amazon Linux" } else if strings.Contains(osDist, "kylin") { return "Kylin" + } else if strings.Contains(osDist, "uos") { + return "UOS" } else if strings.Contains(osDist, "windows") { for _, ver := range []string{"2003", "2008", "2012", "2016", "2019", "2022"} { if strings.Contains(osDist, ver) { @@ -154,6 +156,7 @@ var imageVersions = map[string][]string{ "Windows": {"XP", "7", "8", "Vista", "10", "11"}, "Kylin": {"V10"}, + "UOS": {"V20", "20 1050", "1050", "1060", "1070"}, } func normalizeOsVersion(imageName string, osDist string, osVersion string) string {