mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 16:13:56 +08:00
Compare commits
65 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4334ccf537 | ||
|
|
285c696e6d | ||
|
|
ce6e7542a5 | ||
|
|
5ec462bc8e | ||
|
|
4868674fee | ||
|
|
2e560c1f04 | ||
|
|
71b1244846 | ||
|
|
545f9eebf1 | ||
|
|
e6ce176233 | ||
|
|
f59d56e796 | ||
|
|
37e36f5a08 | ||
|
|
05abebeea5 | ||
|
|
747d70a747 | ||
|
|
ebf3692ba0 | ||
|
|
7dfe68322a | ||
|
|
59861adabc | ||
|
|
40b3e8e382 | ||
|
|
c81563b03d | ||
|
|
a18b34c365 | ||
|
|
f64267897e | ||
|
|
ad8d6e76b5 | ||
|
|
c266722c31 | ||
|
|
4d0cb2b150 | ||
|
|
2171de57ee | ||
|
|
021b4a1ae2 | ||
|
|
b108fe81d2 | ||
|
|
9f854385e5 | ||
|
|
b319be6d0a | ||
|
|
fa28094906 | ||
|
|
f797ec2fb9 | ||
|
|
5ca7179ce1 | ||
|
|
c2b81cf638 | ||
|
|
ddb7981922 | ||
|
|
8020d70bab | ||
|
|
d78c549b4a | ||
|
|
849a74c0a6 | ||
|
|
e016109d6e | ||
|
|
c67aa4991d | ||
|
|
f71b787abb | ||
|
|
780dea24d1 | ||
|
|
a8c65cbeed | ||
|
|
b41bd4066c | ||
|
|
c5a731daa9 | ||
|
|
3bc1381c36 | ||
|
|
ff880efe8c | ||
|
|
813a8c2021 | ||
|
|
4f9b8a29da | ||
|
|
db7621081a | ||
|
|
3032f7e26b | ||
|
|
44c0d0ce47 | ||
|
|
5eb4b549ba | ||
|
|
3b6662f7fa | ||
|
|
551ea72afb | ||
|
|
2c9378cc9a | ||
|
|
be3244d0b5 | ||
|
|
9c756c1cc9 | ||
|
|
fa47f50e32 | ||
|
|
40b3074acb | ||
|
|
035dcaa08b | ||
|
|
efd888ab45 | ||
|
|
3dd36fbc46 | ||
|
|
d3f1c3c202 | ||
|
|
0d301c554c | ||
|
|
19fc35afa5 | ||
|
|
ed7576f2ac |
@@ -35,7 +35,10 @@ type BaseEventListOptions struct {
|
||||
Action []string `help:"Log action"`
|
||||
|
||||
User string `help:"filter by operator user"`
|
||||
Project string `help:"filter by owner project"`
|
||||
Project string `help:"filter by operator user's project"`
|
||||
|
||||
OwnerProjectIds []string `help:"filter by owner project ids"`
|
||||
OwnerDomainIds []string `help:"filter by owner domain ids"`
|
||||
|
||||
PagingMarker string `help:"marker for pagination"`
|
||||
}
|
||||
@@ -107,6 +110,12 @@ func doEventList(man modulebase.ResourceManager, s *mcclient.ClientSession, args
|
||||
if len(args.Scope) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Scope), "scope")
|
||||
}
|
||||
if len(args.OwnerProjectIds) > 0 {
|
||||
params.Add(jsonutils.NewStringArray(args.OwnerProjectIds), "owner_project_ids")
|
||||
}
|
||||
if len(args.OwnerDomainIds) > 0 {
|
||||
params.Add(jsonutils.NewStringArray(args.OwnerDomainIds), "owner_domain_ids")
|
||||
}
|
||||
if len(args.PagingMarker) > 0 {
|
||||
params.Add(jsonutils.NewString(args.PagingMarker), "paging_marker")
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ type ImageOptionalOptions struct {
|
||||
Hypervisor []string `help:"Prefer hypervisor type" choices:"kvm|esxi|baremetal|container|openstack|ctyun"`
|
||||
DiskDriver string `help:"Perfer disk driver" choices:"virtio|scsi|pvscsi|ide|sata"`
|
||||
NetDriver string `help:"Preferred network driver" choices:"virtio|e1000|vmxnet3"`
|
||||
DisableUsbKbd bool `help:"Disable usb keyboard on this image(for hypervisor kvm)"`
|
||||
}
|
||||
|
||||
func addImageOptionalOptions(s *mcclient.ClientSession, params *jsonutils.JSONDict, args ImageOptionalOptions) error {
|
||||
@@ -131,6 +132,9 @@ func addImageOptionalOptions(s *mcclient.ClientSession, params *jsonutils.JSONDi
|
||||
if len(args.Hypervisor) > 0 {
|
||||
params.Add(jsonutils.NewString(strings.Join(args.Hypervisor, ",")), "properties", "hypervisor")
|
||||
}
|
||||
if args.DisableUsbKbd {
|
||||
params.Add(jsonutils.NewString("true"), "properties", "disable_usb_kbd")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1146,6 +1146,7 @@ func init() {
|
||||
ID string `help:"ID or name of VM"`
|
||||
DisableIsaSerial string `help:"disable isa serial device" choices:"true|false"`
|
||||
DisablePvpanic string `help:"disable pvpanic device" choices:"true|false"`
|
||||
DisableUsbKbd string `help:"disable usb kbd" choices:"true|false"`
|
||||
}
|
||||
|
||||
R(&ServerQemuParams{}, "server-set-qemu-params", "config qemu params", func(s *mcclient.ClientSession,
|
||||
@@ -1157,6 +1158,9 @@ func init() {
|
||||
if len(opts.DisablePvpanic) > 0 {
|
||||
params.Set("disable_pvpanic", jsonutils.NewString(opts.DisablePvpanic))
|
||||
}
|
||||
if len(opts.DisableUsbKbd) > 0 {
|
||||
params.Set("disable_usb_kbd", jsonutils.NewString(opts.DisableUsbKbd))
|
||||
}
|
||||
result, err := modules.Servers.PerformAction(s, opts.ID, "set-qemu-params", params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
6
go.mod
6
go.mod
@@ -128,11 +128,11 @@ require (
|
||||
k8s.io/cluster-bootstrap v0.17.3
|
||||
k8s.io/kubernetes v1.16.0
|
||||
yunion.io/x/executor v0.0.0-20200227030256-a18417815e74
|
||||
yunion.io/x/jsonutils v0.0.0-20200710080709-7ca71cdb9383
|
||||
yunion.io/x/jsonutils v0.0.0-20200814075449-927b118adbd8
|
||||
yunion.io/x/log v0.0.0-20200313080802-57a4ce5966b3
|
||||
yunion.io/x/pkg v0.0.0-20200713121502-18154120c49b
|
||||
yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
yunion.io/x/sqlchemy v0.0.0-20200702064124-195445bc4b11
|
||||
yunion.io/x/sqlchemy v0.0.0-20200814052348-164f1f20f8a6
|
||||
yunion.io/x/structarg v0.0.0-20200720093445-9f850fa222ce
|
||||
)
|
||||
|
||||
|
||||
14
go.sum
14
go.sum
@@ -1108,8 +1108,8 @@ vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj
|
||||
yunion.io/x/executor v0.0.0-20200227030256-a18417815e74 h1:A15C6VdVRWvmQ9pAJHrUs9yan5qKlYH7uaRxHg1kRbk=
|
||||
yunion.io/x/executor v0.0.0-20200227030256-a18417815e74/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
yunion.io/x/jsonutils v0.0.0-20200710080709-7ca71cdb9383 h1:XEhTD+FGjBjEIWwcY0Ez1lY3oTTzjUOcRgH/i4eFM5A=
|
||||
yunion.io/x/jsonutils v0.0.0-20200710080709-7ca71cdb9383/go.mod h1:3U5hspYn9apQHaXKY+fJ4Qgwjey32Kc+Mq+mUe9NamQ=
|
||||
yunion.io/x/jsonutils v0.0.0-20200814075449-927b118adbd8 h1:KQVw5EmohJCqBDMdZ3fAcOQNNMIYgVuNCNWNwg4EM3A=
|
||||
yunion.io/x/jsonutils v0.0.0-20200814075449-927b118adbd8/go.mod h1:p0nyMqGA/apTxxyLIU/o1k4V7Vujl2O6ey30L594sYE=
|
||||
yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b/go.mod h1:+gauLs73omeJAPlsXcevLsJLKixV+sR/E7WSYTSx1fE=
|
||||
yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d h1:59zrDL7Ft+hDukguJRmLr/Gdu/9V75x+yX99ovZwfaA=
|
||||
yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d/go.mod h1:LC6f/4FozL0iaAbnFt2eDX9jlsyo3WiOUPm03d7+U4U=
|
||||
@@ -1117,13 +1117,11 @@ yunion.io/x/log v0.0.0-20200313080802-57a4ce5966b3 h1:5Wc5hkB8PtMudmHuzCyok960Ru
|
||||
yunion.io/x/log v0.0.0-20200313080802-57a4ce5966b3/go.mod h1:LC6f/4FozL0iaAbnFt2eDX9jlsyo3WiOUPm03d7+U4U=
|
||||
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 v0.0.0-20200708071451-a663dc94e16b h1:wwPzH8iMRYjtaSM2pBN7nOqeZxR4XW5wdz2VE1KH/Ug=
|
||||
yunion.io/x/pkg v0.0.0-20200708071451-a663dc94e16b/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v0.0.0-20200713121502-18154120c49b h1:Ov/eKwwNeQje7SggkopExzcCW/GfaUouvXkcY6RUEcM=
|
||||
yunion.io/x/pkg v0.0.0-20200713121502-18154120c49b/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6 h1:UarEDTBGkgcgc+nc+PZ75uo9M9+jiOGd5P2B90TxDNw=
|
||||
yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
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 v0.0.0-20200702064124-195445bc4b11 h1:srrssomGJLh4OaDaY/1so+2FUBjZxdwQx/1pZ6403YU=
|
||||
yunion.io/x/sqlchemy v0.0.0-20200702064124-195445bc4b11/go.mod h1:FTdwPdGhMgh4E+UFXc9klI1Ok34fMuybTT+jLhOaIjI=
|
||||
yunion.io/x/sqlchemy v0.0.0-20200814052348-164f1f20f8a6 h1:k7E8Zjwzyk/lo1dDO0jtLbODwYRNv+w/zsUJrKWCXvo=
|
||||
yunion.io/x/sqlchemy v0.0.0-20200814052348-164f1f20f8a6/go.mod h1:FTdwPdGhMgh4E+UFXc9klI1Ok34fMuybTT+jLhOaIjI=
|
||||
yunion.io/x/structarg v0.0.0-20200720093445-9f850fa222ce h1:kU8xE7O5uZ1GSJVMZHoJ+jrNL7csUQHYGyAPW9QfNpE=
|
||||
yunion.io/x/structarg v0.0.0-20200720093445-9f850fa222ce/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=
|
||||
|
||||
@@ -57,7 +57,7 @@ type ProxySettingResourceInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
ProxySettingId string `json:"proxy_setting_id" "yunion:deprecated-by":"proxy_setting"`
|
||||
ProxySettingId string `json:"proxy_setting_id" yunion-deprecated-by:"proxy_setting"`
|
||||
}
|
||||
|
||||
type ProxySettingTestInput struct {
|
||||
|
||||
@@ -285,7 +285,7 @@ type ServerConfigs struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// alias for InstanceType
|
||||
Sku string `json:"sku" "yunion:deprecated-by":"instance_type"`
|
||||
Sku string `json:"sku" yunion-deprecated-by:"instance_type"`
|
||||
|
||||
// 虚拟机高可用(创建备机)
|
||||
// default: false
|
||||
@@ -359,7 +359,7 @@ type ServerCreateInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
KeypairId string `json:"keypair_id" "yunion:deprecated-by":"keypair"`
|
||||
KeypairId string `json:"keypair_id" yunion-deprecated-by:"keypair"`
|
||||
|
||||
// 秘钥对Id
|
||||
// required: false
|
||||
@@ -466,7 +466,8 @@ type ServerCreateInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
OsType string `json:"os_type"`
|
||||
|
||||
// swagger:ignore
|
||||
DisableUsbKbd bool `json:"disable_usb_kbd"`
|
||||
// swagger:ignore
|
||||
OsProfile jsonutils.JSONObject `json:"__os_profile__"`
|
||||
// swagger:ignore
|
||||
|
||||
@@ -42,7 +42,7 @@ type LoadbalancerAclResourceInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
AclId string `json:"acl_id" "yunion:deprecated-by":"acl"`
|
||||
AclId string `json:"acl_id" yunion-deprecated-by:"acl"`
|
||||
}
|
||||
|
||||
type LoadbalancerAclFilterListInput struct {
|
||||
|
||||
@@ -43,7 +43,7 @@ type LoadbalancerCertificateResourceInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
CertificateId string `json:"certificate_id" "yunion:deprecated-by":"certificate"`
|
||||
CertificateId string `json:"certificate_id" yunion-deprecated-by:"certificate"`
|
||||
}
|
||||
|
||||
type LoadbalancerCertificateFilterListInput struct {
|
||||
|
||||
@@ -66,7 +66,7 @@ type CloudenvResourceListInput struct {
|
||||
Providers []string `json:"providers"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
Provider []string `json:"provider" "yunion:deprecated-by":"providers"`
|
||||
Provider []string `json:"provider" yunion-deprecated-by:"providers"`
|
||||
|
||||
// 列出指定云平台品牌的资源,一般来说brand和provider相同,除了以上支持的provider之外,还支持以下band
|
||||
//
|
||||
@@ -77,7 +77,7 @@ type CloudenvResourceListInput struct {
|
||||
Brands []string `json:"brands"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
Brand []string `json:"brand" "yunion:deprecated-by":"brands"`
|
||||
Brand []string `json:"brand" yunion-deprecated-by:"brands"`
|
||||
|
||||
// 列出指定云环境的资源,支持云环境如下:
|
||||
//
|
||||
@@ -227,7 +227,7 @@ type CloudaccountListInput struct {
|
||||
// 代理
|
||||
ProxySetting string `json:"proxy_setting"`
|
||||
// swagger:ignore
|
||||
ProxySettingId string `json:"proxy_setting_id" "yunion:deprecated-by":"proxy_setting"`
|
||||
ProxySettingId string `json:"proxy_setting_id" yunion-deprecated-by:"proxy_setting"`
|
||||
}
|
||||
|
||||
type ProviderProject struct {
|
||||
|
||||
@@ -147,15 +147,15 @@ type CloudproviderResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
Manager string `json:"manager" "yunion:deprecated-by":"cloudprovider"`
|
||||
Manager string `json:"manager" yunion-deprecated-by:"cloudprovider"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
ManagerId string `json:"manager_id" "yunion:deprecated-by":"cloudprovider"`
|
||||
ManagerId string `json:"manager_id" yunion-deprecated-by:"cloudprovider"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
CloudproviderId string `json:"cloudprovider_id" "yunion:deprecated-by":"cloudprovider"`
|
||||
CloudproviderId string `json:"cloudprovider_id" yunion-deprecated-by:"cloudprovider"`
|
||||
}
|
||||
|
||||
type ManagedResourceListInput struct {
|
||||
@@ -169,15 +169,15 @@ type ManagedResourceListInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
CloudaccountId string `json:"cloudaccount_id" "yunion:deprecated-by":"cloudaccount"`
|
||||
CloudaccountId string `json:"cloudaccount_id" yunion-deprecated-by:"cloudaccount"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
Account string `json:"account" "yunion:deprecated-by":"cloudaccount"`
|
||||
Account string `json:"account" yunion-deprecated-by:"cloudaccount"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
AccountId string `json:"account_id" "yunion:deprecated-by":"cloudaccount"`
|
||||
AccountId string `json:"account_id" yunion-deprecated-by:"cloudaccount"`
|
||||
|
||||
// 过滤资源,是否为非OneCloud内置私有云管理的资源
|
||||
// default: false
|
||||
|
||||
@@ -172,7 +172,7 @@ type SDBInstanceRecoveryConfigInput struct {
|
||||
apis.Meta
|
||||
|
||||
// swagger:ignore
|
||||
DBInstancebackup string `json:"dbinstancebackup" "yunion:deprecated-by":"dbinstancebackup_id"`
|
||||
DBInstancebackup string `json:"dbinstancebackup" yunion-deprecated-by:"dbinstancebackup_id"`
|
||||
|
||||
// 备份Id
|
||||
//
|
||||
@@ -327,7 +327,7 @@ type DBInstanceResourceInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
DBInstanceId string `json:"dbinstance_id" "yunion:deprecated-by":"dbinstance"`
|
||||
DBInstanceId string `json:"dbinstance_id" yunion-deprecated-by:"dbinstance"`
|
||||
}
|
||||
|
||||
type DBInstanceFilterListInputBase struct {
|
||||
|
||||
@@ -88,7 +88,7 @@ type SnapshotPolicyResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter disk by snapshotpolicy_id
|
||||
SnapshotpolicyId string `json:"snapshotpolicy_id" "yunion:deprecated-by":"snapshotpolicy"`
|
||||
SnapshotpolicyId string `json:"snapshotpolicy_id" yunion-deprecated-by:"snapshotpolicy"`
|
||||
}
|
||||
|
||||
type SnapshotPolicyFilterListInput struct {
|
||||
@@ -113,7 +113,7 @@ type DiskListInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by disk type
|
||||
Type string `json:"type" "yunion:deprecated-by":"disk_type"`
|
||||
Type string `json:"type" yunion-deprecated-by:"disk_type"`
|
||||
// 过滤指定disk_type的磁盘列表,可能的值为:sys, data, swap. volume
|
||||
//
|
||||
// | disk_type值 | 说明 |
|
||||
@@ -137,13 +137,13 @@ type DiskListInput struct {
|
||||
Template string `json:"template"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
TemplateId string `json:"template_id" "yunion:deprecated-by":"template"`
|
||||
TemplateId string `json:"template_id" yunion-deprecated-by:"template"`
|
||||
|
||||
// 快照
|
||||
Snapshot string `json:"snapshot"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
SnapshotId string `json:"snapshot_id" "yunion:deprecated-by":"snapshot"`
|
||||
SnapshotId string `json:"snapshot_id" yunion-deprecated-by:"snapshot"`
|
||||
}
|
||||
|
||||
type DiskResourceInput struct {
|
||||
@@ -152,7 +152,7 @@ type DiskResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by disk_id
|
||||
DiskId string `json:"disk_id" "yunion:deprecated-by":"disk"`
|
||||
DiskId string `json:"disk_id" yunion-deprecated-by:"disk"`
|
||||
}
|
||||
|
||||
type DiskFilterListInputBase struct {
|
||||
|
||||
@@ -14,5 +14,11 @@
|
||||
|
||||
package compute
|
||||
|
||||
import "yunion.io/x/onecloud/pkg/apis"
|
||||
|
||||
type DnsRecordCreateInput struct {
|
||||
apis.AdminSharableVirtualResourceBaseCreateInput
|
||||
}
|
||||
|
||||
type DnsRecordUpdateInput struct {
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ type ELasticcacheResourceInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
ElasticcacheId string `json:"elasticcache_id" "yunion:deprecated-by":"elasticcache"`
|
||||
ElasticcacheId string `json:"elasticcache_id" yunion-deprecated-by:"elasticcache"`
|
||||
}
|
||||
|
||||
type ElasticcacheFilterListInput struct {
|
||||
|
||||
@@ -24,15 +24,15 @@ type CloudregionResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
CloudregionId string `json:"cloudregion_id" "yunion:deprecated-by":"cloudregion"`
|
||||
CloudregionId string `json:"cloudregion_id" yunion-deprecated-by:"cloudregion"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
Region string `json:"region" "yunion:deprecated-by":"cloudregion"`
|
||||
Region string `json:"region" yunion-deprecated-by:"cloudregion"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
RegionId string `json:"region_id" "yunion:deprecated-by":"cloudregion"`
|
||||
RegionId string `json:"region_id" yunion-deprecated-by:"cloudregion"`
|
||||
}
|
||||
|
||||
type RegionalFilterListInput struct {
|
||||
@@ -134,5 +134,5 @@ type ZoneResourceInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
ZoneId string `json:"zone_id" "yunion:deprecated-by":"zone"`
|
||||
ZoneId string `json:"zone_id" yunion-deprecated-by:"zone"`
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ type GlobalVpcResourceInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
GlobalvpcId string `json:"globalvpc_id" "yunion:deprecated-by":"globalvpc"`
|
||||
GlobalvpcId string `json:"globalvpc_id" yunion-deprecated-by:"globalvpc"`
|
||||
}
|
||||
|
||||
type GlobalVpcResourceListInput struct {
|
||||
|
||||
@@ -30,13 +30,13 @@ type ServerListInput struct {
|
||||
|
||||
HostFilterListInput
|
||||
|
||||
NetworkFilterListInput `"yunion:ambiguous-prefix":"vpc_"`
|
||||
NetworkFilterListInput `yunion-ambiguous-prefix:"vpc_"`
|
||||
|
||||
billing.BillingResourceListInput
|
||||
|
||||
GroupFilterListInput
|
||||
SecgroupFilterListInput
|
||||
//DiskFilterListInput `"yunion:ambiguous-prefix":"storage_"`
|
||||
//DiskFilterListInput `yunion-ambiguous-prefix:"storage_"`
|
||||
ScalingGroupFilterListInput
|
||||
|
||||
// 只列出裸金属主机
|
||||
@@ -66,7 +66,7 @@ type ServerListInput struct {
|
||||
// 列出可以挂载磁盘的主机
|
||||
AttachableServersForDisk string `json:"attachable_servers_for_disk"`
|
||||
// Deprecated:列出可以挂载磁盘的主机
|
||||
Disk string `json:"disk" "yunion:deprecated-by":"attachable_servers_for_disk"`
|
||||
Disk string `json:"disk" yunion-deprecated-by:"attachable_servers_for_disk"`
|
||||
|
||||
// 按主机资源类型进行排序
|
||||
// enum: shared,prepaid,dedicated
|
||||
@@ -267,15 +267,15 @@ type ServerResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by guest Id
|
||||
ServerId string `json:"server_id" "yunion:deprecated-by":"server"`
|
||||
ServerId string `json:"server_id" yunion-deprecated-by:"server"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by guest Id
|
||||
Guest string `json:"guest" "yunion:deprecated-by":"server"`
|
||||
Guest string `json:"guest" yunion-deprecated-by:"server"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by guest Id
|
||||
GuestId string `json:"guest_id" "yunion:deprecated-by":"server"`
|
||||
GuestId string `json:"guest_id" yunion-deprecated-by:"server"`
|
||||
}
|
||||
|
||||
type ServerFilterListInput struct {
|
||||
|
||||
@@ -224,7 +224,7 @@ type HostResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by host_id
|
||||
HostId string `json:"host_id" "yunion:deprecated-by":"host"`
|
||||
HostId string `json:"host_id" yunion-deprecated-by:"host"`
|
||||
}
|
||||
|
||||
type HostRegisterMetadata struct {
|
||||
|
||||
@@ -21,7 +21,7 @@ type HostJointResourceDetailsBase struct {
|
||||
Host string `json:"host"`
|
||||
// 裸金属服务器名称
|
||||
// Deprecated
|
||||
Baremetal string `json:"baremetal" "yunion:deprecated-by":"host"`
|
||||
Baremetal string `json:"baremetal" yunion-deprecated-by:"host"`
|
||||
}
|
||||
|
||||
type HostJointResourceDetails struct {
|
||||
|
||||
@@ -149,7 +149,7 @@ type GuestTemplateFilterListInput struct {
|
||||
GuestTemplate string `json:"guest_template"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
GuestTemplateId string `json:"guest_template_id" "yunion:deprecated-by":"guest_template"`
|
||||
GuestTemplateId string `json:"guest_template_id" yunion-deprecated-by:"guest_template"`
|
||||
}
|
||||
|
||||
type ServiceCatalogListInput struct {
|
||||
|
||||
@@ -50,7 +50,7 @@ type GroupResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by instance group Id
|
||||
GroupId string `json:"group_id" "yunion:deprecated-by":"group"`
|
||||
GroupId string `json:"group_id" yunion-deprecated-by:"group"`
|
||||
}
|
||||
|
||||
type GroupFilterListInput struct {
|
||||
|
||||
@@ -210,7 +210,7 @@ type LoadbalancerResourceInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
LoadbalancerId string `json:"loadbalancer_id" "yunion:deprecated-by":"loadbalancer"`
|
||||
LoadbalancerId string `json:"loadbalancer_id" yunion-deprecated-by:"loadbalancer"`
|
||||
}
|
||||
|
||||
type LoadbalancerFilterListInput struct {
|
||||
|
||||
@@ -39,7 +39,7 @@ type LoadbalancerBackendGroupResourceInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
BackendGroupId string `json:"backend_group_id" "yunion:deprecated-by":"backend_group"`
|
||||
BackendGroupId string `json:"backend_group_id" yunion-deprecated-by:"backend_group"`
|
||||
}
|
||||
|
||||
type LoadbalancerBackendGroupFilterListInput struct {
|
||||
|
||||
@@ -45,7 +45,7 @@ type LoadbalancerClusterResourceInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
ClusterId string `json:"cluster_id" "yunion:deprecated-by":"cluster"`
|
||||
ClusterId string `json:"cluster_id" yunion-deprecated-by:"cluster"`
|
||||
}
|
||||
|
||||
type LoadbalancerClusterFilterListInput struct {
|
||||
|
||||
@@ -45,7 +45,7 @@ type LoadbalancerListenerResourceInput struct {
|
||||
// 负载均衡监听器ID
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
ListenerId string `json:"listener_id" "yunion:deprecated-by":"listener"`
|
||||
ListenerId string `json:"listener_id" yunion-deprecated-by:"listener"`
|
||||
}
|
||||
|
||||
type LoadbalancerListenerFilterListInput struct {
|
||||
|
||||
@@ -89,7 +89,7 @@ type NatGatewayResourceInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
NatgatewayId string `json:"natgateway_id" "yunion:deprecated-by":"natgateway"`
|
||||
NatgatewayId string `json:"natgateway_id" yunion-deprecated-by:"natgateway"`
|
||||
}
|
||||
|
||||
type NatGatewayFilterListInput struct {
|
||||
|
||||
@@ -24,7 +24,7 @@ type WireResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// fitler by wire id
|
||||
WireId string `json:"wire_id" "yunion:deprecated-by":"wire"`
|
||||
WireId string `json:"wire_id" yunion-deprecated-by:"wire"`
|
||||
}
|
||||
|
||||
type WireFilterListBase struct {
|
||||
@@ -47,7 +47,7 @@ type NetworkResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by networkId
|
||||
NetworkId string `json:"network_id" "yunion:deprecated-by":"network"`
|
||||
NetworkId string `json:"network_id" yunion-deprecated-by:"network"`
|
||||
}
|
||||
|
||||
type NetworkFilterListBase struct {
|
||||
|
||||
@@ -45,7 +45,7 @@ type SchedtagResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by schedtag_id
|
||||
SchedtagId string `json:"schedtag_id" "yunion:deprecated-by":"schedtag"`
|
||||
SchedtagId string `json:"schedtag_id" yunion-deprecated-by:"schedtag"`
|
||||
}
|
||||
|
||||
type SchedtagFilterListInput struct {
|
||||
@@ -69,7 +69,7 @@ type SchedtagListInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by type, alias for resource_type
|
||||
Type string `json:"type" "yunion:deprecated-by":"resource_type"`
|
||||
Type string `json:"type" yunion-deprecated-by:"resource_type"`
|
||||
|
||||
DefaultStrategy []string `json:"default_strategy"`
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ type SecgroupResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by secgroup_id
|
||||
SecgroupId string `json:"secgroup_id" "yunion:deprecated-by":"secgroup"`
|
||||
SecgroupId string `json:"secgroup_id" yunion-deprecated-by:"secgroup"`
|
||||
|
||||
// 模糊匹配安全组规则名称
|
||||
SecgroupName string `json:"secgroup_name"`
|
||||
|
||||
@@ -144,7 +144,7 @@ type StorageResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by storage_id
|
||||
StorageId string `json:"storage_id" "yunion:deprecated-by":"storage"`
|
||||
StorageId string `json:"storage_id" yunion-deprecated-by:"storage"`
|
||||
}
|
||||
|
||||
type StorageFilterListInputBase struct {
|
||||
|
||||
@@ -48,13 +48,13 @@ type StoragecachedimageListInput struct {
|
||||
Storagecache string `json:"storagecache"`
|
||||
// Deprecated
|
||||
// swagger:ignore
|
||||
StoragecacheId string `json:"storagecache_id" "yunion:deprecated-by":"storagecache"`
|
||||
StoragecacheId string `json:"storagecache_id" yunion-deprecated-by:"storagecache"`
|
||||
|
||||
// 以镜像缓存过滤
|
||||
Cachedimage string `json:"cachedimage"`
|
||||
// Deprecated
|
||||
// swagger:ignore
|
||||
CachedimageId string `json:"cachedimage_id" "yunion:deprecated-by":"cachedimage"`
|
||||
CachedimageId string `json:"cachedimage_id" yunion-deprecated-by:"cachedimage"`
|
||||
|
||||
// 镜像状态
|
||||
Status []string `json:"status"`
|
||||
|
||||
@@ -80,7 +80,7 @@ type VpcResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by vpc Id
|
||||
VpcId string `json:"vpc_id" "yunion:deprecated-by":"vpc"`
|
||||
VpcId string `json:"vpc_id" yunion-deprecated-by:"vpc"`
|
||||
}
|
||||
|
||||
type VpcFilterListInputBase struct {
|
||||
|
||||
@@ -73,7 +73,7 @@ type IdentityProviderCreateInput struct {
|
||||
TargetDomain string `json:"target_domain"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
TargetDomainId string `json:"target_domain_id" "yunion:deprecated-by":"target_domain"`
|
||||
TargetDomainId string `json:"target_domain_id" yunion-deprecated-by:"target_domain"`
|
||||
|
||||
// 新建域的时候是否自动新建第一个项目
|
||||
AutoCreateProject *bool `json:"auto_create_project"`
|
||||
|
||||
@@ -49,22 +49,22 @@ type ProjectFilterListInput struct {
|
||||
ProjectDomain string `json:"project_domain"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
ProjectDomainId string `json:"project_domain_id" "yunion:deprecated-by":"project-domain"`
|
||||
ProjectDomainId string `json:"project_domain_id" yunion-deprecated-by:"project-domain"`
|
||||
|
||||
// 以项目(ID或Name)过滤列表结果
|
||||
Project string `json:"project"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by project_id
|
||||
ProjectId string `json:"project_id" "yunion:deprecated-by":"project"`
|
||||
ProjectId string `json:"project_id" yunion-deprecated-by:"project"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by tenant
|
||||
Tenant string `json:"tenant" "yunion:deprecated-by":"project"`
|
||||
Tenant string `json:"tenant" yunion-deprecated-by:"project"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by tenant_id
|
||||
TenantId string `json:"tenant_id" "yunion:deprecated-by":"project"`
|
||||
TenantId string `json:"tenant_id" yunion-deprecated-by:"project"`
|
||||
}
|
||||
|
||||
type UserFilterListInput struct {
|
||||
@@ -79,7 +79,7 @@ type UserFilterListInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by user_id
|
||||
UserId string `json:"user_id" "yunion:deprecated-by":"user"`
|
||||
UserId string `json:"user_id" yunion-deprecated-by:"user"`
|
||||
}
|
||||
|
||||
type GroupFilterListInput struct {
|
||||
@@ -94,7 +94,7 @@ type GroupFilterListInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by group_id
|
||||
GroupId string `json:"group_id" "yunion:deprecated-by":"group"`
|
||||
GroupId string `json:"group_id" yunion-deprecated-by:"group"`
|
||||
}
|
||||
|
||||
type RoleFilterListInput struct {
|
||||
@@ -109,7 +109,7 @@ type RoleFilterListInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by role_id
|
||||
RoleId string `json:"role_id" "yunion:deprecated-by":"role"`
|
||||
RoleId string `json:"role_id" yunion-deprecated-by:"role"`
|
||||
}
|
||||
|
||||
type ServiceFilterListInput struct {
|
||||
@@ -121,7 +121,7 @@ type ServiceFilterListInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by service_id
|
||||
ServiceId string `json:"service_id" "yunion:deprecated-by":"service"`
|
||||
ServiceId string `json:"service_id" yunion-deprecated-by:"service"`
|
||||
|
||||
// 以服务名称排序
|
||||
OrderByService string `json:"order_by_service"`
|
||||
@@ -325,7 +325,7 @@ type RegionFilterListInput struct {
|
||||
Region string `json:"region"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
RegionId string `json:"region_id" "yunion:deprecated-by":"region"`
|
||||
RegionId string `json:"region_id" yunion-deprecated-by:"region"`
|
||||
}
|
||||
|
||||
type RegionListInput struct {
|
||||
|
||||
@@ -48,6 +48,7 @@ const (
|
||||
IMAGE_IS_READONLY = "is_readonly"
|
||||
IMAGE_PARTITION_TYPE = "partition_type"
|
||||
IMAGE_INSTALLED_CLOUDINIT = "installed_cloud_init"
|
||||
IMAGE_DISABLE_USB_KBD = "disable_usb_kbd"
|
||||
|
||||
IMAGE_STATUS_UPDATING = "updating"
|
||||
)
|
||||
|
||||
@@ -21,15 +21,15 @@ type DomainizedResourceInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
Domain string `json:"domain" "yunion:deprecated-by":"project_domain"`
|
||||
Domain string `json:"domain" yunion-deprecated-by:"project_domain"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Project domain Id filter, alias for project_domain
|
||||
ProjectDomainId string `json:"project_domain_id" "yunion:deprecated-by":"project_domain"`
|
||||
ProjectDomainId string `json:"project_domain_id" yunion-deprecated-by:"project_domain"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Domain Id filter, alias for project_domain
|
||||
DomainId string `json:"domain_id" "yunion:deprecated-by":"project_domain"`
|
||||
DomainId string `json:"domain_id" yunion-deprecated-by:"project_domain"`
|
||||
}
|
||||
|
||||
type ProjectizedResourceInput struct {
|
||||
@@ -39,15 +39,15 @@ type ProjectizedResourceInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by project_id, alias for project
|
||||
ProjectId string `json:"project_id" "yunion:deprecated-by":"project"`
|
||||
ProjectId string `json:"project_id" yunion-deprecated-by:"project"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by tenant ID or Name, alias for project
|
||||
Tenant string `json:"tenant" "yunion:deprecated-by":"project"`
|
||||
Tenant string `json:"tenant" yunion-deprecated-by:"project"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by tenant_id, alias for project
|
||||
TenantId string `json:"tenant_id" "yunion:deprecated-by":"project"`
|
||||
TenantId string `json:"tenant_id" yunion-deprecated-by:"project"`
|
||||
}
|
||||
|
||||
type DomainizedResourceCreateInput struct {
|
||||
@@ -75,6 +75,27 @@ type SharableVirtualResourceCreateInput struct {
|
||||
SharableResourceBaseCreateInput
|
||||
}
|
||||
|
||||
type AdminSharableVirtualResourceBaseCreateInput struct {
|
||||
SharableVirtualResourceCreateInput
|
||||
|
||||
// 记录
|
||||
Records string `json:"records"`
|
||||
}
|
||||
|
||||
type StatusDomainLevelUserResourceCreateInput struct {
|
||||
StatusDomainLevelResourceCreateInput
|
||||
|
||||
// 本地用户Id,若为空则使用当前用户Id作为此参数值
|
||||
OwnerId string `json:"owner_id"`
|
||||
}
|
||||
|
||||
type UserResourceCreateInput struct {
|
||||
StandaloneResourceCreateInput
|
||||
|
||||
// 本地用户Id,若为空则使用当前用户Id作为此参数值
|
||||
OwnerId string `json:"owner_id"`
|
||||
}
|
||||
|
||||
type VirtualResourceCreateInput struct {
|
||||
StatusStandaloneResourceCreateInput
|
||||
ProjectizedResourceCreateInput
|
||||
|
||||
@@ -50,7 +50,7 @@ type ProjectizedResourceListInput struct {
|
||||
OrderByProject string `json:"order_by_project"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
OrderByTenant string `json:"order_by_tenant" "yunion:deprecated-by":"order_by_project"`
|
||||
OrderByTenant string `json:"order_by_tenant" yunion-deprecated-by:"order_by_project"`
|
||||
}
|
||||
|
||||
type UserResourceListInput struct {
|
||||
@@ -59,7 +59,7 @@ type UserResourceListInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by userId
|
||||
UserId string `json:"user_id" "yunion:deprecated-by":"user"`
|
||||
UserId string `json:"user_id" yunion-deprecated-by:"user"`
|
||||
}
|
||||
|
||||
type ModelBaseListInput struct {
|
||||
|
||||
@@ -137,11 +137,11 @@ type ProjectizedResourceInfo struct {
|
||||
|
||||
// 资源归属项目的ID(向后兼容别名)
|
||||
// Deprecated
|
||||
TenantId string `json:"project_id" "yunion:deprecated-by":"tenant_id"`
|
||||
TenantId string `json:"project_id" yunion-deprecated-by:"tenant_id"`
|
||||
|
||||
// 资源归属项目的名称(向后兼容别名)
|
||||
// Deprecated
|
||||
Tenant string `json:"project" "yunion:deprecated-by":"tenant"`
|
||||
Tenant string `json:"project" yunion-deprecated-by:"tenant"`
|
||||
}
|
||||
|
||||
type ScopedResourceBaseInfo struct {
|
||||
|
||||
@@ -28,14 +28,14 @@ type ParameterListInput struct {
|
||||
|
||||
// Deprecated
|
||||
// swagger:ignore
|
||||
ServiceId string `json:"service_id" "yunion:deprecated-by":"service"`
|
||||
ServiceId string `json:"service_id" yunion-deprecated-by:"service"`
|
||||
|
||||
// 用户名称或ID
|
||||
User string `json:"user"`
|
||||
|
||||
// Deprecated
|
||||
// swagger:ignore
|
||||
UserId string `json:"user_id" "yunion:deprecated-by":"user"`
|
||||
UserId string `json:"user_id" yunion-deprecated-by:"user"`
|
||||
|
||||
// filter by name
|
||||
Name []string `json:"name"`
|
||||
|
||||
@@ -51,7 +51,22 @@ func (manager *SAdminSharableVirtualResourceBaseManager) GetIAdminSharableVirtua
|
||||
return manager.GetVirtualObject().(IAdminSharableVirtualModelManager)
|
||||
}
|
||||
|
||||
func (manager *SAdminSharableVirtualResourceBaseManager) ValidateCreateData(man IAdminSharableVirtualModelManager, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func (manager *SAdminSharableVirtualResourceBaseManager) ValidateCreateData(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
ownerId mcclient.IIdentityProvider,
|
||||
query jsonutils.JSONObject,
|
||||
input apis.AdminSharableVirtualResourceBaseCreateInput,
|
||||
) (apis.AdminSharableVirtualResourceBaseCreateInput, error) {
|
||||
var err error
|
||||
input.SharableVirtualResourceCreateInput, err = manager.SSharableVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.SharableVirtualResourceCreateInput)
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "SSharableVirtualResourceBaseManager.ValidateCreateData")
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (manager *SAdminSharableVirtualResourceBaseManager) ValidateRecordsData(man IAdminSharableVirtualModelManager, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
records, err := man.ParseInputInfo(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -16,6 +16,7 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -460,28 +461,7 @@ func (manager *SOpsLogManager) ListItemFilter(
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
/*userStrs := jsonutils.GetQueryStringArray(query, "user")
|
||||
if len(userStrs) > 0 {
|
||||
for i := range userStrs {
|
||||
usrObj, err := DefaultUserFetcher(ctx, userStrs[i])
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2("user", userStrs[i])
|
||||
} else if err == sqlchemy.ErrDuplicateEntry {
|
||||
return nil, httperrors.NewDuplicateNameError("user", userStrs[i])
|
||||
} else {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
}
|
||||
userStrs[i] = usrObj.GetId()
|
||||
}
|
||||
if len(userStrs) == 1 {
|
||||
q = q.Filter(sqlchemy.Equals(q.Field("user_id"), userStrs[0]))
|
||||
} else {
|
||||
q = q.Filter(sqlchemy.In(q.Field("user_id"), userStrs))
|
||||
}
|
||||
}
|
||||
projStrs := jsonutils.GetQueryStringArray(query, "project")
|
||||
projStrs := jsonutils.GetQueryStringArray(query, "owner_project_ids")
|
||||
if len(projStrs) > 0 {
|
||||
for i := range projStrs {
|
||||
projObj, err := DefaultProjectFetcher(ctx, projStrs[i])
|
||||
@@ -494,12 +474,23 @@ func (manager *SOpsLogManager) ListItemFilter(
|
||||
}
|
||||
projStrs[i] = projObj.GetId()
|
||||
}
|
||||
if len(projStrs) == 1 {
|
||||
q = q.Filter(sqlchemy.Equals(q.Field("owner_tenant_id"), projStrs[0]))
|
||||
} else {
|
||||
q = q.Filter(sqlchemy.In(q.Field("owner_tenant_id"), projStrs))
|
||||
q = q.Filter(sqlchemy.In(q.Field("owner_tenant_id"), projStrs))
|
||||
}
|
||||
domainStrs := jsonutils.GetQueryStringArray(query, "owner_domain_ids")
|
||||
if len(domainStrs) > 0 {
|
||||
for i := range domainStrs {
|
||||
domainObj, err := DefaultDomainFetcher(ctx, domainStrs[i])
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2("domain", domainStrs[i])
|
||||
} else {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
}
|
||||
domainStrs[i] = domainObj.GetId()
|
||||
}
|
||||
}*/
|
||||
q = q.Filter(sqlchemy.In(q.Field("owner_domain_id"), domainStrs))
|
||||
}
|
||||
objTypes := jsonutils.GetQueryStringArray(query, "obj_type")
|
||||
if len(objTypes) > 0 {
|
||||
if len(objTypes) == 1 {
|
||||
|
||||
@@ -126,7 +126,7 @@ func RawNotify(recipientId []string, isGroup bool, channel notify.TNotifyChannel
|
||||
msg.Topic = topic
|
||||
body, _ := getContent(event, "content", channel, data)
|
||||
if len(body) == 0 {
|
||||
body = data.String()
|
||||
body, _ = data.GetString()
|
||||
}
|
||||
msg.Msg = body
|
||||
// log.Debugf("send notification %s %s", topic, body)
|
||||
|
||||
@@ -368,3 +368,42 @@ func (self *SESXiGuestDriver) RequestAssociateEip(ctx context.Context, userCred
|
||||
func (self *SESXiGuestDriver) IsSupportCdrom(guest *models.SGuest) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) RequestSyncstatusOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, userCred mcclient.TokenCredential) (jsonutils.JSONObject, error) {
|
||||
ihost, err := host.GetIHost()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ivm, err := ihost.GetIVMById(guest.GetExternalId())
|
||||
if err != nil && errors.Cause(err) != errors.ErrNotFound {
|
||||
return nil, err
|
||||
}
|
||||
// VM may be migrated by Vcenter, try to find VM from whole datacenter.
|
||||
if err != nil {
|
||||
ehost := ihost.(*esxi.SHost)
|
||||
dc, err := ehost.GetDatacenter()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "ehost.GetDatacenter")
|
||||
}
|
||||
vm, err := dc.FetchVMById(guest.GetExternalId())
|
||||
if err != nil {
|
||||
log.Errorf("fail to find ivm by id %q in dc %q: %v", guest.GetExternalId(), dc.GetName(), err)
|
||||
return nil, err
|
||||
}
|
||||
ihost = vm.GetIHost()
|
||||
host = models.HostManager.FetchHostByExtId(ihost.GetGlobalId())
|
||||
if host == nil {
|
||||
return nil, errors.Wrapf(errors.ErrNotFound, "find ivm %q in ihost %q which is not existed here", guest.GetExternalId(), ihost.GetGlobalId())
|
||||
}
|
||||
ivm = vm
|
||||
}
|
||||
err = guest.SyncAllWithCloudVM(ctx, userCred, host, ivm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
status := GetCloudVMStatus(ivm)
|
||||
body := jsonutils.NewDict()
|
||||
body.Add(jsonutils.NewString(status), "status")
|
||||
return body, nil
|
||||
}
|
||||
|
||||
@@ -1229,7 +1229,7 @@ func SyncCloudProject(userCred mcclient.TokenCredential, model db.IVirtualModel,
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, managerId)
|
||||
if err != nil {
|
||||
log.Errorf("sync project for %s %s error: %v", model.Keyword(), model.GetName(), err)
|
||||
} else {
|
||||
} else if len(extProject.ProjectId) > 0 {
|
||||
newOwnerId = extProject.GetOwnerId()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1287,6 +1287,13 @@ func (manager *SDBInstanceManager) SyncDBInstances(ctx context.Context, userCred
|
||||
return nil, nil, syncResult
|
||||
}
|
||||
|
||||
for i := range dbInstances {
|
||||
if taskman.TaskManager.IsInTask(&dbInstances[i]) {
|
||||
syncResult.Error(fmt.Errorf("dbInstance %s(%s)in task", dbInstances[i].Name, dbInstances[i].Id))
|
||||
return nil, nil, syncResult
|
||||
}
|
||||
}
|
||||
|
||||
removed := make([]SDBInstance, 0)
|
||||
commondb := make([]SDBInstance, 0)
|
||||
commonext := make([]cloudprovider.ICloudDBInstance, 0)
|
||||
|
||||
@@ -337,11 +337,26 @@ func (man *SDnsRecordManager) ValidateCreateData(
|
||||
query jsonutils.JSONObject,
|
||||
data *jsonutils.JSONDict,
|
||||
) (*jsonutils.JSONDict, error) {
|
||||
_, err := man.validateModelData(ctx, data, true)
|
||||
var err error
|
||||
|
||||
input := apis.AdminSharableVirtualResourceBaseCreateInput{}
|
||||
err = data.Unmarshal(&input)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Unmarshal AdminSharableVirtualResourceBaseCreateInput")
|
||||
}
|
||||
|
||||
input, err = man.SAdminSharableVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SAdminSharableVirtualResourceBaseManager.ValidateCreateData")
|
||||
}
|
||||
|
||||
data.Update(jsonutils.Marshal(input))
|
||||
|
||||
_, err = man.validateModelData(ctx, data, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return man.SAdminSharableVirtualResourceBaseManager.ValidateCreateData(man, data)
|
||||
return man.SAdminSharableVirtualResourceBaseManager.ValidateRecordsData(man, data)
|
||||
}
|
||||
|
||||
func (man *SDnsRecordManager) QueryDns(projectId, name string) *SDnsRecord {
|
||||
|
||||
@@ -448,6 +448,13 @@ func (manager *SElasticcacheManager) SyncElasticcaches(ctx context.Context, user
|
||||
return nil, nil, syncResult
|
||||
}
|
||||
|
||||
for i := range dbInstances {
|
||||
if taskman.TaskManager.IsInTask(&dbInstances[i]) {
|
||||
syncResult.Error(fmt.Errorf("ElasticCacheInstance %s(%s)in task", dbInstances[i].Name, dbInstances[i].Id))
|
||||
return nil, nil, syncResult
|
||||
}
|
||||
}
|
||||
|
||||
removed := make([]SElasticcache, 0)
|
||||
commondb := make([]SElasticcache, 0)
|
||||
commonext := make([]cloudprovider.ICloudElasticcache, 0)
|
||||
|
||||
@@ -421,8 +421,11 @@ func (self *SElasticip) SyncInstanceWithCloudEip(ctx context.Context, userCred m
|
||||
case api.EIP_ASSOCIATE_TYPE_SERVER:
|
||||
sq := HostManager.Query().SubQuery()
|
||||
return q.Join(sq, sqlchemy.Equals(sq.Field("id"), q.Field("host_id"))).Filter(sqlchemy.Equals(sq.Field("manager_id"), self.ManagerId))
|
||||
case api.EIP_ASSOCIATE_TYPE_NAT_GATEWAY, api.EIP_ASSOCIATE_TYPE_LOADBALANCER:
|
||||
case api.EIP_ASSOCIATE_TYPE_LOADBALANCER:
|
||||
return q.Equals("manager_id", self.ManagerId)
|
||||
case api.EIP_ASSOCIATE_TYPE_NAT_GATEWAY:
|
||||
sq := VpcManager.Query("id").Equals("manager_id", self.ManagerId)
|
||||
return q.In("vpc_id", sq.SubQuery())
|
||||
}
|
||||
return q
|
||||
})
|
||||
|
||||
@@ -3056,6 +3056,13 @@ func (self *SGuest) PerformSetQemuParams(ctx context.Context, userCred mcclient.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
usbKbd, err := data.GetString("disable_usb_kbd")
|
||||
if err == nil {
|
||||
err = self.SetMetadata(ctx, "disable_usb_kbd", usbKbd, userCred)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -3612,9 +3619,11 @@ func (self *SGuest) SaveRenewInfo(
|
||||
guestdisks := self.GetDisks()
|
||||
for i := 0; i < len(guestdisks); i += 1 {
|
||||
disk := guestdisks[i].GetDisk()
|
||||
err = disk.SaveRenewInfo(ctx, userCred, bc, expireAt, billingType)
|
||||
if err != nil {
|
||||
return err
|
||||
if disk.AutoDelete {
|
||||
err = disk.SaveRenewInfo(ctx, userCred, bc, expireAt, billingType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -1107,6 +1107,7 @@ func (manager *SGuestManager) validateCreateData(
|
||||
if len(imgProperties) == 0 {
|
||||
imgProperties = map[string]string{"os_type": "Linux"}
|
||||
}
|
||||
input.DisableUsbKbd = imgProperties[imageapi.IMAGE_DISABLE_USB_KBD] == "true"
|
||||
|
||||
osType := input.OsType
|
||||
osProf, err = osprofile.GetOSProfileFromImageProperties(imgProperties, hypervisor)
|
||||
@@ -1665,6 +1666,9 @@ func (guest *SGuest) PostCreate(ctx context.Context, userCred mcclient.TokenCred
|
||||
if osProfileJson != nil {
|
||||
guest.setOSProfile(ctx, userCred, osProfileJson)
|
||||
}
|
||||
if jsonutils.QueryBoolean(data, imageapi.IMAGE_DISABLE_USB_KBD, false) {
|
||||
guest.SetMetadata(ctx, imageapi.IMAGE_DISABLE_USB_KBD, "true", userCred)
|
||||
}
|
||||
|
||||
userData, _ := data.GetString("user_data")
|
||||
if len(userData) > 0 {
|
||||
@@ -2726,7 +2730,7 @@ func getCloudNicNetwork(vnic cloudprovider.ICloudNic, host *SHost, ipList []stri
|
||||
if vnet == nil {
|
||||
if vnic.InClassicNetwork() {
|
||||
region := host.GetRegion()
|
||||
cloudprovider := region.GetCloudprovider()
|
||||
cloudprovider := host.GetCloudprovider()
|
||||
vpc, err := VpcManager.GetOrCreateVpcForClassicNetwork(cloudprovider, region)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "NewVpcForClassicNetwork")
|
||||
@@ -4216,6 +4220,14 @@ func (self *SGuest) GetShortDesc(ctx context.Context) *jsonutils.JSONDict {
|
||||
billingInfo.SCloudProviderInfo = host.getCloudProviderInfo()
|
||||
}
|
||||
|
||||
if len(self.BackupHostId) > 0 {
|
||||
backupHost := HostManager.FetchHostById(self.BackupHostId)
|
||||
if backupHost != nil {
|
||||
desc.Set("backup_host", jsonutils.NewString(backupHost.Name))
|
||||
desc.Set("backup_host_id", jsonutils.NewString(backupHost.Id))
|
||||
}
|
||||
}
|
||||
|
||||
if priceKey := self.GetMetadata("ext:price_key", nil); len(priceKey) > 0 {
|
||||
billingInfo.PriceKey = priceKey
|
||||
}
|
||||
|
||||
@@ -1381,6 +1381,17 @@ func (self *SHost) GetGuests() []SGuest {
|
||||
return guests
|
||||
}
|
||||
|
||||
func (self *SHost) GetKvmGuests() []SGuest {
|
||||
q := GuestManager.Query().Equals("host_id", self.Id).Equals("hypervisor", api.HYPERVISOR_KVM)
|
||||
guests := make([]SGuest, 0)
|
||||
err := db.FetchModelObjects(GuestManager, q, &guests)
|
||||
if err != nil {
|
||||
log.Errorf("GetGuests %s", err)
|
||||
return nil
|
||||
}
|
||||
return guests
|
||||
}
|
||||
|
||||
func (self *SHost) GetGuestCount() (int, error) {
|
||||
q := self.GetGuestsQuery()
|
||||
return q.CountWithError()
|
||||
@@ -4809,7 +4820,7 @@ func (host *SHost) PerformHostMaintenance(ctx context.Context, userCred mcclient
|
||||
preferHostId = host.Id
|
||||
}
|
||||
|
||||
guests := host.GetGuests()
|
||||
guests := host.GetKvmGuests()
|
||||
for i := 0; i < len(guests); i++ {
|
||||
lockman.LockObject(ctx, &guests[i])
|
||||
defer lockman.ReleaseObject(ctx, &guests[i])
|
||||
@@ -5229,3 +5240,15 @@ func (manager *SHostManager) ListItemExportKeys(ctx context.Context,
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SHostManager) FetchHostByExtId(extid string) *SHost {
|
||||
host := SHost{}
|
||||
host.SetModelManager(manager, &host)
|
||||
err := manager.Query().Equals("external_id", extid).First(&host)
|
||||
if err != nil {
|
||||
log.Errorf("fetchHostByExtId fail %s", err)
|
||||
return nil
|
||||
} else {
|
||||
return &host
|
||||
}
|
||||
}
|
||||
|
||||
@@ -706,6 +706,13 @@ func (man *SLoadbalancerManager) SyncLoadbalancers(ctx context.Context, userCred
|
||||
return nil, nil, syncResult
|
||||
}
|
||||
|
||||
for i := range dbLbs {
|
||||
if taskman.TaskManager.IsInTask(&dbLbs[i]) {
|
||||
syncResult.Error(fmt.Errorf("loadbalancer %s(%s)in task", dbLbs[i].Name, dbLbs[i].Id))
|
||||
return nil, nil, syncResult
|
||||
}
|
||||
}
|
||||
|
||||
removed := []SLoadbalancer{}
|
||||
commondb := []SLoadbalancer{}
|
||||
commonext := []cloudprovider.ICloudLoadbalancer{}
|
||||
|
||||
@@ -822,16 +822,17 @@ func (manager *SNetworkManager) GetOnPremiseNetworkOfIP(ipAddr string, serverTyp
|
||||
|
||||
func (manager *SNetworkManager) allNetworksQ(providers []string, brands []string, cloudEnv string, rangeObjs []db.IStandaloneModel) *sqlchemy.SQuery {
|
||||
networks := manager.Query().SubQuery()
|
||||
hostwires := HostwireManager.Query().SubQuery()
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
wires := WireManager.Query().SubQuery()
|
||||
vpcs := VpcManager.Query().SubQuery()
|
||||
|
||||
q := networks.Query(networks.Field("id"))
|
||||
q = q.Join(hostwires, sqlchemy.Equals(hostwires.Field("wire_id"), networks.Field("wire_id")))
|
||||
q = q.Join(hosts, sqlchemy.Equals(hosts.Field("id"), hostwires.Field("host_id")))
|
||||
q = q.Filter(sqlchemy.IsTrue(hosts.Field("enabled")))
|
||||
q = q.Filter(sqlchemy.OR(
|
||||
sqlchemy.Equals(hosts.Field("host_type"), api.HOST_TYPE_BAREMETAL),
|
||||
sqlchemy.Equals(hosts.Field("host_status"), api.HOST_ONLINE)))
|
||||
return AttachUsageQuery(q, hosts, nil, nil, providers, brands, cloudEnv, rangeObjs)
|
||||
q = q.Join(wires, sqlchemy.Equals(q.Field("wire_id"), wires.Field("id")))
|
||||
q = q.Join(vpcs, sqlchemy.Equals(wires.Field("vpc_id"), vpcs.Field("id")))
|
||||
|
||||
q = CloudProviderFilter(q, vpcs.Field("manager_id"), providers, brands, cloudEnv)
|
||||
q = RangeObjectsFilter(q, rangeObjs, vpcs.Field("cloudregion_id"), wires.Field("zone_id"), vpcs.Field("manager_id"), nil, nil)
|
||||
|
||||
return q
|
||||
}
|
||||
|
||||
func (manager *SNetworkManager) totalPortCountQ(
|
||||
|
||||
@@ -1142,10 +1142,15 @@ func (manager *SServerSkuManager) newFromCloudSku(ctx context.Context, userCred
|
||||
sku.Status = api.SkuStatusReady
|
||||
sku.constructSku(extSku)
|
||||
|
||||
sku.Name = extSku.GetName()
|
||||
var err error
|
||||
sku.Name, err = db.GenerateName(manager, userCred, extSku.GetName())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "db.GenerateName")
|
||||
}
|
||||
|
||||
sku.CloudregionId = api.DEFAULT_REGION_ID
|
||||
sku.SetModelManager(manager, sku)
|
||||
err := manager.TableSpec().Insert(sku)
|
||||
err = manager.TableSpec().Insert(sku)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "newFromCloudSku.Insert")
|
||||
}
|
||||
|
||||
@@ -953,8 +953,6 @@ func (manager *SStorageManager) totalCapacityQ(
|
||||
q = RangeObjectsFilter(q, rangeObjs, nil, storages.Field("zone_id"), storages.Field("manager_id"), nil, storages.Field("id"))
|
||||
}
|
||||
|
||||
q = q.Distinct()
|
||||
|
||||
if storageOwnership {
|
||||
switch scope {
|
||||
case rbacutils.ScopeSystem:
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
@@ -182,7 +183,7 @@ func (manager *SVpcManager) getVpcExternalIdForClassicNetwork(regionId, cloudpro
|
||||
func (manager *SVpcManager) GetOrCreateVpcForClassicNetwork(cloudprovider *SCloudprovider, region *SCloudregion) (*SVpc, error) {
|
||||
externalId := manager.getVpcExternalIdForClassicNetwork(region.Id, cloudprovider.Id)
|
||||
_vpc, err := db.FetchByExternalIdAndManagerId(manager, externalId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
return q.Equals("manager_id", region.ManagerId)
|
||||
return q.Equals("manager_id", cloudprovider.Id)
|
||||
})
|
||||
if err == nil {
|
||||
return _vpc.(*SVpc), nil
|
||||
@@ -199,7 +200,7 @@ func (manager *SVpcManager) GetOrCreateVpcForClassicNetwork(cloudprovider *SClou
|
||||
vpc.SetEnabled(false)
|
||||
vpc.Status = api.VPC_STATUS_UNAVAILABLE
|
||||
vpc.ExternalId = externalId
|
||||
vpc.ManagerId = region.ManagerId
|
||||
vpc.ManagerId = cloudprovider.Id
|
||||
err = manager.TableSpec().Insert(vpc)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Insert vpc for classic network")
|
||||
@@ -1024,6 +1025,11 @@ func (self *SVpc) initWire(ctx context.Context, zone *SZone) (*SWire, error) {
|
||||
wire.ZoneId = zone.Id
|
||||
wire.IsEmulated = true
|
||||
wire.Name = fmt.Sprintf("vpc-%s", self.Name)
|
||||
|
||||
wire.DomainId = self.DomainId
|
||||
wire.IsPublic = self.IsPublic
|
||||
wire.PublicScope = self.PublicScope
|
||||
|
||||
wire.SetModelManager(WireManager, wire)
|
||||
err := WireManager.TableSpec().Insert(wire)
|
||||
if err != nil {
|
||||
@@ -1176,3 +1182,100 @@ func (manager *SVpcManager) ListItemExportKeys(ctx context.Context,
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (vpc *SVpc) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicDomainInput) (jsonutils.JSONObject, error) {
|
||||
if vpc.Id == api.DEFAULT_VPC_ID && rbacutils.String2ScopeDefault(input.Scope, rbacutils.ScopeSystem) != rbacutils.ScopeSystem {
|
||||
return nil, httperrors.NewForbiddenError("For default vpc, only system level sharing can be set")
|
||||
}
|
||||
_, err := vpc.SEnabledStatusInfrasResourceBase.PerformPublic(ctx, userCred, query, input)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SEnabledStatusInfrasResourceBase.PerformPublic")
|
||||
}
|
||||
// perform public for all emulated wires
|
||||
wires := vpc.GetWires()
|
||||
for i := range wires {
|
||||
if wires[i].IsEmulated {
|
||||
_, err := wires[i].PerformPublic(ctx, userCred, query, input)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "wire.PerformPublic")
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (vpc *SVpc) PerformPrivate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPrivateInput) (jsonutils.JSONObject, error) {
|
||||
if vpc.Id == "default" {
|
||||
return nil, httperrors.NewForbiddenError("Prohibit making default vpc private")
|
||||
}
|
||||
// perform private for all emulated wires
|
||||
emptyNets := true
|
||||
wires := vpc.GetWires()
|
||||
for i := range wires {
|
||||
if wires[i].DomainId == vpc.DomainId {
|
||||
nets, _ := wires[i].getNetworks(nil, rbacutils.ScopeNone)
|
||||
for j := range nets {
|
||||
if nets[j].DomainId != vpc.DomainId {
|
||||
emptyNets = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if !emptyNets {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
emptyNets = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if emptyNets {
|
||||
for i := range wires {
|
||||
nets, _ := wires[i].getNetworks(nil, rbacutils.ScopeNone)
|
||||
netfail := false
|
||||
for j := range nets {
|
||||
if nets[j].IsPublic && nets[j].GetPublicScope().HigherEqual(rbacutils.ScopeDomain) {
|
||||
var err error
|
||||
if consts.GetNonDefaultDomainProjects() {
|
||||
netinput := apis.PerformPublicProjectInput{}
|
||||
netinput.Scope = string(rbacutils.ScopeDomain)
|
||||
_, err = nets[j].PerformPublic(ctx, userCred, nil, netinput)
|
||||
} else {
|
||||
_, err = nets[j].PerformPrivate(ctx, userCred, nil, input)
|
||||
}
|
||||
if err != nil {
|
||||
log.Errorf("nets[j].PerformPublic fail %s", err)
|
||||
netfail = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if netfail {
|
||||
break
|
||||
}
|
||||
_, err := wires[i].PerformPrivate(ctx, userCred, query, input)
|
||||
if err != nil {
|
||||
log.Errorf("wires[i].PerformPrivate fail %s", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return vpc.SEnabledStatusInfrasResourceBase.PerformPrivate(ctx, userCred, query, input)
|
||||
}
|
||||
|
||||
func (vpc *SVpc) PerformChangeOwner(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformChangeDomainOwnerInput) (jsonutils.JSONObject, error) {
|
||||
_, err := vpc.SEnabledStatusInfrasResourceBase.PerformChangeOwner(ctx, userCred, query, input)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SEnabledStatusInfrasResourceBase.PerformChangeOwner")
|
||||
}
|
||||
wires := vpc.GetWires()
|
||||
for i := range wires {
|
||||
if wires[i].IsEmulated {
|
||||
_, err := wires[i].PerformChangeOwner(ctx, userCred, query, input)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "wires[i].PerformChangeOwner")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -101,10 +101,13 @@ func (self *DiskDeleteTask) startDeleteDisk(ctx context.Context, disk *models.SD
|
||||
)
|
||||
|
||||
storage = disk.GetStorage()
|
||||
if storage != nil {
|
||||
host = storage.GetMasterHost()
|
||||
if storage == nil { // dirty data
|
||||
self.OnGuestDiskDeleteComplete(ctx, disk, nil)
|
||||
return
|
||||
}
|
||||
|
||||
host = storage.GetMasterHost()
|
||||
|
||||
isPurge := false
|
||||
if (host == nil || !host.GetEnabled()) && jsonutils.QueryBoolean(self.Params, "purge", false) {
|
||||
isPurge = true
|
||||
@@ -112,21 +115,25 @@ func (self *DiskDeleteTask) startDeleteDisk(ctx context.Context, disk *models.SD
|
||||
disk.SetStatus(self.UserCred, api.DISK_DEALLOC, "")
|
||||
if isPurge {
|
||||
self.OnGuestDiskDeleteComplete(ctx, disk, nil)
|
||||
return
|
||||
}
|
||||
if isNeed, _ := disk.IsNeedWaitSnapshotsDeleted(); isNeed { // for kvm rbd disk
|
||||
self.OnGuestDiskDeleteComplete(ctx, disk, nil)
|
||||
return
|
||||
}
|
||||
if len(disk.BackupStorageId) > 0 {
|
||||
self.SetStage("OnMasterStorageDeleteDiskComplete", nil)
|
||||
} else {
|
||||
if isNeed, _ := disk.IsNeedWaitSnapshotsDeleted(); isNeed {
|
||||
self.OnGuestDiskDeleteComplete(ctx, disk, nil)
|
||||
return
|
||||
}
|
||||
if len(disk.BackupStorageId) > 0 {
|
||||
self.SetStage("OnMasterStorageDeleteDiskComplete", nil)
|
||||
} else {
|
||||
self.SetStage("OnGuestDiskDeleteComplete", nil)
|
||||
}
|
||||
if host == nil {
|
||||
self.OnGuestDiskDeleteCompleteFailed(ctx, disk, jsonutils.NewString("fail to find master host"))
|
||||
} else if err := host.GetHostDriver().RequestDeallocateDiskOnHost(ctx, host, storage, disk, self); err != nil {
|
||||
self.OnGuestDiskDeleteCompleteFailed(ctx, disk, jsonutils.NewString(err.Error()))
|
||||
}
|
||||
self.SetStage("OnGuestDiskDeleteComplete", nil)
|
||||
}
|
||||
if host == nil {
|
||||
self.OnGuestDiskDeleteCompleteFailed(ctx, disk, jsonutils.NewString("fail to find master host"))
|
||||
return
|
||||
}
|
||||
err := host.GetHostDriver().RequestDeallocateDiskOnHost(ctx, host, storage, disk, self)
|
||||
if err != nil {
|
||||
self.OnGuestDiskDeleteCompleteFailed(ctx, disk, jsonutils.NewString(err.Error()))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ func (self *GuestDetachDiskTask) OnDetachDiskComplete(ctx context.Context, guest
|
||||
return
|
||||
}
|
||||
}
|
||||
models.StartResourceSyncStatusTask(ctx, self.GetUserCred(), disk, "DiskSyncstatusTask", "")
|
||||
disk.SetStatus(self.UserCred, api.DISK_READY, "on detach disk complete")
|
||||
keepDisk := jsonutils.QueryBoolean(self.Params, "keep_disk", true)
|
||||
host := guest.GetHost()
|
||||
purge := false
|
||||
|
||||
@@ -133,7 +133,6 @@ func Start(app *appsrv.Application) error {
|
||||
}
|
||||
|
||||
func (agent *SEsxiAgent) AddImageCacheHandler(prefix string, app *appsrv.Application) {
|
||||
hostutils.InitWorkerManager()
|
||||
app.AddHandler("POST",
|
||||
fmt.Sprintf("%s/disks/image_cache", prefix),
|
||||
auth.Authenticate(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -19,18 +19,19 @@ import common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
|
||||
type EsxiOptions struct {
|
||||
common_options.CommonOptions
|
||||
|
||||
ListenInterface string `help:"Master address of host server" default:"br0"`
|
||||
ListenAddress string `help:"Host serve IP address to select when multiple address bind to ListenInterface"`
|
||||
EsxiAgentPath string `default:"/opt/cloud/workspace/esxi_agent" help:"Path for esxi agent configuration files"`
|
||||
ImageCachePath string `help:"Path for storing image caches"`
|
||||
ImageCacheLimit int `help:"Maximal storage space for image caching, in GB" default:"20"`
|
||||
AgentTempPath string `help:"Path for ESXI Agent"`
|
||||
AgentTempLimit int `help:"Maximal storage space for ESXi agent, in GB" default:"20"`
|
||||
LinuxDefaultRootUser bool `help:"Default account for Linux system is root" default:"false"`
|
||||
WindowsDefaultAdminUser bool `help:"Default account for Windows system is Administrator" default:"true"`
|
||||
DefaultImageSaveFormat string `help:"Default image save format, default is vmdk, canbe qcow2" default:"vmdk"`
|
||||
Zone string `help:"Zone where the agent locates"`
|
||||
DeployServerSocketPath string `help:"Deploy server listen socket path" default:"/var/run/deploy.sock"`
|
||||
ListenInterface string `help:"Master address of host server" default:"br0"`
|
||||
ListenAddress string `help:"Host serve IP address to select when multiple address bind to ListenInterface"`
|
||||
EsxiAgentPath string `default:"/opt/cloud/workspace/esxi_agent" help:"Path for esxi agent configuration files"`
|
||||
ImageCachePath string `help:"Path for storing image caches"`
|
||||
ImageCacheLimit int `help:"Maximal storage space for image caching, in GB" default:"20"`
|
||||
AgentTempPath string `help:"Path for ESXI Agent"`
|
||||
AgentTempLimit int `help:"Maximal storage space for ESXi agent, in GB" default:"20"`
|
||||
LinuxDefaultRootUser bool `help:"Default account for Linux system is root" default:"false"`
|
||||
WindowsDefaultAdminUser bool `help:"Default account for Windows system is Administrator" default:"true"`
|
||||
DefaultImageSaveFormat string `help:"Default image save format, default is vmdk, canbe qcow2" default:"vmdk"`
|
||||
Zone string `help:"Zone where the agent locates"`
|
||||
DeployServerSocketPath string `help:"Deploy server listen socket path" default:"/var/run/deploy.sock"`
|
||||
HostDelayTaskWorkerCount int `default:"8" help:"Host delay worker thread count, default is 8"`
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/esxi/options"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestfs/fsdriver"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostdeployer/deployclient"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostutils"
|
||||
)
|
||||
|
||||
type SExsiAgentService struct {
|
||||
@@ -70,6 +71,7 @@ func (s *SExsiAgentService) StartService() {
|
||||
fsdriver.Init(nil)
|
||||
deployclient.Init(options.Options.DeployServerSocketPath)
|
||||
|
||||
hostutils.InitWorkerManagerWithCount(options.Options.HostDelayTaskWorkerCount)
|
||||
app := app_common.InitApp(&options.Options.BaseOptions, false)
|
||||
handler.InitHandlers(app)
|
||||
|
||||
|
||||
@@ -764,7 +764,7 @@ func (d *SUbuntuRootFs) GetReleaseInfo(rootFs IDiskPartition) *deployapi.Release
|
||||
lines := strings.Split(string(rel), "\n")
|
||||
for _, l := range lines {
|
||||
if strings.HasPrefix(l, distroKey) {
|
||||
version = strings.TrimSpace(l[len(distroKey) : len(l)-1])
|
||||
version = strings.TrimSpace(l[len(distroKey):])
|
||||
}
|
||||
}
|
||||
return deployapi.NewReleaseInfo(d.GetName(), version, d.GetArch(rootFs))
|
||||
|
||||
@@ -103,7 +103,7 @@ func (p *SKVMGuestDiskPartition) MountPartReadOnly() bool {
|
||||
|
||||
func (p *SKVMGuestDiskPartition) Mount() bool {
|
||||
if len(p.fs) == 0 || utils.IsInStringArray(p.fs, []string{"swap", "btrfs"}) {
|
||||
log.Errorf("Mount fs failed: %s", p.fs)
|
||||
log.Errorf("Mount fs failed: unsupport fs %s on %s", p.fs, p.partDev)
|
||||
return false
|
||||
}
|
||||
err := p.fsck()
|
||||
@@ -127,6 +127,7 @@ func (p *SKVMGuestDiskPartition) Mount() bool {
|
||||
p.readonly = true
|
||||
}
|
||||
}
|
||||
log.Infof("mount fs %s on %s success", p.fs, p.partDev)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -154,7 +155,21 @@ func (p *SKVMGuestDiskPartition) mount(readonly bool) error {
|
||||
cmds = append(cmds, "-o", opt)
|
||||
}
|
||||
cmds = append(cmds, p.partDev, p.mountPath)
|
||||
_, err := procutils.NewCommand(cmds[0], cmds[1:]...).Output()
|
||||
|
||||
var err error
|
||||
if fsType == "xfs" {
|
||||
uuids := fileutils2.GetDevUuid(p.partDev)
|
||||
uuid := uuids["UUID"]
|
||||
if len(uuid) > 0 {
|
||||
LockXfsPartition(uuid)
|
||||
defer func() {
|
||||
if err != nil {
|
||||
UnlockXfsPartition(uuid)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
_, err = procutils.NewCommand(cmds[0], cmds[1:]...).Output()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -217,6 +232,13 @@ func (p *SKVMGuestDiskPartition) Umount() bool {
|
||||
tries += 1
|
||||
_, err := procutils.NewCommand("umount", p.mountPath).Output()
|
||||
if err == nil {
|
||||
if p.fs == "xfs" {
|
||||
uuids := fileutils2.GetDevUuid(p.partDev)
|
||||
uuid := uuids["UUID"]
|
||||
if len(uuid) > 0 {
|
||||
UnlockXfsPartition(uuid)
|
||||
}
|
||||
}
|
||||
procutils.NewCommand("blockdev", "--flushbufs", p.partDev).Output()
|
||||
os.Remove(p.mountPath)
|
||||
return true
|
||||
|
||||
40
pkg/hostman/guestfs/utils.go
Normal file
40
pkg/hostman/guestfs/utils.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package guestfs
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"yunion.io/x/log"
|
||||
)
|
||||
|
||||
func LockXfsPartition(uuid string) {
|
||||
log.Infof("xfs lock %s", uuid)
|
||||
|
||||
var (
|
||||
xfsLock *sync.Mutex
|
||||
ok bool
|
||||
)
|
||||
|
||||
mapLock.Lock()
|
||||
xfsLock, ok = xfsMountUniqueTool[uuid]
|
||||
if !ok {
|
||||
xfsLock = new(sync.Mutex)
|
||||
xfsMountUniqueTool[uuid] = xfsLock
|
||||
}
|
||||
mapLock.Unlock()
|
||||
|
||||
xfsLock.Lock()
|
||||
}
|
||||
|
||||
func UnlockXfsPartition(uuid string) {
|
||||
log.Infof("xfs unlock %s", uuid)
|
||||
mapLock.Lock()
|
||||
xfsLock := xfsMountUniqueTool[uuid]
|
||||
mapLock.Unlock()
|
||||
|
||||
xfsLock.Unlock()
|
||||
}
|
||||
|
||||
var (
|
||||
mapLock = sync.Mutex{}
|
||||
xfsMountUniqueTool = map[string]*sync.Mutex{}
|
||||
)
|
||||
@@ -79,6 +79,11 @@ func (s *SKVMGuestInstance) getOsname() string {
|
||||
return osName
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) disableUsbKbd() bool {
|
||||
val, _ := s.Desc.GetString("metadata", "disable_usb_kbd")
|
||||
return val == "true"
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getOsDistribution() string {
|
||||
osDis, _ := s.Desc.GetString("metadata", "os_distribution")
|
||||
return osDis
|
||||
@@ -499,7 +504,7 @@ func (s *SKVMGuestInstance) _generateStartScript(data *jsonutils.JSONDict) (stri
|
||||
|
||||
cmd += " -device virtio-serial"
|
||||
cmd += " -usb"
|
||||
if !utils.IsInStringArray(s.getOsDistribution(), []string{OS_NAME_OPENWRT, OS_NAME_CIRROS}) {
|
||||
if !utils.IsInStringArray(s.getOsDistribution(), []string{OS_NAME_OPENWRT, OS_NAME_CIRROS}) && !s.disableUsbKbd() {
|
||||
cmd += " -device usb-kbd"
|
||||
}
|
||||
// # if osname == self.OS_NAME_ANDROID:
|
||||
|
||||
@@ -757,6 +757,7 @@ func (h *SHostInfo) tryCreateNetworkOnWire() {
|
||||
params.Set("mask", jsonutils.NewInt(int64(mask)))
|
||||
params.Set("is_on_premise", jsonutils.JSONTrue)
|
||||
params.Set("server_type", jsonutils.NewString(api.NETWORK_TYPE_BAREMETAL))
|
||||
params.Set("is_on_premise", jsonutils.JSONTrue)
|
||||
ret, err := modules.Networks.PerformClassAction(
|
||||
hostutils.GetComputeSession(context.Background()),
|
||||
"try-create-network", params)
|
||||
@@ -1295,6 +1296,9 @@ func (h *SHostInfo) onGetStorageInfoSucc(hoststorages []jsonutils.JSONObject) {
|
||||
|
||||
func (h *SHostInfo) uploadStorageInfo() {
|
||||
for _, s := range storageman.GetManager().Storages {
|
||||
if err := s.SetStorageInfo(s.GetId(), s.GetStorageName(), s.GetStorageConf()); err != nil {
|
||||
h.onFail(err)
|
||||
}
|
||||
res, err := s.SyncStorageInfo()
|
||||
if err != nil {
|
||||
h.onFail(err)
|
||||
|
||||
@@ -189,7 +189,11 @@ func DelayTaskWithWorker(
|
||||
}
|
||||
|
||||
func InitWorkerManager() {
|
||||
wm = workmanager.NewWorkManger(TaskFailed, TaskComplete, options.HostOptions.DefaultRequestWorkerCount)
|
||||
InitWorkerManagerWithCount(options.HostOptions.DefaultRequestWorkerCount)
|
||||
}
|
||||
|
||||
func InitWorkerManagerWithCount(count int) {
|
||||
wm = workmanager.NewWorkManger(TaskFailed, TaskComplete, count)
|
||||
}
|
||||
|
||||
func InitK8sWorkerManager() {
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostutils"
|
||||
"yunion.io/x/onecloud/pkg/hostman/options"
|
||||
"yunion.io/x/onecloud/pkg/hostman/storageman/remotefile"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
@@ -75,11 +74,11 @@ func (r *SRbdImageCache) Acquire(ctx context.Context, zone, srcUrl, format strin
|
||||
}
|
||||
r.imageName = localImageCache.GetName()
|
||||
if !r.Load() {
|
||||
log.Debugf("convert local image %s to rbd pool %s", r.imageId, r.Manager.GetPath())
|
||||
log.Infof("convert local image %s to rbd pool %s", r.imageId, r.Manager.GetPath())
|
||||
err := procutils.NewRemoteCommandAsFarAsPossible(qemutils.GetQemuImg(),
|
||||
"convert", "-O", "raw", localImageCache.GetPath(), r.GetPath()).Run()
|
||||
if err != nil {
|
||||
log.Errorf("failed to convert image %s", options.HostOptions.ServersPath)
|
||||
log.Errorf("failed to convert image %s", err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,12 +225,12 @@ func (c *SAgentImageCacheManager) perfetchTemplateVMImageCache(ctx context.Conte
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "host.GetDatacenter")
|
||||
}
|
||||
_, err = dc.GetTemplateVMById(data.ImageExternalId)
|
||||
_, err = dc.FetchTemplateVMById(data.ImageExternalId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := jsonutils.NewDict()
|
||||
res.Add(jsonutils.NewString(data.ImageId), "image_id")
|
||||
res.Add(jsonutils.NewString(data.ImageExternalId), "image_id")
|
||||
return res, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ func (c *SRbdImageCacheManager) PrefetchImageCache(ctx context.Context, data int
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
format := "qcow2"
|
||||
format, _ := body.GetString("format")
|
||||
srcUrl, _ := body.GetString("src_url")
|
||||
zone, _ := body.GetString("zone")
|
||||
|
||||
|
||||
@@ -262,6 +262,7 @@ func (s *SBaseStorage) bindMountTo(sPath string) error {
|
||||
return errors.Errorf("bind mount temp path to local image path failed %s", out)
|
||||
}
|
||||
}
|
||||
log.Infof("bind mount %s -> %s", tempPath, sPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ func storageVerifyMountPoint(ctx context.Context, w http.ResponseWriter, r *http
|
||||
hostutils.Response(ctx, w, httperrors.NewMissingParameterError("mount_point"))
|
||||
return
|
||||
}
|
||||
output, err := procutils.NewCommand("mountpoint", mountPoint).Output()
|
||||
output, err := procutils.NewRemoteCommandAsFarAsPossible("mountpoint", mountPoint).Output()
|
||||
if err == nil {
|
||||
appsrv.SendStruct(w, map[string]interface{}{"is_mount_point": true})
|
||||
} else {
|
||||
|
||||
@@ -603,6 +603,16 @@ func (self *SImage) ValidateUpdateData(ctx context.Context, userCred mcclient.To
|
||||
if appParams != nil && appParams.Request.ContentLength > 0 {
|
||||
return nil, httperrors.NewInvalidStatusError("cannot upload in status %s", self.Status)
|
||||
}
|
||||
if minDiskSize, err := data.Int("min_disk"); err == nil {
|
||||
img, err := qemuimg.NewQemuImage(self.getLocalLocation())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "open image")
|
||||
}
|
||||
virtualSizeMB := img.SizeBytes / 1024 / 1024
|
||||
if virtualSizeMB > 0 && minDiskSize < virtualSizeMB {
|
||||
return nil, httperrors.NewBadRequestError("min disk size must >= %v", virtualSizeMB)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
appParams := appsrv.AppContextGetParams(ctx)
|
||||
if appParams != nil {
|
||||
@@ -654,7 +664,6 @@ func (self *SImage) ValidateUpdateData(ctx context.Context, userCred mcclient.To
|
||||
return nil, errors.Wrap(err, "SSharableVirtualResourceBase.ValidateUpdateData")
|
||||
}
|
||||
data.Update(jsonutils.Marshal(input))
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -261,9 +261,9 @@ func (policy *SPolicy) Delete(ctx context.Context, userCred mcclient.TokenCreden
|
||||
}
|
||||
|
||||
func (policy *SPolicy) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if policy.IsShared() {
|
||||
return httperrors.NewInvalidStatusError("cannot delete shared policy")
|
||||
}
|
||||
// if policy.IsShared() {
|
||||
// return httperrors.NewInvalidStatusError("cannot delete shared policy")
|
||||
// }
|
||||
if policy.Enabled.IsTrue() {
|
||||
return httperrors.NewInvalidStatusError("cannot delete enabled policy")
|
||||
}
|
||||
|
||||
@@ -188,9 +188,9 @@ func (role *SRole) IsSystemRole() bool {
|
||||
}
|
||||
|
||||
func (role *SRole) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if role.IsShared() {
|
||||
return httperrors.NewInvalidStatusError("cannot delete shared role")
|
||||
}
|
||||
// if role.IsShared() {
|
||||
// return httperrors.NewInvalidStatusError("cannot delete shared role")
|
||||
// }
|
||||
if role.IsSystemRole() {
|
||||
return httperrors.NewForbiddenError("cannot delete system role")
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func (self *SClassicStorage) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (self *SClassicStorage) IsEmulated() bool {
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SClassicStorage) GetIZone() cloudprovider.ICloudZone {
|
||||
|
||||
@@ -18,6 +18,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/view"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
|
||||
@@ -237,32 +239,85 @@ func (dc *SDatacenter) getDcObj() *object.Datacenter {
|
||||
return object.NewDatacenter(dc.manager.client.Client, dc.object.Reference())
|
||||
}
|
||||
|
||||
// fetchVms will identify if VM is a template and return two different arrays; the latter contains all template vms.
|
||||
func (dc *SDatacenter) fetchVms(vmRefs []types.ManagedObjectReference, all bool) ([]cloudprovider.ICloudVM, []*SVirtualMachine, error) {
|
||||
var vms []mo.VirtualMachine
|
||||
func (dc *SDatacenter) fetchVms(vmRefs []types.ManagedObjectReference, all bool) ([]*SVirtualMachine, error) {
|
||||
var movms []mo.VirtualMachine
|
||||
if vmRefs != nil {
|
||||
err := dc.manager.references2Objects(vmRefs, VIRTUAL_MACHINE_PROPS, &vms)
|
||||
err := dc.manager.references2Objects(vmRefs, VIRTUAL_MACHINE_PROPS, &movms)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "dc.manager.references2Objects")
|
||||
return nil, errors.Wrap(err, "dc.manager.references2Objects")
|
||||
}
|
||||
}
|
||||
|
||||
// avoid applying new memory and copying
|
||||
retVms := make([]cloudprovider.ICloudVM, 0, len(vms)/2)
|
||||
templateVMs := make([]*SVirtualMachine, 0, 2)
|
||||
for i := 0; i < len(vms); i += 1 {
|
||||
if all || !strings.HasPrefix(vms[i].Entity().Name, api.ESXI_IMAGE_CACHE_TMP_PREFIX) {
|
||||
vmObj := NewVirtualMachine(dc.manager, &vms[i], dc)
|
||||
if vms[i].Config != nil && vms[i].Config.Template {
|
||||
templateVMs = append(templateVMs, vmObj)
|
||||
continue
|
||||
}
|
||||
if vmObj != nil {
|
||||
retVms = append(retVms, vmObj)
|
||||
}
|
||||
vms := make([]*SVirtualMachine, 0, len(movms))
|
||||
for i := range movms {
|
||||
if all || !strings.HasPrefix(movms[i].Entity().Name, api.ESXI_IMAGE_CACHE_TMP_PREFIX) {
|
||||
vms = append(vms, NewVirtualMachine(dc.manager, &movms[i], dc))
|
||||
}
|
||||
}
|
||||
return retVms, templateVMs, nil
|
||||
return vms, nil
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) FetchVMs() ([]*SVirtualMachine, error) {
|
||||
return dc.fetchVMs(property.Filter{})
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) FetchNoTemplateVMs() ([]*SVirtualMachine, error) {
|
||||
filter := property.Filter{}
|
||||
filter["config.template"] = false
|
||||
return dc.fetchVMs(filter)
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) fetchVMs(filter property.Filter) ([]*SVirtualMachine, error) {
|
||||
odc := dc.getObjectDatacenter()
|
||||
root := odc.Reference()
|
||||
m := view.NewManager(dc.manager.client.Client)
|
||||
v, err := m.CreateContainerView(dc.manager.context, root, []string{"VirtualMachine"}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
_ = v.Destroy(dc.manager.context)
|
||||
}()
|
||||
objs, err := v.Find(dc.manager.context, []string{"VirtualMachine"}, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vms, err := dc.fetchVms(objs, false)
|
||||
return vms, err
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) FetchTemplateVMs() ([]*SVirtualMachine, error) {
|
||||
filter := property.Filter{}
|
||||
filter["config.template"] = true
|
||||
return dc.fetchVMs(filter)
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) FetchTemplateVMById(id string) (*SVirtualMachine, error) {
|
||||
filter := property.Filter{}
|
||||
filter["config.template"] = true
|
||||
filter["summary.config.uuid"] = id
|
||||
vms, err := dc.fetchVMs(filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(vms) == 0 {
|
||||
return nil, errors.ErrNotFound
|
||||
}
|
||||
return vms[0], nil
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) FetchVMById(id string) (*SVirtualMachine, error) {
|
||||
filter := property.Filter{}
|
||||
filter["summary.config.uuid"] = id
|
||||
vms, err := dc.fetchVMs(filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(vms) == 0 {
|
||||
return nil, errors.ErrNotFound
|
||||
}
|
||||
return vms[0], nil
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) fetchDatastores(datastoreRefs []types.ManagedObjectReference) ([]cloudprovider.ICloudStorage, error) {
|
||||
@@ -381,24 +436,3 @@ func (dc *SDatacenter) GetTemplateVMs() ([]*SVirtualMachine, error) {
|
||||
}
|
||||
return templateVms, nil
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) GetTemplateVMById(id string) (*SVirtualMachine, error) {
|
||||
id = dc.manager.getPrivateId(id)
|
||||
hosts, err := dc.GetIHosts()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SDatacenter.GetIHosts")
|
||||
}
|
||||
for _, ihost := range hosts {
|
||||
host := ihost.(*SHost)
|
||||
tvms, err := host.GetTemplateVMs()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "host.GetTemplateVMs")
|
||||
}
|
||||
for i := range tvms {
|
||||
if tvms[i].GetGlobalId() == id {
|
||||
return tvms[i], nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
@@ -179,6 +179,7 @@ func (self *SHost) fetchVMs(all bool) error {
|
||||
}
|
||||
|
||||
MAX_TRIES := 3
|
||||
var vms []*SVirtualMachine
|
||||
for tried := 0; tried < MAX_TRIES; tried += 1 {
|
||||
hostVms := self.getHostSystem().Vm
|
||||
if len(hostVms) == 0 {
|
||||
@@ -186,15 +187,20 @@ func (self *SHost) fetchVMs(all bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
vms, templatevms, err := dc.fetchVms(hostVms, all)
|
||||
vms, err = dc.fetchVms(hostVms, all)
|
||||
if err != nil {
|
||||
log.Errorf("dc.fetchVms fail %s", err)
|
||||
time.Sleep(time.Second)
|
||||
self.Refresh()
|
||||
continue
|
||||
}
|
||||
self.vms = vms
|
||||
self.tempalteVMs = templatevms
|
||||
}
|
||||
for _, vm := range vms {
|
||||
if vm.IsTemplate() {
|
||||
self.tempalteVMs = append(self.tempalteVMs, vm)
|
||||
} else {
|
||||
self.vms = append(self.vms, vm)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -684,9 +690,13 @@ func (self *SHost) CreateVM2(ctx context.Context, ds *SDatastore, params SCreate
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SEsxiClient.FindHostByIp")
|
||||
}
|
||||
temvm, err := imgHost.GetTemplateVMById(imageInfo.ImageExternalId)
|
||||
dc, err := imgHost.GetDatacenter()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHost.GetTemplateVMById")
|
||||
return nil, errors.Wrap(err, "host.GetDatacenter")
|
||||
}
|
||||
temvm, err := dc.FetchTemplateVMById(imageInfo.ImageExternalId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "datacenter.TemplateVMById for image %q and datacenter %q", imageInfo.ImageExternalId, dc.GetId())
|
||||
}
|
||||
return self.CloneVM(ctx, temvm, ds, params)
|
||||
}
|
||||
|
||||
@@ -27,28 +27,53 @@ import (
|
||||
|
||||
func init() {
|
||||
type VirtualMachineListOptions struct {
|
||||
HOSTIP string `help:"Host IP"`
|
||||
Template bool `help:"Whether it is tempalte virtual machine"`
|
||||
Datacenter string `help:"Datacenter"`
|
||||
HostIP string `help:"HostIP"`
|
||||
Template bool `help:"Whether it is tempalte virtual machine, default:false"`
|
||||
}
|
||||
shellutils.R(&VirtualMachineListOptions{}, "vm-list", "List vms of a host", func(cli *esxi.SESXiClient, args *VirtualMachineListOptions) error {
|
||||
host, err := cli.FindHostByIp(args.HOSTIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if args.Template {
|
||||
vms, err := host.GetTemplateVMs()
|
||||
switch {
|
||||
case len(args.HostIP) > 0:
|
||||
host, err := cli.FindHostByIp(args.HostIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if args.Template {
|
||||
vms, err := host.GetTemplateVMs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(vms, []string{})
|
||||
return nil
|
||||
}
|
||||
vms, err := host.GetIVMs2()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(vms, []string{})
|
||||
return nil
|
||||
case len(args.Datacenter) > 0:
|
||||
dc, err := cli.FindDatacenterByMoId(args.Datacenter)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "FindDatacenterByMoId")
|
||||
}
|
||||
var vms []*esxi.SVirtualMachine
|
||||
if args.Template {
|
||||
vms, err = dc.FetchTemplateVMs()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "FetchTemplateVMs")
|
||||
}
|
||||
} else {
|
||||
vms, err = dc.FetchNoTemplateVMs()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "FetchNoTemplateVMs")
|
||||
}
|
||||
}
|
||||
printList(vms, []string{})
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("Both Datacenter and HostIP cannot be empty")
|
||||
}
|
||||
vms, err := host.GetIVMs2()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(vms, []string{})
|
||||
return nil
|
||||
})
|
||||
|
||||
type VirtualMachineCloneOptions struct {
|
||||
@@ -91,24 +116,45 @@ func init() {
|
||||
})
|
||||
|
||||
type VirtualMachineShowOptions struct {
|
||||
HOSTIP string `help:"Host IP"`
|
||||
VMID string `help:"VM ID"`
|
||||
Template bool
|
||||
Datacenter string `help:"Datacenter"`
|
||||
HostIP string `help:"Host IP"`
|
||||
VMID string `help:"VM ID"`
|
||||
}
|
||||
getVM := func(cli *esxi.SESXiClient, args *VirtualMachineShowOptions) (*esxi.SVirtualMachine, error) {
|
||||
var vm *esxi.SVirtualMachine
|
||||
switch {
|
||||
case len(args.HostIP) > 0:
|
||||
host, err := cli.FindHostByIp(args.HostIP)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "FindHostByIp")
|
||||
}
|
||||
ivm, err := host.GetIVMById(args.VMID)
|
||||
if err != nil && errors.Cause(err) != errors.ErrNotFound {
|
||||
return nil, err
|
||||
}
|
||||
if err != nil {
|
||||
vm, err = host.GetTemplateVMById(args.VMID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetTemplateVMById")
|
||||
}
|
||||
}
|
||||
vm = ivm.(*esxi.SVirtualMachine)
|
||||
case len(args.Datacenter) > 0:
|
||||
dc, err := cli.FindDatacenterByMoId(args.Datacenter)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "FindDatacenterByMoId")
|
||||
}
|
||||
vm, err = dc.FetchVMById(args.VMID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "FetchVMById")
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("Both Datacenter and HostIP cannot be empty")
|
||||
}
|
||||
return vm, nil
|
||||
}
|
||||
shellutils.R(&VirtualMachineShowOptions{}, "vm-show", "Show vm details", func(cli *esxi.SESXiClient, args *VirtualMachineShowOptions) error {
|
||||
host, err := cli.FindHostByIp(args.HOSTIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if args.Template {
|
||||
vm, err := host.GetTemplateVMById(args.VMID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(vm)
|
||||
return nil
|
||||
}
|
||||
vm, err := host.GetIVMById(args.VMID)
|
||||
vm, err := getVM(cli, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -117,11 +163,7 @@ func init() {
|
||||
})
|
||||
|
||||
shellutils.R(&VirtualMachineShowOptions{}, "vm-nics", "Show vm nics details", func(cli *esxi.SESXiClient, args *VirtualMachineShowOptions) error {
|
||||
host, err := cli.FindHostByIp(args.HOSTIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vm, err := host.GetIVMById(args.VMID)
|
||||
vm, err := getVM(cli, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -134,11 +176,7 @@ func init() {
|
||||
})
|
||||
|
||||
shellutils.R(&VirtualMachineShowOptions{}, "vm-disks", "Show vm disks details", func(cli *esxi.SESXiClient, args *VirtualMachineShowOptions) error {
|
||||
host, err := cli.FindHostByIp(args.HOSTIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vm, err := host.GetIVMById(args.VMID)
|
||||
vm, err := getVM(cli, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -151,17 +189,12 @@ func init() {
|
||||
})
|
||||
|
||||
type VirtualMachineDiskResizeOptions struct {
|
||||
HOSTIP string `help:"host ip"`
|
||||
VMID string `help:"virtual machine UUID"`
|
||||
DISKIDX int `help:"disk index"`
|
||||
SIZEGB int64 `help:"new size of disk"`
|
||||
VirtualMachineShowOptions
|
||||
DISKIDX int `help:"disk index"`
|
||||
SIZEGB int64 `help:"new size of disk"`
|
||||
}
|
||||
shellutils.R(&VirtualMachineDiskResizeOptions{}, "vm-disk-resize", "Resize a vm disk", func(cli *esxi.SESXiClient, args *VirtualMachineDiskResizeOptions) error {
|
||||
host, err := cli.FindHostByIp(args.HOSTIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vm, err := host.GetIVMById(args.VMID)
|
||||
vm, err := getVM(cli, &args.VirtualMachineShowOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -178,11 +211,7 @@ func init() {
|
||||
})
|
||||
|
||||
shellutils.R(&VirtualMachineShowOptions{}, "vm-vnc", "Show vm VNC details", func(cli *esxi.SESXiClient, args *VirtualMachineShowOptions) error {
|
||||
host, err := cli.FindHostByIp(args.HOSTIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vm, err := host.GetIVMById(args.VMID)
|
||||
vm, err := getVM(cli, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -195,15 +224,11 @@ func init() {
|
||||
})
|
||||
|
||||
shellutils.R(&VirtualMachineShowOptions{}, "vm-file-status", "Show vm files details", func(cli *esxi.SESXiClient, args *VirtualMachineShowOptions) error {
|
||||
host, err := cli.FindHostByIp(args.HOSTIP)
|
||||
vm, err := getVM(cli, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vm, err := host.GetIVMById(args.VMID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = vm.(*esxi.SVirtualMachine).CheckFileInfo(context.Background())
|
||||
err = vm.CheckFileInfo(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -259,7 +259,14 @@ func (self *SDatastore) getVMs() ([]cloudprovider.ICloudVM, error) {
|
||||
if len(vms) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
ret, _, err := dc.fetchVms(vms, false)
|
||||
svms, err := dc.fetchVms(vms, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := make([]cloudprovider.ICloudVM, len(svms))
|
||||
for i := range svms {
|
||||
ret[i] = svms[i]
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -77,15 +78,31 @@ func (self *SDatastoreImageCache) GetPath() string {
|
||||
|
||||
func (self *SDatastoreImageCache) GetIImages() ([]cloudprovider.ICloudImage, error) {
|
||||
ctx := context.Background()
|
||||
ret := make([]cloudprovider.ICloudImage, 0, 2)
|
||||
|
||||
// get vm template with only one disk
|
||||
tems, err := self.host.GetTemplateVMs()
|
||||
if err != nil {
|
||||
log.Errorf("fail to get templateVMs of host '%s' in SDatastoreImageCache.GetIImages", self.host.GetName())
|
||||
return ret, nil
|
||||
}
|
||||
for _, tem := range tems {
|
||||
// for now, add vm template with only one disk as cachedimage
|
||||
if len(tem.vdisks) != 1 {
|
||||
continue
|
||||
}
|
||||
ret = append(ret, NewVMTemplate(tem, self))
|
||||
}
|
||||
|
||||
files, err := self.datastore.ListDir(ctx, IMAGE_CACHE_DIR_NAME)
|
||||
if errors.Cause(err) == errors.ErrNotFound {
|
||||
return ret, nil
|
||||
}
|
||||
if err != nil {
|
||||
log.Errorf("GetIImages ListDir fail %s", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := make([]cloudprovider.ICloudImage, 0)
|
||||
|
||||
validFilenames := make(map[string]bool)
|
||||
|
||||
for i := 0; i < len(files); i += 1 {
|
||||
@@ -119,20 +136,6 @@ func (self *SDatastoreImageCache) GetIImages() ([]cloudprovider.ICloudImage, err
|
||||
}
|
||||
}
|
||||
|
||||
// get vm template with only one disk
|
||||
tems, err := self.host.GetTemplateVMs()
|
||||
if err != nil {
|
||||
log.Errorf("fail to get templateVMs of host '%s' in SDatastoreImageCache.GetIImages", self.host.GetName())
|
||||
return ret, nil
|
||||
}
|
||||
for _, tem := range tems {
|
||||
// for now, add vm template with only one disk as cachedimage
|
||||
if len(tem.vdisks) != 1 {
|
||||
continue
|
||||
}
|
||||
ret = append(ret, NewVMTemplate(tem, self))
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -72,10 +72,7 @@ func (d byDiskType) Less(i, j int) bool {
|
||||
|
||||
func NewVirtualMachine(manager *SESXiClient, vm *mo.VirtualMachine, dc *SDatacenter) *SVirtualMachine {
|
||||
svm := &SVirtualMachine{SManagedObject: newManagedObject(manager, vm, dc)}
|
||||
err := svm.fetchHardwareInfo()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
svm.fetchHardwareInfo()
|
||||
return svm
|
||||
}
|
||||
|
||||
@@ -708,7 +705,7 @@ func (self *SVirtualMachine) UpdateUserData(userData string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVirtualMachine) fetchHardwareInfo() error {
|
||||
func (self *SVirtualMachine) fetchHardwareInfo() {
|
||||
self.vnics = make([]SVirtualNIC, 0)
|
||||
self.vdisks = make([]SVirtualDisk, 0)
|
||||
self.cdroms = make([]SVirtualCdrom, 0)
|
||||
@@ -722,7 +719,8 @@ func (self *SVirtualMachine) fetchHardwareInfo() error {
|
||||
}
|
||||
|
||||
if moVM == nil || moVM.Config == nil || moVM.Config.Hardware.Device == nil {
|
||||
return errors.Error("invalid vm config")
|
||||
log.Errorf("invalid vm config, moVM: %v", moVM)
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < len(moVM.Config.Hardware.Device); i += 1 {
|
||||
@@ -750,7 +748,6 @@ func (self *SVirtualMachine) fetchHardwareInfo() error {
|
||||
sort.Slice(self.vdisks, func(i, j int) bool {
|
||||
return self.vdisks[i].GetIndex() < self.vdisks[j].GetIndex()
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVirtualMachine) getVdev(key int32) SVirtualDevice {
|
||||
@@ -1218,3 +1215,8 @@ func (self *SVirtualMachine) FindMinDiffKey(limit int32) int32 {
|
||||
}
|
||||
return limit
|
||||
}
|
||||
|
||||
func (self *SVirtualMachine) IsTemplate() bool {
|
||||
movm := self.getVirtualMachine()
|
||||
return movm.Config != nil && movm.Config.Template
|
||||
}
|
||||
|
||||
@@ -141,17 +141,13 @@ func (ce *HuaweiClientError) Error() string {
|
||||
}
|
||||
|
||||
func (ce *HuaweiClientError) ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error {
|
||||
err := body.Unmarshal(ce)
|
||||
if err != nil {
|
||||
ce.err = errors.Wrapf(err, "body.Unmarshal(%s)", body.String())
|
||||
ce.Code = statusCode
|
||||
ce.Details = body.String()
|
||||
return ce
|
||||
if body != nil {
|
||||
body.Unmarshal(ce)
|
||||
}
|
||||
if ce.Code == 0 {
|
||||
ce.Code = statusCode
|
||||
}
|
||||
if len(ce.Details) == 0 {
|
||||
if len(ce.Details) == 0 && body != nil {
|
||||
ce.Details = body.String()
|
||||
}
|
||||
return ce
|
||||
@@ -182,10 +178,6 @@ func (self *SBaseManager) jsonRequest(request requests.IRequest) (http.Header, j
|
||||
}
|
||||
}
|
||||
|
||||
if self.debug {
|
||||
log.Debugf("url: %s", request.BuildUrl())
|
||||
}
|
||||
|
||||
client := httputils.NewJsonClient(self.httpClient)
|
||||
req := httputils.NewJsonRequest(httputils.THttpMethod(request.GetMethod()), request.BuildUrl(), jsonBody)
|
||||
req.SetHeader(header)
|
||||
@@ -196,12 +188,11 @@ func (self *SBaseManager) jsonRequest(request requests.IRequest) (http.Header, j
|
||||
for {
|
||||
h, b, e := client.Send(ctx, req, resp, self.debug)
|
||||
if e == nil {
|
||||
if self.debug {
|
||||
log.Debugf("response: %s body: %s", h, b)
|
||||
}
|
||||
return h, b, e
|
||||
return h, b, nil
|
||||
}
|
||||
|
||||
log.Errorf("[%s] %s body: %v error: %v", req.GetHttpMethod(), req.GetUrl(), jsonBody, e)
|
||||
|
||||
switch err := e.(type) {
|
||||
case *HuaweiClientError:
|
||||
if (err.Code == 499 || err.Code == 429) && retry > 0 && request.GetMethod() == "GET" {
|
||||
|
||||
@@ -537,16 +537,19 @@ func (self *SRegion) CreateISecurityGroup(conf *cloudprovider.SecurityGroupCreat
|
||||
|
||||
// https://support.huaweicloud.com/api-vpc/zh-cn_topic_0020090608.html
|
||||
func (self *SRegion) CreateIVpc(name string, desc string, cidr string) (cloudprovider.ICloudVpc, error) {
|
||||
params := jsonutils.NewDict()
|
||||
vpcObj := jsonutils.NewDict()
|
||||
vpcObj.Add(jsonutils.NewString(name), "name")
|
||||
vpcObj.Add(jsonutils.NewString(cidr), "cidr")
|
||||
params.Add(vpcObj, "vpc")
|
||||
return self.CreateVpc(name, cidr, desc)
|
||||
}
|
||||
|
||||
vpc := SVpc{}
|
||||
err := DoCreate(self.ecsClient.Vpcs.Create, params, &vpc)
|
||||
vpc.region = self
|
||||
return &vpc, err
|
||||
func (self *SRegion) CreateVpc(name, cidr, desc string) (*SVpc, error) {
|
||||
params := map[string]interface{}{
|
||||
"vpc": map[string]string{
|
||||
"name": name,
|
||||
"cidr": cidr,
|
||||
"description": desc,
|
||||
},
|
||||
}
|
||||
vpc := &SVpc{region: self}
|
||||
return vpc, DoCreate(self.ecsClient.Vpcs.Create, jsonutils.Marshal(params), vpc)
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-vpc/zh-cn_topic_0020090596.html
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/secrules"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -227,7 +228,7 @@ func (self *SRegion) GetSecurityGroupDetails(secGroupId string) (*SSecurityGroup
|
||||
// https://support.huaweicloud.com/api-vpc/zh-cn_topic_0020090617.html
|
||||
func (self *SRegion) GetSecurityGroups(vpcId string, name string) ([]SSecurityGroup, error) {
|
||||
querys := map[string]string{}
|
||||
if len(vpcId) > 0 {
|
||||
if len(vpcId) > 0 && !utils.IsInStringArray(vpcId, []string{"default", api.NORMAL_VPC_ID}) { // vpc_id = default or normal 时报错 '{"code":"VPC.0601","message":"Query security groups error vpcId is invalid."}'
|
||||
querys["vpc_id"] = vpcId
|
||||
}
|
||||
|
||||
|
||||
@@ -30,4 +30,28 @@ func init() {
|
||||
printList(vpcs, 0, 0, 0, nil)
|
||||
return nil
|
||||
})
|
||||
|
||||
type VpcCreateOptions struct {
|
||||
NAME string
|
||||
CIDR string
|
||||
Desc string
|
||||
}
|
||||
|
||||
shellutils.R(&VpcCreateOptions{}, "vpc-create", "Create vpc", func(cli *huawei.SRegion, args *VpcCreateOptions) error {
|
||||
vpc, err := cli.CreateVpc(args.NAME, args.CIDR, args.Desc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(vpc)
|
||||
return nil
|
||||
})
|
||||
|
||||
type VpcIdOption struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
shellutils.R(&VpcIdOption{}, "vpc-delete", "Delete vpc", func(cli *huawei.SRegion, args *VpcIdOption) error {
|
||||
return cli.DeleteVpc(args.ID)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -225,6 +225,18 @@ func (self *SRegion) getVpc(vpcId string) (*SVpc, error) {
|
||||
}
|
||||
|
||||
func (self *SRegion) DeleteVpc(vpcId string) error {
|
||||
if vpcId != "default" {
|
||||
secgroups, err := self.GetSecurityGroups(vpcId, "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "GetSecurityGroups")
|
||||
}
|
||||
for _, secgroup := range secgroups {
|
||||
err = self.DeleteSecurityGroup(secgroup.ID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "DeleteSecurityGroup(%s)", secgroup.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return DoDelete(self.ecsClient.Vpcs.Delete, vpcId, nil, nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ func (host *SHypervisor) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
func (host *SHypervisor) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
istorages := []cloudprovider.ICloudStorage{}
|
||||
storages, err := host.zone.region.GetStorageTypes()
|
||||
if err != nil {
|
||||
if err != nil && errors.Cause(err) != ErrNoEndpoint {
|
||||
return nil, errors.Wrap(err, "GetStorageTypes")
|
||||
}
|
||||
for i := range storages {
|
||||
@@ -148,7 +148,12 @@ func (host *SHypervisor) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (c
|
||||
}
|
||||
|
||||
func (host *SHypervisor) GetEnabled() bool {
|
||||
return true
|
||||
switch host.Status {
|
||||
case "enabled", "":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (host *SHypervisor) GetAccessIp() string {
|
||||
@@ -266,9 +271,6 @@ func (host *SHypervisor) GetHostType() string {
|
||||
}
|
||||
|
||||
func (host *SHypervisor) GetHostStatus() string {
|
||||
if host.Status == "disabled" {
|
||||
return api.HOST_OFFLINE
|
||||
}
|
||||
switch host.State {
|
||||
case "up", "":
|
||||
return api.HOST_ONLINE
|
||||
@@ -282,12 +284,7 @@ func (host *SHypervisor) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface,
|
||||
}
|
||||
|
||||
func (host *SHypervisor) GetIsMaintenance() bool {
|
||||
switch host.Status {
|
||||
case "enabled", "":
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (host *SHypervisor) GetVersion() string {
|
||||
|
||||
@@ -45,6 +45,8 @@ const (
|
||||
OPENSTACK_SERVICE_VOLUMEV2 = "volumev2"
|
||||
OPENSTACK_SERVICE_VOLUME = "volume"
|
||||
OPENSTACK_SERVICE_IMAGE = "image"
|
||||
|
||||
ErrNoEndpoint = errors.Error("no valid endpoint")
|
||||
)
|
||||
|
||||
type OpenstackClientConfig struct {
|
||||
@@ -159,11 +161,13 @@ type OpenstackError struct {
|
||||
}
|
||||
|
||||
func (ce *OpenstackError) ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error {
|
||||
body.Unmarshal(ce)
|
||||
if body != nil {
|
||||
body.Unmarshal(ce)
|
||||
}
|
||||
if ce.Code == 0 {
|
||||
ce.Code = statusCode
|
||||
}
|
||||
if len(ce.Details) == 0 {
|
||||
if len(ce.Details) == 0 && body != nil {
|
||||
ce.Details = body.String()
|
||||
}
|
||||
if len(ce.Class) == 0 {
|
||||
@@ -250,12 +254,20 @@ func jsonReuest(token mcclient.TokenCredential, service, region, endpointType st
|
||||
}
|
||||
}
|
||||
|
||||
requestUrl := resource
|
||||
if !strings.HasPrefix(resource, serviceUrl) {
|
||||
requestUrl = fmt.Sprintf("%s/%s", serviceUrl, resource)
|
||||
if service == OPENSTACK_SERVICE_IDENTITY {
|
||||
if strings.HasSuffix(serviceUrl, "/v3/") {
|
||||
serviceUrl = strings.TrimSuffix(serviceUrl, "/v3/")
|
||||
} else if strings.HasSuffix(serviceUrl, "/v3") {
|
||||
serviceUrl = strings.TrimSuffix(serviceUrl, "/v3")
|
||||
}
|
||||
}
|
||||
|
||||
if query != nil {
|
||||
requestUrl := resource
|
||||
if !strings.HasPrefix(resource, serviceUrl) {
|
||||
requestUrl = fmt.Sprintf("%s/%s", strings.TrimSuffix(serviceUrl, "/"), strings.TrimPrefix(resource, "/"))
|
||||
}
|
||||
|
||||
if query != nil && len(query) > 0 {
|
||||
requestUrl = fmt.Sprintf("%s?%s", requestUrl, query.Encode())
|
||||
}
|
||||
|
||||
@@ -327,7 +339,7 @@ func (cli *SOpenStackClient) bsRequest(region string, method httputils.THttpMeth
|
||||
return jsonReuest(cli.tokenCredential, service, region, cli.endpointType, method, resource, query, body, cli.debug)
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("no valid volume service endpoint")
|
||||
return nil, errors.Wrap(ErrNoEndpoint, "cinder service")
|
||||
}
|
||||
|
||||
func (cli *SOpenStackClient) bsCreate(projectId, region, resource string, body interface{}) (jsonutils.JSONObject, error) {
|
||||
@@ -345,7 +357,7 @@ func (cli *SOpenStackClient) bsCreate(projectId, region, resource string, body i
|
||||
return jsonReuest(token, service, region, cli.endpointType, httputils.POST, resource, nil, body, cli.debug)
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("no valid volume service endpoint")
|
||||
return nil, errors.Wrap(ErrNoEndpoint, "cinder service")
|
||||
}
|
||||
|
||||
func (cli *SOpenStackClient) imageUpload(region, url string, body io.Reader) (*http.Response, error) {
|
||||
|
||||
@@ -112,7 +112,7 @@ func (zone *SZone) getStorageByCategory(category, host string) (*SStorage, error
|
||||
|
||||
func (zone *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
storages, err := zone.region.GetStorageTypes()
|
||||
if err != nil {
|
||||
if err != nil && errors.Cause(err) != ErrNoEndpoint {
|
||||
return nil, errors.Wrap(err, "GetStorageTypes")
|
||||
}
|
||||
istorages := []cloudprovider.ICloudStorage{}
|
||||
|
||||
@@ -59,7 +59,7 @@ type ZstackClientConfig struct {
|
||||
|
||||
func NewZstackClientConfig(authURL, username, password string) *ZstackClientConfig {
|
||||
cfg := &ZstackClientConfig{
|
||||
authURL: authURL,
|
||||
authURL: strings.TrimSuffix(authURL, "/"),
|
||||
username: username,
|
||||
password: password,
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/signalutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/webconsole"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
@@ -66,9 +67,15 @@ func StartService() {
|
||||
|
||||
common_options.StartOptionManager(opts, opts.ConfigSyncPeriodSeconds, api.SERVICE_TYPE, api.SERVICE_VERSION, o.OnOptionsChange)
|
||||
|
||||
registerSigTraps()
|
||||
start()
|
||||
}
|
||||
|
||||
func registerSigTraps() {
|
||||
signalutils.SetDumpStackSignal()
|
||||
signalutils.StartTrap()
|
||||
}
|
||||
|
||||
func start() {
|
||||
baseOpts := &o.Options.BaseOptions
|
||||
// commonOpts := &o.Options.CommonOptions
|
||||
|
||||
@@ -102,6 +102,10 @@ func (p *Pty) Resize(size *pty.Winsize) {
|
||||
func (p *Pty) Stop() (err error) {
|
||||
var errs []error
|
||||
|
||||
defer func() {
|
||||
p.Cmd, p.Pty = nil, nil
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
err = errors.NewAggregate(errs)
|
||||
}()
|
||||
@@ -139,8 +143,5 @@ func (p *Pty) Stop() (err error) {
|
||||
}
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
p.Cmd, p.Pty = nil, nil
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
6
vendor/modules.txt
vendored
6
vendor/modules.txt
vendored
@@ -993,12 +993,12 @@ sigs.k8s.io/yaml
|
||||
yunion.io/x/executor/apis
|
||||
yunion.io/x/executor/client
|
||||
yunion.io/x/executor/server
|
||||
# yunion.io/x/jsonutils v0.0.0-20200710080709-7ca71cdb9383
|
||||
# yunion.io/x/jsonutils v0.0.0-20200814075449-927b118adbd8
|
||||
yunion.io/x/jsonutils
|
||||
# yunion.io/x/log v0.0.0-20200313080802-57a4ce5966b3
|
||||
yunion.io/x/log
|
||||
yunion.io/x/log/hooks
|
||||
# yunion.io/x/pkg v0.0.0-20200713121502-18154120c49b
|
||||
# yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6
|
||||
yunion.io/x/pkg/errors
|
||||
yunion.io/x/pkg/gotypes
|
||||
yunion.io/x/pkg/prettytable
|
||||
@@ -1031,7 +1031,7 @@ yunion.io/x/pkg/util/workqueue
|
||||
yunion.io/x/pkg/utils
|
||||
# yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
yunion.io/x/s3cli
|
||||
# yunion.io/x/sqlchemy v0.0.0-20200702064124-195445bc4b11
|
||||
# yunion.io/x/sqlchemy v0.0.0-20200814052348-164f1f20f8a6
|
||||
yunion.io/x/sqlchemy
|
||||
# yunion.io/x/structarg v0.0.0-20200720093445-9f850fa222ce
|
||||
yunion.io/x/structarg
|
||||
|
||||
2
vendor/yunion.io/x/jsonutils/.gitignore
generated
vendored
2
vendor/yunion.io/x/jsonutils/.gitignore
generated
vendored
@@ -11,3 +11,5 @@
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
.idea
|
||||
|
||||
out.gotext.json
|
||||
|
||||
6
vendor/yunion.io/x/jsonutils/errors.go
generated
vendored
6
vendor/yunion.io/x/jsonutils/errors.go
generated
vendored
@@ -6,7 +6,7 @@ import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
const (
|
||||
ErrJsonDictFailInsert = errors.Error("fail to insert object")
|
||||
|
||||
ErrInvalidJsonDict = errors.Error("not a valid JSONDict")
|
||||
@@ -31,8 +31,8 @@ var (
|
||||
ErrInterfaceUnsupported = errors.Error("do not known how to deserialize json into this interface type")
|
||||
ErrMapKeyMustString = errors.Error("map key must be string")
|
||||
|
||||
ErrMisingInputField = errors.Error("missing input field")
|
||||
ErrNilInputField = errors.Error("nil input field")
|
||||
ErrMissingInputField = errors.Error("missing input field")
|
||||
ErrNilInputField = errors.Error("nil input field")
|
||||
|
||||
ErrYamlMissingDictKey = errors.Error("Cannot find JSONDict key")
|
||||
ErrYamlIllFormat = errors.Error("Illformat")
|
||||
|
||||
3
vendor/yunion.io/x/jsonutils/go.mod
generated
vendored
3
vendor/yunion.io/x/jsonutils/go.mod
generated
vendored
@@ -9,7 +9,8 @@ require (
|
||||
github.com/pkg/errors v0.8.1 // indirect
|
||||
github.com/sirupsen/logrus v1.4.2 // indirect
|
||||
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 // indirect
|
||||
golang.org/x/text v0.3.0
|
||||
gopkg.in/yaml.v2 v2.2.2 // indirect
|
||||
yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b
|
||||
yunion.io/x/pkg v0.0.0-20200708071451-a663dc94e16b
|
||||
yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6
|
||||
)
|
||||
|
||||
5
vendor/yunion.io/x/jsonutils/go.sum
generated
vendored
5
vendor/yunion.io/x/jsonutils/go.sum
generated
vendored
@@ -28,6 +28,7 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
@@ -39,3 +40,7 @@ yunion.io/x/pkg v0.0.0-20200302034534-fdf44d54b070 h1:rKnYgtvMHKmzPEUTkyNjyKOG7w
|
||||
yunion.io/x/pkg v0.0.0-20200302034534-fdf44d54b070/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v0.0.0-20200708071451-a663dc94e16b h1:wwPzH8iMRYjtaSM2pBN7nOqeZxR4XW5wdz2VE1KH/Ug=
|
||||
yunion.io/x/pkg v0.0.0-20200708071451-a663dc94e16b/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v0.0.0-20200713121502-18154120c49b h1:Ov/eKwwNeQje7SggkopExzcCW/GfaUouvXkcY6RUEcM=
|
||||
yunion.io/x/pkg v0.0.0-20200713121502-18154120c49b/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6 h1:UarEDTBGkgcgc+nc+PZ75uo9M9+jiOGd5P2B90TxDNw=
|
||||
yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
|
||||
3
vendor/yunion.io/x/jsonutils/string.go
generated
vendored
3
vendor/yunion.io/x/jsonutils/string.go
generated
vendored
@@ -2,6 +2,7 @@ package jsonutils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -18,7 +19,7 @@ func (this *JSONInt) String() string {
|
||||
}
|
||||
|
||||
func (this *JSONFloat) String() string {
|
||||
return fmt.Sprintf("%f", this.data)
|
||||
return strconv.FormatFloat(this.data, 'g', -1, 64)
|
||||
}
|
||||
|
||||
func (this *JSONBool) String() string {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user