mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-21 00:24:07 +08:00
Compare commits
169 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73246a90b7 | ||
|
|
5cf2937871 | ||
|
|
a7064c792e | ||
|
|
d797eb3144 | ||
|
|
a3fa8463dd | ||
|
|
ddc7c4ffb6 | ||
|
|
9a94f03e11 | ||
|
|
194998499b | ||
|
|
d435034e6d | ||
|
|
d51ea4d961 | ||
|
|
8381a3f1f2 | ||
|
|
df141ff513 | ||
|
|
09854f51c3 | ||
|
|
f0fd038faa | ||
|
|
c9c2c8e478 | ||
|
|
25a9086f98 | ||
|
|
b736a6d483 | ||
|
|
d3c8315b81 | ||
|
|
bad21c8698 | ||
|
|
f42bce4184 | ||
|
|
a0e31df7be | ||
|
|
e4e1469114 | ||
|
|
982430a025 | ||
|
|
e1fd572f0e | ||
|
|
4938bd8b4f | ||
|
|
5f5f02ac07 | ||
|
|
101502895e | ||
|
|
8ecd6b5967 | ||
|
|
e0aaf54316 | ||
|
|
07ea3fa160 | ||
|
|
d36f8103dd | ||
|
|
15af5feed5 | ||
|
|
d9165e540e | ||
|
|
3d15d0ffde | ||
|
|
5bc85cc8a9 | ||
|
|
5b55749dbd | ||
|
|
0d0c52ddb1 | ||
|
|
d766d5a979 | ||
|
|
2798b9e592 | ||
|
|
b67dd5200a | ||
|
|
3c7c40e71a | ||
|
|
77ed62fbf0 | ||
|
|
8e982788fe | ||
|
|
35cba00416 | ||
|
|
58e8f9dd03 | ||
|
|
a663c5ce87 | ||
|
|
6a661d3eae | ||
|
|
928bb282ac | ||
|
|
928e2902a1 | ||
|
|
eeec217220 | ||
|
|
8ab7b49f05 | ||
|
|
4c00be06a2 | ||
|
|
06dcc0b6d9 | ||
|
|
881f4085ea | ||
|
|
37223ce58a | ||
|
|
aa80106b84 | ||
|
|
d8f0cc6b4a | ||
|
|
57244dcbd0 | ||
|
|
6e7d07f47e | ||
|
|
e90f89efa8 | ||
|
|
7756028da0 | ||
|
|
fe66a6e907 | ||
|
|
7e68d87c60 | ||
|
|
7f1f9e21d8 | ||
|
|
b773be0f73 | ||
|
|
777920cd29 | ||
|
|
00cb7fb015 | ||
|
|
8b1aa2e675 | ||
|
|
3940d23b21 | ||
|
|
c874e90985 | ||
|
|
5a71c664d1 | ||
|
|
17aeab6b4e | ||
|
|
b73d206365 | ||
|
|
722855f8f1 | ||
|
|
5f0c1cfd49 | ||
|
|
6b115aa28b | ||
|
|
fee8a08fb9 | ||
|
|
0a6daca02d | ||
|
|
eafd63ed99 | ||
|
|
0c6d7f1534 | ||
|
|
55db52bc3a | ||
|
|
4365c22e31 | ||
|
|
904f00cc55 | ||
|
|
5350c65fdd | ||
|
|
5be6a18f2b | ||
|
|
798f5e638e | ||
|
|
29cdd2154c | ||
|
|
98a31154e5 | ||
|
|
14431ff1dc | ||
|
|
00c4490ec8 | ||
|
|
c3f37211a2 | ||
|
|
1b741f18fc | ||
|
|
de876d1736 | ||
|
|
65786781e1 | ||
|
|
8cc318ac34 | ||
|
|
22a7f0a748 | ||
|
|
23bde8e519 | ||
|
|
8345f0ab8f | ||
|
|
3b5c84f5e0 | ||
|
|
505303c708 | ||
|
|
34c96d68ac | ||
|
|
68b341561c | ||
|
|
bd1cb2fc1d | ||
|
|
69d66eef67 | ||
|
|
0a140753be | ||
|
|
fe54f42735 | ||
|
|
1e53b7a995 | ||
|
|
40a9c4723f | ||
|
|
b880951a01 | ||
|
|
a0c176936e | ||
|
|
09c02afdac | ||
|
|
3acb2469a7 | ||
|
|
6ab9b68ab5 | ||
|
|
9ba603e29b | ||
|
|
0a4f530d4b | ||
|
|
ed3bd14773 | ||
|
|
bd40d802ec | ||
|
|
ea8f261ed6 | ||
|
|
86817febe1 | ||
|
|
8f1d9998f1 | ||
|
|
3026b2d73c | ||
|
|
5ea09eea51 | ||
|
|
bbb91f39d9 | ||
|
|
a7bf1fc8c6 | ||
|
|
63b97fbad0 | ||
|
|
a0bd95fabb | ||
|
|
f87e5c4004 | ||
|
|
155f9620c6 | ||
|
|
48d45592e4 | ||
|
|
5ebb30ed83 | ||
|
|
a09dccf981 | ||
|
|
7d49c48eff | ||
|
|
9407ff7397 | ||
|
|
7cc3a98825 | ||
|
|
cea2968b04 | ||
|
|
b2b21f8095 | ||
|
|
e4280eaa48 | ||
|
|
c6e291b425 | ||
|
|
140898a2f8 | ||
|
|
32b3d831b6 | ||
|
|
b974842932 | ||
|
|
30875951e1 | ||
|
|
c6fd3d5dbd | ||
|
|
5414541ce5 | ||
|
|
8b889fc561 | ||
|
|
3ce447c35e | ||
|
|
9a2e197c43 | ||
|
|
dc27b93775 | ||
|
|
2a49b7903b | ||
|
|
272e4173c2 | ||
|
|
ac674553ee | ||
|
|
d7078cd1d6 | ||
|
|
2c34090015 | ||
|
|
b5d55c7ebc | ||
|
|
62189913f1 | ||
|
|
05e19381d8 | ||
|
|
ae98388b8a | ||
|
|
da1fc9e8f3 | ||
|
|
ee3df76aa3 | ||
|
|
7ce28e78fd | ||
|
|
436b809249 | ||
|
|
d894992e29 | ||
|
|
c0db3ead14 | ||
|
|
91dbb1b64e | ||
|
|
7f52cc5ec0 | ||
|
|
213637679e | ||
|
|
02dc737ccd | ||
|
|
627e97b73a | ||
|
|
0ac263dee1 |
@@ -3,7 +3,7 @@
|
||||
{{- if $d.brand -}}
|
||||
{{ $d.brand }}平台
|
||||
{{- end -}}
|
||||
{{ .resource_type_display }}{{ $d.name }}已经{{ .action_display }}{{.result_display}}
|
||||
{{ .resource_type_display }}{{ $d.name }}{{ .action_display }}{{.result_display}}
|
||||
{{- if eq .result "failed" -}}
|
||||
,请尽快前往控制台进行处理
|
||||
{{- end -}}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
{{- if $d.brand -}}
|
||||
{{ $d.brand }}平台
|
||||
{{- end -}}
|
||||
{{ .resource_type_display }}{{ $d.name }}已经创建成功
|
||||
{{ .resource_type_display }}{{ $d.name }}创建成功
|
||||
{{- if $d.private_dns -}}
|
||||
,内网地址为{{ $d.private_dns }}:{{ $d.private_connect_port }}
|
||||
{{- end -}}
|
||||
|
||||
@@ -19,4 +19,4 @@
|
||||
{{- if $d.ip_addr -}}
|
||||
,IP地址为{{ $d.ip_addr }}
|
||||
{{- end -}}
|
||||
{{ .resource_type_display }}{{ $d.name }}已经删除成功。
|
||||
{{ .resource_type_display }}{{ $d.name }}删除成功
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{{- $d := .resource_details -}}
|
||||
您在{{ $d.project }}项目的
|
||||
|
||||
{{- if $d.ips -}}
|
||||
IP地址为{{ $d.ips }}的
|
||||
{{- end -}}
|
||||
|
||||
{{- if $d.ip_addr -}}
|
||||
IP地址为{{ $d.ip_addr }}的
|
||||
{{- end -}}
|
||||
{{- if $d.brand -}}
|
||||
{{ $d.brand }}平台
|
||||
{{- end -}}
|
||||
{{ .resource_type_display }}{{ $d.name }}成功加入回收站
|
||||
@@ -3,7 +3,7 @@
|
||||
{{- if $d.brand -}}
|
||||
{{ $d.brand }}平台
|
||||
{{- end -}}
|
||||
{{ .resource_type_display }}{{ $d.name }}已经{{ .action_display }}成功
|
||||
{{ .resource_type_display }}{{ $d.name }}{{ .action_display }}成功
|
||||
{{- if $d.account -}}
|
||||
,帐号为{{ $d.account }}
|
||||
{{- end -}}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{{- $d := .resource_details -}}
|
||||
Your {{ if $d.brand -}} {{ $d.brand }} {{ end -}} {{ .resource_type_display }} {{ $d.name }}
|
||||
{{ if $d.project -}} in project {{ $d.project }} {{ end -}} has been added to recycle bin successfully
|
||||
{{- if $d.private_dns -}}
|
||||
, the intranet address is {{ $d.private_dns }}:{{ $d.private_connect_port }}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $d.public_dns -}}
|
||||
, the external address is {{ $d.public_dns }}:{{ $d.public_connect_port }}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and $d.address_type $d.address -}}
|
||||
, the service address is {{ $d.address_type }}{{ $d.address }}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $d.ips -}}
|
||||
, the IP address is {{ $d.ips }}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $d.ip_addr -}}
|
||||
, the IP address is {{ $d.ip_addr }}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,5 @@
|
||||
{{- $d := .resource_details -}}
|
||||
{{- if $d.project -}}
|
||||
{{ $d.project }}项目的
|
||||
{{- end -}}
|
||||
{{ .resource_type_display }}{{ $d.name }}成功加入回收站
|
||||
@@ -0,0 +1,2 @@
|
||||
{{- $d := .resource_details -}}
|
||||
The {{ .resource_type_display }} {{ .Name }} {{ if $d.project }} in poject {{ $d.project }} {{ end -}} has been added to recycle bin successfully
|
||||
@@ -28,4 +28,5 @@ func init() {
|
||||
cmd.List(&options.ProxyAgentListOptions{})
|
||||
cmd.Show(&options.ProxyAgentShowOptions{})
|
||||
cmd.Delete(&options.ProxyAgentDeleteOptions{})
|
||||
cmd.Perform("purge-forwards", &options.ProxyAgentPurgeForwardsOptions{})
|
||||
}
|
||||
|
||||
@@ -90,6 +90,8 @@ func init() {
|
||||
cmd.Perform("make-sshable", &options.ServerMakeSshableOptions{})
|
||||
cmd.Perform("migrate-network", &options.ServerMigrateNetworkOptions{})
|
||||
cmd.Perform("set-sshport", &options.ServerSetSshportOptions{})
|
||||
cmd.Perform("have-agent", &options.ServerHaveAgentOptions{})
|
||||
cmd.Perform("change-disk-storage", &options.ServerChangeDiskStorageOptions{})
|
||||
|
||||
cmd.Get("vnc", new(options.ServerIdOptions))
|
||||
cmd.Get("desc", new(options.ServerIdOptions))
|
||||
|
||||
@@ -185,7 +185,22 @@ func (h *AuthHandlers) GetRegionsResponse(ctx context.Context, w http.ResponseWr
|
||||
|
||||
resp.Add(jsonutils.NewArray(retIdps...), "idps")
|
||||
|
||||
resp.Add(jsonutils.NewString(options.Options.ApiServer), "api_server")
|
||||
// in case api_server changed but not synchronized from Keystone
|
||||
// fetch this option directly from Keystone
|
||||
var apiSrv string
|
||||
commonCfg, err := modules.ServicesV3.GetSpecific(s, "common", "config", nil)
|
||||
if err != nil {
|
||||
log.Errorf("fetch common config error: %s", err)
|
||||
} else {
|
||||
apiSrv, err = commonCfg.GetString("config", "default", "api_server")
|
||||
if err != nil {
|
||||
log.Errorf("fetch api_server fail: %s (cfg: %s)", err, commonCfg)
|
||||
}
|
||||
}
|
||||
if len(apiSrv) == 0 {
|
||||
apiSrv = options.Options.ApiServer
|
||||
}
|
||||
resp.Add(jsonutils.NewString(apiSrv), "api_server")
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -346,8 +346,9 @@ func (mh *MiscHandler) DoBatchUserRegister(ctx context.Context, w http.ResponseW
|
||||
rowIdx := i + 2
|
||||
name := row[0]
|
||||
password := row[1]
|
||||
domain := row[2]
|
||||
allowWebConsole := strings.ToLower(row[3])
|
||||
displayname := row[2]
|
||||
domain := row[3]
|
||||
allowWebConsole := strings.ToLower(row[4])
|
||||
|
||||
// 忽略空白行
|
||||
rowStr := strings.Join(row, "")
|
||||
@@ -361,6 +362,10 @@ func (mh *MiscHandler) DoBatchUserRegister(ctx context.Context, w http.ResponseW
|
||||
return
|
||||
}
|
||||
|
||||
if len(displayname) == 0 {
|
||||
displayname = name
|
||||
}
|
||||
|
||||
if len(password) == 0 {
|
||||
e := httperrors.NewClientError("row %d password is empty", rowIdx)
|
||||
httperrors.JsonClientError(ctx, w, e)
|
||||
@@ -401,6 +406,7 @@ func (mh *MiscHandler) DoBatchUserRegister(ctx context.Context, w http.ResponseW
|
||||
|
||||
user := jsonutils.NewDict()
|
||||
user.Add(jsonutils.NewString(name), "name")
|
||||
user.Add(jsonutils.NewString(displayname), "displayname")
|
||||
user.Add(jsonutils.NewString(domainId), "domain_id")
|
||||
if len(password) > 0 {
|
||||
user.Add(jsonutils.NewString(password), "password")
|
||||
@@ -468,7 +474,7 @@ func (mh *MiscHandler) getDownloadsHandler(ctx context.Context, w http.ResponseW
|
||||
return
|
||||
}
|
||||
case "BatchUserRegister":
|
||||
records := [][]string{{"*用户名(user)", "*用户密码(password)", "*部门/域(domain)", "*是否登录控制台(allow_web_console:true、false)"}}
|
||||
records := [][]string{{"*用户名(user)", "*用户密码(password)", "*显示名(displayname)", "*部门/域(domain)", "*是否登录控制台(allow_web_console:true、false)"}}
|
||||
content, err = writeXlsx("users", records)
|
||||
if err != nil {
|
||||
httperrors.InternalServerError(ctx, w, "internal server error")
|
||||
|
||||
@@ -26,7 +26,7 @@ type GatewayOptions struct {
|
||||
|
||||
DisableModuleApiVersion bool `help:"Disable each modules default api version" default:"false"`
|
||||
|
||||
EnableTotp bool `help:"Enable two-factor authentication" default:"true"`
|
||||
EnableTotp bool `help:"Enable two-factor authentication" default:"false"`
|
||||
|
||||
SsoRedirectUrl string `help:"SSO idp redirect URL"`
|
||||
SsoAuthCallbackUrl string `help:"SSO idp auth callback URL"`
|
||||
|
||||
@@ -30,7 +30,8 @@ type ProxyEndpointCreateInput struct {
|
||||
}
|
||||
|
||||
type ProxyEndpointCreateFromServerInput struct {
|
||||
Name string
|
||||
Name string
|
||||
GenerateName string
|
||||
|
||||
ServerId string
|
||||
}
|
||||
|
||||
@@ -396,6 +396,10 @@ type ServerCreateInput struct {
|
||||
// emulate: BIOS, UEFI
|
||||
Bios string `json:"bios"`
|
||||
|
||||
// Machine类型
|
||||
// emulate: pc, q35
|
||||
Machine string `json:"machine"`
|
||||
|
||||
// 启动顺序
|
||||
// c: cdrome
|
||||
// d: disk
|
||||
|
||||
@@ -39,6 +39,9 @@ type CloudproviderregionDetails struct {
|
||||
// example: 300
|
||||
SyncIntervalSeconds int `json:"sync_interval_seconds"`
|
||||
|
||||
// 云订阅同步状态
|
||||
CloudproviderSyncStatus string `json:"cloudprovider_sync_status"`
|
||||
|
||||
// 支持服务列表
|
||||
Capabilities []string `json:"capabilities"`
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ const (
|
||||
CITY_XIA_MEN = "XiaMen" //厦门
|
||||
CITY_HUAI_NAN = "HuaiNan" //淮南
|
||||
CITY_SU_QIAN = "SuQian" //宿迁
|
||||
CITY_DA_LIAN = "Dalian" //大连
|
||||
|
||||
// 日本
|
||||
CITY_TOKYO = "Tokyo" //东京
|
||||
@@ -101,6 +102,7 @@ const (
|
||||
CITY_JAKARTA = "Jakarta" //雅加达
|
||||
|
||||
// 印度
|
||||
CITY_DELHI = "Delhi" // 德里
|
||||
CITY_MUMBAI = "Mumbai" //孟买
|
||||
CITY_KANCHIPURAM = "Kanchipuram" //甘吉布勒姆
|
||||
CITY_MAHARASHTRA = "Maharashtra" //马哈拉施特拉邦
|
||||
@@ -159,6 +161,9 @@ const (
|
||||
// 瑞典
|
||||
CITY_STOCKHOLM = "Stockholm" //斯德哥尔摩
|
||||
|
||||
// 波兰
|
||||
CITY_WARSAW = "Warsaw" // 华沙
|
||||
|
||||
// 巴西
|
||||
CITY_SAO_PAULO = "Sao Paulo" //圣保罗
|
||||
CITY_RIO_DE_JANEIRO = "Rio de Janeiro" // 里约热内卢
|
||||
@@ -220,4 +225,7 @@ const (
|
||||
COUNTRY_CODE_MX = "MX" //墨西哥
|
||||
COUNTRY_CODE_CL = "CL" //智利
|
||||
COUNTRY_CODE_BH = "BH" //巴林
|
||||
COUNTRY_CODE_PL = "PL" //波兰
|
||||
COUNTRY_CODE_FI = "FI" //芬兰
|
||||
COUNTRY_CODE_BE = "BE" //比利时
|
||||
)
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/apis/billing"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/esxi/vcenter"
|
||||
)
|
||||
|
||||
type DiskCreateInput struct {
|
||||
@@ -265,3 +266,24 @@ func (self DiskResizeInput) SizeMb() (int, error) {
|
||||
}
|
||||
return fileutils.GetSizeMb(self.Size, 'M', 1024)
|
||||
}
|
||||
|
||||
type DiskAllocateInput struct {
|
||||
Format string
|
||||
DiskSizeMb int
|
||||
ImageId string
|
||||
FsFormat string
|
||||
Encryption bool
|
||||
Rebuild bool
|
||||
BackingDiskId string
|
||||
SnapshotId string
|
||||
|
||||
SnapshotUrl string
|
||||
SnapshotOutOfChain bool
|
||||
Protocol string
|
||||
SrcDiskId string
|
||||
SrcPool string
|
||||
|
||||
// vmware
|
||||
HostIp string
|
||||
Datastore vcenter.SVCenterAccessInfo
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ const (
|
||||
DISK_POST_MIGRATE = "post_migrate"
|
||||
DISK_MIGRATING = "migrating"
|
||||
|
||||
DISK_CLONE = "clone"
|
||||
DISK_CLONE_FAIL = "clone_failed"
|
||||
|
||||
DISK_START_SNAPSHOT = "start_snapshot"
|
||||
DISK_SNAPSHOTING = "snapshoting"
|
||||
DISK_APPLY_SNAPSHOT_FAIL = "apply_snapshot_failed"
|
||||
|
||||
@@ -77,15 +77,17 @@ const (
|
||||
VM_REBUILD_ROOT = "rebuild_root"
|
||||
VM_REBUILD_ROOT_FAIL = "rebuild_root_fail"
|
||||
|
||||
VM_START_SNAPSHOT = "snapshot_start"
|
||||
VM_SNAPSHOT = "snapshot"
|
||||
VM_SNAPSHOT_DELETE = "snapshot_delete"
|
||||
VM_BLOCK_STREAM = "block_stream"
|
||||
VM_BLOCK_STREAM_FAIL = "block_stream_fail"
|
||||
VM_SNAPSHOT_SUCC = "snapshot_succ"
|
||||
VM_SNAPSHOT_FAILED = "snapshot_failed"
|
||||
VM_DISK_RESET = "disk_reset"
|
||||
VM_DISK_RESET_FAIL = "disk_reset_failed"
|
||||
VM_START_SNAPSHOT = "snapshot_start"
|
||||
VM_SNAPSHOT = "snapshot"
|
||||
VM_SNAPSHOT_DELETE = "snapshot_delete"
|
||||
VM_BLOCK_STREAM = "block_stream"
|
||||
VM_BLOCK_STREAM_FAIL = "block_stream_fail"
|
||||
VM_SNAPSHOT_SUCC = "snapshot_succ"
|
||||
VM_SNAPSHOT_FAILED = "snapshot_failed"
|
||||
VM_DISK_RESET = "disk_reset"
|
||||
VM_DISK_RESET_FAIL = "disk_reset_failed"
|
||||
VM_DISK_CHANGE_STORAGE = "disk_change_storage"
|
||||
VM_DISK_CHANGE_STORAGE_FAIL = "disk_change_storage_fail"
|
||||
|
||||
VM_START_INSTANCE_SNAPSHOT = "start_instance_snapshot"
|
||||
VM_INSTANCE_SNAPSHOT_FAILED = "instance_snapshot_failed"
|
||||
@@ -178,6 +180,11 @@ const (
|
||||
CPU_MODE_HOST = "host"
|
||||
)
|
||||
|
||||
const (
|
||||
VM_MACHINE_TYPE_PC = "pc"
|
||||
VM_MACHINE_TYPE_Q35 = "q35"
|
||||
)
|
||||
|
||||
var VM_RUNNING_STATUS = []string{VM_START_START, VM_STARTING, VM_RUNNING, VM_BLOCK_STREAM, VM_BLOCK_STREAM_FAIL}
|
||||
var VM_CREATING_STATUS = []string{VM_CREATE_NETWORK, VM_CREATE_DISK, VM_START_DEPLOY, VM_DEPLOYING}
|
||||
|
||||
|
||||
@@ -44,6 +44,13 @@ type GuestSshableOutput struct {
|
||||
MethodTried []GuestSshableMethodData
|
||||
}
|
||||
|
||||
type GuestHaveAgentInput struct {
|
||||
}
|
||||
|
||||
type GuestHaveAgentOutput struct {
|
||||
Have bool
|
||||
}
|
||||
|
||||
type GuestMakeSshableInput struct {
|
||||
User string
|
||||
PrivateKey string
|
||||
|
||||
@@ -631,7 +631,7 @@ type GuestJsonDesc struct {
|
||||
Cpu int `json:"cpu"`
|
||||
Vga string `json:"vga"`
|
||||
Vdi string `json:"vdi"`
|
||||
Machine string `json:"machie"`
|
||||
Machine string `json:"machine"`
|
||||
Bios string `json:"bios"`
|
||||
BootOrder string `json:"boot_order"`
|
||||
SrcIpCheck bool `json:"src_ip_check"`
|
||||
@@ -688,3 +688,15 @@ type GuestJsonDesc struct {
|
||||
InstanceId string `json:"instance_id"`
|
||||
} `json:"instance_snapshot_info"`
|
||||
}
|
||||
|
||||
type ServerChangeDiskStorageInput struct {
|
||||
DiskId string `json:"disk_id"`
|
||||
TargetStorageId string `json:"target_storage_id"`
|
||||
KeepOriginDisk bool `json:"keep_origin_disk"`
|
||||
}
|
||||
|
||||
type ServerChangeDiskStorageInternalInput struct {
|
||||
ServerChangeDiskStorageInput
|
||||
StorageId string `json:"storage_id"`
|
||||
TargetDiskId string `json:"target_disk_id"`
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
type HoststorageDetails struct {
|
||||
@@ -58,3 +60,10 @@ type HoststorageListInput struct {
|
||||
|
||||
StorageFilterListInput
|
||||
}
|
||||
|
||||
type HostStorageCreateInput struct {
|
||||
apis.JoinResourceBaseCreateInput
|
||||
StorageId string `json:"storage_id"`
|
||||
HostId string `json:"host_id"`
|
||||
MountPoint string `json:"mount_point"`
|
||||
}
|
||||
|
||||
@@ -332,6 +332,7 @@ const (
|
||||
LB_SCHEDULER_SCH = "sch" // source-ip-based consistent hash
|
||||
LB_SCHEDULER_TCH = "tch" // 4-tuple-based consistent hash
|
||||
LB_SCHEDULER_QCH = "qch"
|
||||
LB_SCHEDULER_MH = "mh" // maglev consistent hash
|
||||
)
|
||||
|
||||
var LB_SCHEDULER_TYPES = choices.NewChoices(
|
||||
|
||||
556
pkg/apis/compute/regiondata.go
Normal file
556
pkg/apis/compute/regiondata.go
Normal file
@@ -0,0 +1,556 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
var (
|
||||
// China
|
||||
RegionBeijing = cloudprovider.SGeographicInfo{
|
||||
Latitude: 39.90419989999999,
|
||||
Longitude: 116.4073963,
|
||||
City: CITY_BEI_JING,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionNingxia = cloudprovider.SGeographicInfo{
|
||||
Latitude: 37.198731,
|
||||
Longitude: 106.1580937,
|
||||
City: CITY_NING_XIA,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionShanghai = cloudprovider.SGeographicInfo{
|
||||
Latitude: 31.17,
|
||||
Longitude: 121.47,
|
||||
City: CITY_SHANG_HAI,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionGuangzhou = cloudprovider.SGeographicInfo{
|
||||
Latitude: 23.12911,
|
||||
Longitude: 113.264385,
|
||||
City: CITY_GUANG_ZHOU,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionDalian = cloudprovider.SGeographicInfo{
|
||||
Latitude: 38.91400300000001,
|
||||
Longitude: 121.614682,
|
||||
City: CITY_DA_LIAN,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionGuiyang = cloudprovider.SGeographicInfo{
|
||||
Latitude: 26.6470035286,
|
||||
Longitude: 106.6302113880,
|
||||
City: CITY_GUI_YANG,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionNeimenggu = cloudprovider.SGeographicInfo{
|
||||
Latitude: 41.0178713,
|
||||
Longitude: 113.094978,
|
||||
City: CITY_NEI_MENG_GU,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionQingdao = cloudprovider.SGeographicInfo{
|
||||
Latitude: 36.067108,
|
||||
Longitude: 120.382607,
|
||||
City: CITY_QING_DAO,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionZhangjiakou = cloudprovider.SGeographicInfo{
|
||||
Latitude: 40.767544,
|
||||
Longitude: 114.886337,
|
||||
City: CITY_ZHANG_JIA_KOU,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionHuhehaote = cloudprovider.SGeographicInfo{
|
||||
Latitude: 40.842358,
|
||||
Longitude: 111.749992,
|
||||
City: CITY_HU_HE_HAO_TE,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionHangzhou = cloudprovider.SGeographicInfo{
|
||||
Latitude: 30.274084,
|
||||
Longitude: 120.155067,
|
||||
City: CITY_HANG_ZHOU,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionShenzhen = cloudprovider.SGeographicInfo{
|
||||
Latitude: 22.543097,
|
||||
Longitude: 114.057861,
|
||||
City: CITY_SHEN_ZHEN,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionChengdu = cloudprovider.SGeographicInfo{
|
||||
Latitude: 30.572815,
|
||||
Longitude: 104.066803,
|
||||
City: CITY_CHENG_DU,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionHeyuan = cloudprovider.SGeographicInfo{
|
||||
Latitude: 23.7292717,
|
||||
Longitude: 114.6965786,
|
||||
City: CITY_HE_YUAN,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionWulanchabu = cloudprovider.SGeographicInfo{
|
||||
Latitude: 41.0178065,
|
||||
Longitude: 113.094978,
|
||||
City: CITY_WU_LAN_CHA_BU,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionChongqing = cloudprovider.SGeographicInfo{
|
||||
Latitude: 29.431585,
|
||||
Longitude: 106.912254,
|
||||
City: CITY_CHONG_QING,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionNanjing = cloudprovider.SGeographicInfo{
|
||||
Latitude: 32.0584065670,
|
||||
Longitude: 118.7964897811,
|
||||
City: CITY_NAN_JING,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
|
||||
// Asia
|
||||
RegionTaiwan = cloudprovider.SGeographicInfo{
|
||||
Latitude: 25.0443,
|
||||
Longitude: 121.509,
|
||||
City: CITY_TAI_WAN,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionHongkong = cloudprovider.SGeographicInfo{
|
||||
Latitude: 22.396427,
|
||||
Longitude: 114.109497,
|
||||
City: CITY_HONG_KONG,
|
||||
CountryCode: COUNTRY_CODE_CN,
|
||||
}
|
||||
RegionTokyo = cloudprovider.SGeographicInfo{
|
||||
Latitude: 35.709026,
|
||||
Longitude: 139.731995,
|
||||
City: CITY_TOKYO,
|
||||
CountryCode: COUNTRY_CODE_JP,
|
||||
}
|
||||
RegionOsaka = cloudprovider.SGeographicInfo{
|
||||
Latitude: 34.6937378,
|
||||
Longitude: 135.5021651,
|
||||
City: CITY_OSAKA,
|
||||
CountryCode: COUNTRY_CODE_JP,
|
||||
}
|
||||
RegionSeoul = cloudprovider.SGeographicInfo{
|
||||
Latitude: 34.6937378,
|
||||
Longitude: 135.5021651,
|
||||
City: CITY_SEOUL,
|
||||
CountryCode: COUNTRY_CODE_KR,
|
||||
}
|
||||
RegionBusan = cloudprovider.SGeographicInfo{
|
||||
Latitude: 35.1,
|
||||
Longitude: 129.0403,
|
||||
City: CITY_BUSAN,
|
||||
CountryCode: COUNTRY_CODE_KR,
|
||||
}
|
||||
|
||||
RegionMumbai = cloudprovider.SGeographicInfo{
|
||||
Latitude: 19.07599,
|
||||
Longitude: 72.877393,
|
||||
City: CITY_MUMBAI,
|
||||
CountryCode: COUNTRY_CODE_IN,
|
||||
}
|
||||
RegionDelhi = cloudprovider.SGeographicInfo{
|
||||
Latitude: 28.61,
|
||||
Longitude: 77.23,
|
||||
City: CITY_DELHI,
|
||||
CountryCode: COUNTRY_CODE_IN,
|
||||
}
|
||||
RegionMaharashtra = cloudprovider.SGeographicInfo{
|
||||
Latitude: 18.97,
|
||||
Longitude: 72.82,
|
||||
City: CITY_MAHARASHTRA,
|
||||
CountryCode: COUNTRY_CODE_IN,
|
||||
}
|
||||
RegionKanchipuram = cloudprovider.SGeographicInfo{
|
||||
Latitude: 12.8387,
|
||||
Longitude: 79.7016,
|
||||
City: CITY_KANCHIPURAM,
|
||||
CountryCode: COUNTRY_CODE_IN,
|
||||
}
|
||||
|
||||
RegionSingapore = cloudprovider.SGeographicInfo{
|
||||
Latitude: 1.352083,
|
||||
Longitude: 103.819839,
|
||||
City: CITY_SINGAPORE,
|
||||
CountryCode: COUNTRY_CODE_SG,
|
||||
}
|
||||
RegionJakarta = cloudprovider.SGeographicInfo{
|
||||
Latitude: -6.175110,
|
||||
Longitude: 106.865036,
|
||||
City: CITY_JAKARTA,
|
||||
CountryCode: COUNTRY_CODE_ID,
|
||||
}
|
||||
RegionKualaLumpur = cloudprovider.SGeographicInfo{
|
||||
Latitude: 3.139003,
|
||||
Longitude: 101.686852,
|
||||
City: CITY_KUALA_LUMPUR,
|
||||
CountryCode: COUNTRY_CODE_MY,
|
||||
}
|
||||
RegionBangkok = cloudprovider.SGeographicInfo{
|
||||
Latitude: 13.7563309,
|
||||
Longitude: 100.5017651,
|
||||
City: CITY_BANGKOK,
|
||||
CountryCode: COUNTRY_CODE_TH,
|
||||
}
|
||||
|
||||
RegionSydney = cloudprovider.SGeographicInfo{
|
||||
Latitude: -33.8688197,
|
||||
Longitude: 151.2092955,
|
||||
City: CITY_SYDNEY,
|
||||
CountryCode: COUNTRY_CODE_AU,
|
||||
}
|
||||
RegionMelbourne = cloudprovider.SGeographicInfo{
|
||||
Latitude: -37.813611,
|
||||
Longitude: 144.963056,
|
||||
City: CITY_MELBOURNE,
|
||||
CountryCode: COUNTRY_CODE_AU,
|
||||
}
|
||||
//亚拉伦拉 澳大利亚
|
||||
RegionYarralumla = cloudprovider.SGeographicInfo{
|
||||
Latitude: -35.3016,
|
||||
Longitude: 149.078,
|
||||
City: CITY_YARRALUMLA,
|
||||
CountryCode: COUNTRY_CODE_AU,
|
||||
}
|
||||
|
||||
// Africa
|
||||
RegionCapeTown = cloudprovider.SGeographicInfo{
|
||||
Latitude: -33.9152209,
|
||||
Longitude: 18.3758904,
|
||||
City: CITY_CAPE_TOWN,
|
||||
CountryCode: COUNTRY_CODE_ZA,
|
||||
}
|
||||
// 比勒陀利亚
|
||||
RegionPretoria = cloudprovider.SGeographicInfo{
|
||||
Latitude: -25.716667,
|
||||
Longitude: 28.283333,
|
||||
City: CITY_PRETORIA,
|
||||
CountryCode: COUNTRY_CODE_ZA,
|
||||
}
|
||||
RegionJohannesburg = cloudprovider.SGeographicInfo{
|
||||
Latitude: -26.1714537,
|
||||
Longitude: 27.8999389,
|
||||
City: CITY_JOHANNESBURG,
|
||||
CountryCode: COUNTRY_CODE_ZA,
|
||||
}
|
||||
|
||||
// Middleeast
|
||||
RegionBahrain = cloudprovider.SGeographicInfo{
|
||||
Latitude: 25.9408826,
|
||||
Longitude: 50.4474957,
|
||||
City: CITY_BAHRAIN,
|
||||
CountryCode: COUNTRY_CODE_BH,
|
||||
}
|
||||
RegionDubai = cloudprovider.SGeographicInfo{
|
||||
Latitude: 25.263056,
|
||||
Longitude: 55.297222,
|
||||
City: CITY_DUBAI,
|
||||
CountryCode: COUNTRY_CODE_AE,
|
||||
}
|
||||
|
||||
// Europe
|
||||
RegionFinland = cloudprovider.SGeographicInfo{
|
||||
Latitude: 64.8255731,
|
||||
Longitude: 21.5432837,
|
||||
City: CITY_FINLAND,
|
||||
CountryCode: COUNTRY_CODE_FI,
|
||||
}
|
||||
RegionBelgium = cloudprovider.SGeographicInfo{
|
||||
Latitude: 50.499734,
|
||||
Longitude: 3.9057517,
|
||||
City: CITY_BELGIUM,
|
||||
CountryCode: COUNTRY_CODE_BE,
|
||||
}
|
||||
RegionLondon = cloudprovider.SGeographicInfo{
|
||||
Latitude: 51.507351,
|
||||
Longitude: -0.127758,
|
||||
City: CITY_LONDON,
|
||||
CountryCode: COUNTRY_CODE_GB,
|
||||
}
|
||||
RegionHalton = cloudprovider.SGeographicInfo{
|
||||
Latitude: 53.3331,
|
||||
Longitude: -2.6957,
|
||||
City: CITY_HALTON,
|
||||
CountryCode: COUNTRY_CODE_GB,
|
||||
}
|
||||
RegionSussex = cloudprovider.SGeographicInfo{
|
||||
Latitude: 51,
|
||||
Longitude: 0,
|
||||
City: CITY_WEST_SUSSEX,
|
||||
CountryCode: COUNTRY_CODE_GB,
|
||||
}
|
||||
RegionFrankfurt = cloudprovider.SGeographicInfo{
|
||||
Latitude: 51.165691,
|
||||
Longitude: 10.451526,
|
||||
City: CITY_FRANKFURT,
|
||||
CountryCode: COUNTRY_CODE_DE,
|
||||
}
|
||||
RegionHolland = cloudprovider.SGeographicInfo{
|
||||
Latitude: 52.2076831,
|
||||
Longitude: 4.1585786,
|
||||
City: CITY_HOLLAND,
|
||||
CountryCode: COUNTRY_CODE_NL,
|
||||
}
|
||||
RegionZurich = cloudprovider.SGeographicInfo{
|
||||
Latitude: 47.3774497,
|
||||
Longitude: 8.5016958,
|
||||
City: CITY_ZURICH,
|
||||
CountryCode: COUNTRY_CODE_CH,
|
||||
}
|
||||
RegionWarsaw = cloudprovider.SGeographicInfo{
|
||||
Latitude: 52.233333,
|
||||
Longitude: 21.016667,
|
||||
City: CITY_WARSAW,
|
||||
CountryCode: COUNTRY_CODE_PL,
|
||||
}
|
||||
RegionIreland = cloudprovider.SGeographicInfo{
|
||||
Latitude: 53.41291,
|
||||
Longitude: -8.24389,
|
||||
City: CITY_IRELAND,
|
||||
CountryCode: COUNTRY_CODE_IE,
|
||||
}
|
||||
RegionDublin = cloudprovider.SGeographicInfo{
|
||||
Latitude: 53.349722,
|
||||
Longitude: -6.260278,
|
||||
City: CITY_DUBLIN,
|
||||
CountryCode: COUNTRY_CODE_IE,
|
||||
}
|
||||
RegionParis = cloudprovider.SGeographicInfo{
|
||||
Latitude: 48.856614,
|
||||
Longitude: 2.3522219,
|
||||
City: CITY_PARIS,
|
||||
CountryCode: COUNTRY_CODE_FR,
|
||||
}
|
||||
RegionAllier = cloudprovider.SGeographicInfo{
|
||||
Latitude: 46.5178,
|
||||
Longitude: 3.3592,
|
||||
City: CITY_ALLIER,
|
||||
CountryCode: COUNTRY_CODE_FR,
|
||||
}
|
||||
RegionTarn = cloudprovider.SGeographicInfo{
|
||||
Latitude: 43.8656,
|
||||
Longitude: 1.505,
|
||||
City: CITY_TARN,
|
||||
CountryCode: COUNTRY_CODE_FR,
|
||||
}
|
||||
RegionStockholm = cloudprovider.SGeographicInfo{
|
||||
Latitude: 59.1946,
|
||||
Longitude: 18.47,
|
||||
City: CITY_STOCKHOLM,
|
||||
CountryCode: COUNTRY_CODE_SE,
|
||||
}
|
||||
RegionDelmenhorst = cloudprovider.SGeographicInfo{
|
||||
Latitude: 53.050556,
|
||||
Longitude: 8.631667,
|
||||
City: CITY_DELMENHORST,
|
||||
CountryCode: COUNTRY_CODE_DE,
|
||||
}
|
||||
RegionGeneva = cloudprovider.SGeographicInfo{
|
||||
Latitude: 46.201667,
|
||||
Longitude: 6.146944,
|
||||
City: CITY_GENEVA,
|
||||
CountryCode: COUNTRY_CODE_CH,
|
||||
}
|
||||
RegionStavanger = cloudprovider.SGeographicInfo{
|
||||
Latitude: 58.963333,
|
||||
Longitude: 5.718889,
|
||||
City: CITY_STAVANGER,
|
||||
CountryCode: COUNTRY_CODE_NO,
|
||||
}
|
||||
RegionOslo = cloudprovider.SGeographicInfo{
|
||||
Latitude: 59.905556,
|
||||
Longitude: 10.768333,
|
||||
City: CITY_OSLO,
|
||||
CountryCode: COUNTRY_CODE_NO,
|
||||
}
|
||||
|
||||
RegionMoscow = cloudprovider.SGeographicInfo{
|
||||
Latitude: 55.755825,
|
||||
Longitude: 37.617298,
|
||||
City: CITY_MOSCOW,
|
||||
CountryCode: COUNTRY_CODE_RU,
|
||||
}
|
||||
|
||||
// America
|
||||
RegionMontreal = cloudprovider.SGeographicInfo{
|
||||
Latitude: 45.5580206,
|
||||
Longitude: -73.8003414,
|
||||
City: CITY_MONTREAL,
|
||||
CountryCode: COUNTRY_CODE_CA,
|
||||
}
|
||||
RegionToronto = cloudprovider.SGeographicInfo{
|
||||
Latitude: 43.653225,
|
||||
Longitude: -79.383186,
|
||||
City: CITY_TORONTO,
|
||||
CountryCode: COUNTRY_CODE_CA,
|
||||
}
|
||||
RegionCanadaCentral = cloudprovider.SGeographicInfo{
|
||||
Latitude: 56.130366,
|
||||
Longitude: -106.346771,
|
||||
City: CITY_CANADA_CENTRAL,
|
||||
CountryCode: COUNTRY_CODE_CA,
|
||||
}
|
||||
RegionQuebec = cloudprovider.SGeographicInfo{
|
||||
Latitude: 52,
|
||||
Longitude: -72,
|
||||
City: CITY_QUEBEC,
|
||||
CountryCode: COUNTRY_CODE_CA,
|
||||
}
|
||||
|
||||
RegionSaoPaulo = cloudprovider.SGeographicInfo{
|
||||
Latitude: -23.5505199,
|
||||
Longitude: -46.6333094,
|
||||
City: CITY_SAO_PAULO,
|
||||
CountryCode: COUNTRY_CODE_BR,
|
||||
}
|
||||
// 里约热内卢
|
||||
RegionRioDeJaneiro = cloudprovider.SGeographicInfo{
|
||||
Latitude: -22.9083,
|
||||
Longitude: -43.1964,
|
||||
City: CITY_RIO_DE_JANEIRO,
|
||||
CountryCode: COUNTRY_CODE_BR,
|
||||
}
|
||||
|
||||
RegionMexico = cloudprovider.SGeographicInfo{
|
||||
Latitude: 55.1182908,
|
||||
Longitude: 141.0377645,
|
||||
City: CITY_MEXICO,
|
||||
CountryCode: COUNTRY_CODE_MX,
|
||||
}
|
||||
|
||||
RegionSantiago = cloudprovider.SGeographicInfo{
|
||||
Latitude: -33.45206,
|
||||
Longitude: -70.676031,
|
||||
City: CITY_SANTIAGO,
|
||||
CountryCode: COUNTRY_CODE_CL,
|
||||
}
|
||||
|
||||
RegionIowa = cloudprovider.SGeographicInfo{
|
||||
Latitude: 41.9328655,
|
||||
Longitude: -94.5106809,
|
||||
City: CITY_IOWA,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionCarolina = cloudprovider.SGeographicInfo{
|
||||
Latitude: 33.6194409,
|
||||
Longitude: -82.0475635,
|
||||
City: CITY_SOUTH_CAROLINA,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
// 西雅图,华盛顿州
|
||||
RegionWashington = cloudprovider.SGeographicInfo{
|
||||
Latitude: 47.6,
|
||||
Longitude: -122.3,
|
||||
City: CITY_WASHINGTON,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionVirginia = cloudprovider.SGeographicInfo{
|
||||
Latitude: 37.4315734,
|
||||
Longitude: -78.6568942,
|
||||
City: CITY_VIRGINIA,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionTexas = cloudprovider.SGeographicInfo{
|
||||
Latitude: 31,
|
||||
Longitude: -100,
|
||||
City: CITY_TEXAS,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionChicago = cloudprovider.SGeographicInfo{
|
||||
Latitude: 41.8819,
|
||||
Longitude: -87.6278,
|
||||
City: CITY_CHICAGO,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionPhoenix = cloudprovider.SGeographicInfo{
|
||||
Latitude: 33.4483,
|
||||
Longitude: -112.0739,
|
||||
City: CITY_PHOENIX,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionUtah = cloudprovider.SGeographicInfo{
|
||||
Latitude: 39.5,
|
||||
Longitude: -111.5,
|
||||
City: CITY_UTAH,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionSanFrancisco = cloudprovider.SGeographicInfo{
|
||||
Latitude: 37.7775,
|
||||
Longitude: -122.4164,
|
||||
City: CITY_SAN_FRANCISCO,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionSiliconValley = cloudprovider.SGeographicInfo{
|
||||
Latitude: 37.387474,
|
||||
Longitude: -122.057541,
|
||||
City: CITY_SILICONVALLEY,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionNothVirginia = cloudprovider.SGeographicInfo{
|
||||
Latitude: 37.4315734,
|
||||
Longitude: -78.6568942,
|
||||
City: CITY_N_VIRGINIA,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionOregon = cloudprovider.SGeographicInfo{
|
||||
Latitude: 43.8041334,
|
||||
Longitude: -120.5542012,
|
||||
City: CITY_OREGON,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionLosAngeles = cloudprovider.SGeographicInfo{
|
||||
Latitude: 34.0522342,
|
||||
Longitude: -118.2436849,
|
||||
City: CITY_LOS_ANGELES,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionSaltLakeCity = cloudprovider.SGeographicInfo{
|
||||
Latitude: 40.7767168,
|
||||
Longitude: -111.9905243,
|
||||
City: CITY_SALT_LAKE_CITY,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionLasVegas = cloudprovider.SGeographicInfo{
|
||||
Latitude: 36.1249185,
|
||||
Longitude: -115.3150811,
|
||||
City: CITY_LAS_VEGAS,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionNorthCalifornia = cloudprovider.SGeographicInfo{
|
||||
Latitude: 38.8375215,
|
||||
Longitude: -120.8958242,
|
||||
City: CITY_N_CALIFORNIA,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
RegionOhio = cloudprovider.SGeographicInfo{
|
||||
Latitude: 40.4172871,
|
||||
Longitude: -82.90712300000001,
|
||||
City: CITY_OHIO,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
|
||||
RegionUSGOVWest = cloudprovider.SGeographicInfo{
|
||||
Latitude: 37.09024,
|
||||
Longitude: -95.712891,
|
||||
City: CITY_US_GOV_WEST,
|
||||
CountryCode: COUNTRY_CODE_US,
|
||||
}
|
||||
)
|
||||
@@ -62,6 +62,9 @@ type VpcListInput struct {
|
||||
UsableResourceListInput
|
||||
UsableVpcResourceListInput
|
||||
|
||||
// 过滤vpc底下有指定zone的ip子网
|
||||
ZoneId string `json:"zone_id"`
|
||||
|
||||
// filter by globalvpc
|
||||
Globalvpc string `json:"globalvpc"`
|
||||
|
||||
|
||||
@@ -43,6 +43,9 @@ const (
|
||||
|
||||
SERVICE_TYPE_ETCD = "etcd"
|
||||
SERVICE_TYPE_INFLUXDB = "influxdb"
|
||||
|
||||
STATUS_UPDATE_TAGS = "update_tags"
|
||||
STATUS_UPDATE_TAGS_FAILED = "update_tags_fail"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
20
pkg/apis/host/types.go
Normal file
20
pkg/apis/host/types.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package host
|
||||
|
||||
type ServerCloneDiskFromStorageResponse struct {
|
||||
TargetAccessPath string `json:"target_access_path"`
|
||||
TargetFormat string `json:"target_format"`
|
||||
}
|
||||
@@ -15,6 +15,8 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
@@ -37,6 +39,7 @@ type AlertRecordShieldDetails struct {
|
||||
CommonAlertDetails
|
||||
AlertName string `json:"alert_name"`
|
||||
ResName string `json:"res_name"`
|
||||
Expired bool `json:"expired"`
|
||||
}
|
||||
|
||||
type AlertRecordShieldListInput struct {
|
||||
@@ -46,9 +49,11 @@ type AlertRecordShieldListInput struct {
|
||||
apis.EnabledResourceBaseListInput
|
||||
apis.StatusStandaloneResourceListInput
|
||||
|
||||
AlertName string `json:"alert_name"`
|
||||
ResType string `json:"res_type"`
|
||||
ResName string `json:"res_name"`
|
||||
ResId string `json:"res_id"`
|
||||
AlertId string `json:"alert_id"`
|
||||
AlertName string `json:"alert_name"`
|
||||
ResType string `json:"res_type"`
|
||||
ResName string `json:"res_name"`
|
||||
ResId string `json:"res_id"`
|
||||
AlertId string `json:"alert_id"`
|
||||
StartTime *time.Time `json:"start_time"`
|
||||
EndTime *time.Time `json:"end_time"`
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ const (
|
||||
METRIC_RES_TYPE_TENANT = "tenant"
|
||||
METRIC_RES_TYPE_DOMAIN = "domain"
|
||||
METRIC_RES_TYPE_STORAGE = "storage"
|
||||
METRIC_RES_TYPE_ELB = "elb"
|
||||
//ext is prefix!
|
||||
METRIC_RES_TYPE_JENKINS = "ext_jenkins"
|
||||
METRIC_RES_TYPE_EXT_MYSQL = "ext_mysql"
|
||||
|
||||
@@ -32,6 +32,7 @@ type MonitorResourceJointListInput struct {
|
||||
ResType string `json:"res_type"`
|
||||
ResName string `json:"res_name"`
|
||||
AlertName string `json:"alert_name"`
|
||||
Level string `json:"level"`
|
||||
}
|
||||
|
||||
type MonitorResourceJointCreateInput struct {
|
||||
|
||||
@@ -106,6 +106,16 @@ const (
|
||||
TOPIC_RESOURCE_ELASTICCACHE = "elasticcache"
|
||||
TOPIC_RESOURCE_SCHEDULEDTASK = "scheduledtask"
|
||||
TOPIC_RESOURCE_BAREMETAL = "baremetal"
|
||||
TOPIC_RESOURCE_VPC = "vpc"
|
||||
TOPIC_RESOURCE_DNSZONE = "dns_zone"
|
||||
TOPIC_RESOURCE_NATGATEWAY = "natgateway"
|
||||
TOPIC_RESOURCE_WEBAPP = "webapp"
|
||||
TOPIC_RESOURCE_CDNDOMAIN = "cdn_domain"
|
||||
TOPIC_RESOURCE_FILESYSTEM = "file_system"
|
||||
TOPIC_RESOURCE_WAF = "waf_instance"
|
||||
TOPIC_RESOURCE_KAFKA = "kafka"
|
||||
TOPIC_RESOURCE_ELASTICSEARCH = "elastic_search"
|
||||
TOPIC_RESOURCE_MONGODB = "mongodb"
|
||||
|
||||
SUBSCRIBER_TYPE_ROLE = "role"
|
||||
SUBSCRIBER_TYPE_ROBOT = "robot"
|
||||
|
||||
@@ -40,6 +40,10 @@ var (
|
||||
ActionCreateBackupServer SAction = "add_backup_server"
|
||||
ActionDelBackupServer SAction = "delete_backup_server"
|
||||
|
||||
ActionSyncCreate SAction = "sync_create"
|
||||
ActionSyncUpdate SAction = "sync_update"
|
||||
ActionSyncDelete SAction = "sync_delete"
|
||||
|
||||
ResultFailed SResult = "failed"
|
||||
ResultSucceed SResult = "succeed"
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ type ModelBaseDetails struct {
|
||||
CanUpdate bool `json:"can_update"`
|
||||
|
||||
// 资源不能更新的原因
|
||||
UpdateFailReason string `json:"update_fail_reason"`
|
||||
UpdateFailReason httperrors.Error `json:"update_fail_reason"`
|
||||
}
|
||||
|
||||
type ModelBaseShortDescDetail struct {
|
||||
|
||||
@@ -185,6 +185,7 @@ func (m *SBaremetalManager) CleanBaremetal(bmId string) {
|
||||
func (m *SBaremetalManager) updateBaremetal(session *mcclient.ClientSession, bmId string) (jsonutils.JSONObject, error) {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.JSONTrue, "is_baremetal")
|
||||
params.Add(jsonutils.JSONTrue, "not_sync_config")
|
||||
obj, err := modules.Hosts.Put(session, bmId, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -2658,7 +2659,13 @@ func (s *SBaremetalServer) DoRebuildRootDisk(term *ssh.Client) ([]*disktool.Part
|
||||
|
||||
func (s *SBaremetalServer) SyncPartitionSize(term *ssh.Client, parts []*disktool.Partition) ([]jsonutils.JSONObject, error) {
|
||||
disks, _ := s.desc.GetArray("disks")
|
||||
|
||||
// calculate root partitions count
|
||||
rootPartsCnt := len(parts) - len(disks) + 1
|
||||
if len(parts) < len(disks) {
|
||||
// HACK: rebuild root disk
|
||||
rootPartsCnt = len(parts)
|
||||
}
|
||||
rootParts := parts[0:rootPartsCnt]
|
||||
dataParts := parts[rootPartsCnt:]
|
||||
idx := 0
|
||||
|
||||
@@ -36,6 +36,7 @@ type BaremetalOptions struct {
|
||||
TftpMaxTimeoutRetries int `default:"50" help:"Maximal tftp timeout retries, default is 50"`
|
||||
LengthyWorkerCount int `default:"8" help:"Parallel worker count for lengthy tasks"`
|
||||
ShortWorkerCount int `default:"8" help:"Parallel worker count for short-lived tasks"`
|
||||
TaskWorkerCount int `default:"32" help:"Parallel worker count for tasks"`
|
||||
|
||||
DefaultIpmiPassword string `help:"Default IPMI passowrd"`
|
||||
DefaultStrongIpmiPassword string `help:"Default strong IPMI passowrd"`
|
||||
|
||||
@@ -24,16 +24,16 @@ import (
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/baremetal/options"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
)
|
||||
|
||||
var baremetalTaskWorkerMan *appsrv.SWorkerManager
|
||||
|
||||
func init() {
|
||||
baremetalTaskWorkerMan = appsrv.NewWorkerManager("BaremetalTaskWorkerManager", 8, 1024, false)
|
||||
}
|
||||
|
||||
func GetWorkManager() *appsrv.SWorkerManager {
|
||||
if baremetalTaskWorkerMan == nil {
|
||||
baremetalTaskWorkerMan = appsrv.NewWorkerManager("BaremetalTaskWorkerManager", options.Options.TaskWorkerCount, 1024, false)
|
||||
}
|
||||
return baremetalTaskWorkerMan
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func ExecuteTask(task ITask, args interface{}) {
|
||||
task: task,
|
||||
args: args,
|
||||
}
|
||||
baremetalTaskWorkerMan.Run(t, nil, nil)
|
||||
GetWorkManager().Run(t, nil, nil)
|
||||
}
|
||||
|
||||
func executeTask(task ITask, args interface{}) {
|
||||
|
||||
@@ -298,6 +298,7 @@ func FetchCustomizeColumns(
|
||||
jsonDict.Update(jsonutils.Marshal(objs[i]).(*jsonutils.JSONDict))
|
||||
out := apis.ModelBaseDetails{
|
||||
CanDelete: true,
|
||||
CanUpdate: true,
|
||||
}
|
||||
|
||||
err = ValidateDeleteCondition(objs[i].(IModel), ctx, jsonDict)
|
||||
@@ -307,6 +308,13 @@ func FetchCustomizeColumns(
|
||||
out.DeleteFailReason = httperrors.NewErrorFromGeneralError(ctx, err)
|
||||
}
|
||||
}
|
||||
err = ValidateUpdateCondition(objs[i].(IModel), ctx)
|
||||
if err != nil {
|
||||
out.CanUpdate = false
|
||||
if showReason {
|
||||
out.UpdateFailReason = httperrors.NewErrorFromGeneralError(ctx, err)
|
||||
}
|
||||
}
|
||||
jsonDict.Update(jsonutils.Marshal(out))
|
||||
|
||||
retVal[i] = jsonDict
|
||||
@@ -351,3 +359,14 @@ func ValidateDeleteCondition(model IModel, ctx context.Context, data jsonutils.J
|
||||
}
|
||||
return ValueToError(ret[0])
|
||||
}
|
||||
|
||||
func ValidateUpdateCondition(model IModel, ctx context.Context) error {
|
||||
ret, err := call(model, "ValidateUpdateCondition", ctx)
|
||||
if err != nil {
|
||||
return httperrors.NewGeneralError(err)
|
||||
}
|
||||
if len(ret) != 1 {
|
||||
return httperrors.NewInternalServerError("Invald ValidateUpdateCondition return value")
|
||||
}
|
||||
return ValueToError(ret[0])
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/appsrv/dispatcher"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
@@ -184,7 +183,7 @@ func applyListItemsSearchFilters(manager IModelManager, ctx context.Context, q *
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func applyListItemsGeneralFilters(manager IModelManager, q *sqlchemy.SQuery,
|
||||
func ApplyListItemsGeneralFilters(manager IModelManager, q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential, filters []string, filterAny bool) (*sqlchemy.SQuery, error) {
|
||||
conds := make([]sqlchemy.ICondition, 0)
|
||||
schFields := searchFields(manager, userCred) // only filter searchable fields
|
||||
@@ -298,7 +297,7 @@ func listItemQueryFiltersRaw(manager IModelManager,
|
||||
filterAny, _ := query.Bool("filter_any")
|
||||
filters := jsonutils.GetQueryStringArray(query, "filter")
|
||||
if len(filters) > 0 {
|
||||
q, err = applyListItemsGeneralFilters(manager, q, userCred, filters, filterAny)
|
||||
q, err = ApplyListItemsGeneralFilters(manager, q, userCred, filters, filterAny)
|
||||
}
|
||||
jointFilter := jsonutils.GetQueryStringArray(query, "joint_filter")
|
||||
if len(jointFilter) > 0 {
|
||||
@@ -708,12 +707,14 @@ func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok
|
||||
// skip markerField in pagingConf
|
||||
continue
|
||||
}
|
||||
colSpec := manager.TableSpec().ColumnSpec(orderByField)
|
||||
if colSpec != nil {
|
||||
if order == sqlchemy.SQL_ORDER_ASC {
|
||||
q = q.Asc(orderByField)
|
||||
} else {
|
||||
q = q.Desc(orderByField)
|
||||
for _, field := range q.QueryFields() {
|
||||
if orderByField == field.Name() {
|
||||
if order == sqlchemy.SQL_ORDER_ASC {
|
||||
q = q.Asc(field)
|
||||
} else {
|
||||
q = q.Desc(field)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -852,20 +853,6 @@ func (dispatcher *DBModelDispatcher) List(ctx context.Context, query jsonutils.J
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func getModelExtraDetails(item IModel, ctx context.Context, showReason bool) apis.ModelBaseDetails {
|
||||
out := apis.ModelBaseDetails{
|
||||
CanUpdate: true,
|
||||
}
|
||||
err := item.ValidateUpdateCondition(ctx)
|
||||
if err != nil {
|
||||
out.CanUpdate = false
|
||||
if showReason {
|
||||
out.UpdateFailReason = err.Error()
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func getModelItemDetails(manager IModelManager, item IModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isHead bool) (jsonutils.JSONObject, error) {
|
||||
appParams := appsrv.AppContextGetParams(ctx)
|
||||
if appParams == nil && isHead {
|
||||
@@ -891,7 +878,7 @@ func getModelItemDetails(manager IModelManager, item IModel, ctx context.Context
|
||||
}
|
||||
|
||||
func GetItemDetails(manager IModelManager, item IModel, ctx context.Context, userCred mcclient.TokenCredential) (jsonutils.JSONObject, error) {
|
||||
return getItemDetails(manager, item, ctx, userCred, nil)
|
||||
return getItemDetails(manager, item, ctx, userCred, jsonutils.NewDict())
|
||||
}
|
||||
|
||||
func getItemDetails(manager IModelManager, item IModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
|
||||
@@ -306,14 +306,7 @@ func (manager *SModelBaseManager) FetchCustomizeColumns(
|
||||
fields stringutils2.SSortedStrings,
|
||||
isList bool,
|
||||
) []apis.ModelBaseDetails {
|
||||
showReason := false
|
||||
if query.Contains("show_fail_reason") {
|
||||
showReason = true
|
||||
}
|
||||
ret := make([]apis.ModelBaseDetails, len(objs))
|
||||
for i := range objs {
|
||||
ret[i] = getModelExtraDetails(objs[i].(IModel), ctx, showReason)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,10 @@ var (
|
||||
ActionSyncStatus = api.ActionSyncStatus
|
||||
|
||||
ActionPendingDelete = api.ActionPendingDelete
|
||||
|
||||
ActionSyncCreate = api.ActionSyncCreate
|
||||
ActionSyncUpdate = api.ActionSyncUpdate
|
||||
ActionSyncDelete = api.ActionSyncDelete
|
||||
)
|
||||
|
||||
type SEvent struct {
|
||||
|
||||
@@ -249,16 +249,21 @@ func (t *eventTask) Run() {
|
||||
}
|
||||
|
||||
func EventNotify(ctx context.Context, userCred mcclient.TokenCredential, ep SEventNotifyParam) {
|
||||
ret, err := db.FetchCustomizeColumns(ep.Obj.GetModelManager(), ctx, userCred, jsonutils.NewDict(), []interface{}{ep.Obj}, stringutils2.SSortedStrings{}, false)
|
||||
if err != nil {
|
||||
log.Errorf("unable to FetchCustomizeColumns: %v", err)
|
||||
return
|
||||
var objDetails *jsonutils.JSONDict
|
||||
if ep.Action == ActionDelete || ep.Action == ActionSyncDelete {
|
||||
objDetails = jsonutils.Marshal(ep.Obj).(*jsonutils.JSONDict)
|
||||
} else {
|
||||
ret, err := db.FetchCustomizeColumns(ep.Obj.GetModelManager(), ctx, userCred, jsonutils.NewDict(), []interface{}{ep.Obj}, stringutils2.SSortedStrings{}, false)
|
||||
if err != nil {
|
||||
log.Errorf("unable to FetchCustomizeColumns: %v", err)
|
||||
return
|
||||
}
|
||||
if len(ret) == 0 {
|
||||
log.Errorf("unable to FetchCustomizeColumns: details of model %q is empty", ep.Obj.GetId())
|
||||
return
|
||||
}
|
||||
objDetails = ret[0]
|
||||
}
|
||||
if len(ret) == 0 {
|
||||
log.Errorf("unable to FetchCustomizeColumns: details of model %q is empty", ep.Obj.GetId())
|
||||
return
|
||||
}
|
||||
objDetails := ret[0]
|
||||
if ep.ObjDetailsDecorator != nil {
|
||||
ep.ObjDetailsDecorator(ctx, objDetails)
|
||||
}
|
||||
|
||||
@@ -53,6 +53,10 @@ func OnBaseOptionsChange(oOpts, nOpts interface{}) bool {
|
||||
if oldOpts.EnableQuotaCheck != newOpts.EnableQuotaCheck {
|
||||
consts.SetEnableQuotaCheck(newOpts.EnableQuotaCheck)
|
||||
}
|
||||
if oldOpts.ApiServer != newOpts.ApiServer {
|
||||
log.Debugf("api_server changed from %d to %d", oldOpts.ApiServer, newOpts.ApiServer)
|
||||
changed = true
|
||||
}
|
||||
return changed
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudmon/collectors/common"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -50,7 +49,7 @@ type SAzureCloudReport struct {
|
||||
}
|
||||
|
||||
func (self *SAzureCloudReport) Report() error {
|
||||
servers, err := self.GetAllserverOfThisProvider(&modules.Servers)
|
||||
servers, err := self.GetResourceByOperator()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -64,19 +63,19 @@ func (self *SAzureCloudReport) Report() error {
|
||||
}
|
||||
for _, region := range regionList {
|
||||
servers := regionServerMap[region.GetGlobalId()]
|
||||
switch self.Operator {
|
||||
case "server":
|
||||
err = common.CollectRegionMetricAsync(self.Args.Batch, region, servers, self)
|
||||
//err = self.collectRegionMetricOfHost(region, servers)
|
||||
//case "redis":
|
||||
// err = self.collectRegionMetricOfRedis(region, servers)
|
||||
//case "rds":
|
||||
// err = self.collectRegionMetricOfRds(region, servers)
|
||||
//case "oss":
|
||||
// err = self.collectRegionMetricOfOss(region, servers)
|
||||
//case "elb":
|
||||
// err = self.collectRegionMetricOfElb(region, servers)
|
||||
}
|
||||
err = common.CollectRegionMetricAsync(self.Args.Batch, region, servers, self)
|
||||
//switch self.Operator {
|
||||
//case "server":
|
||||
// //err = self.collectRegionMetricOfHost(region, servers)
|
||||
// //case "redis":
|
||||
// // err = self.collectRegionMetricOfRedis(region, servers)
|
||||
// //case "rds":
|
||||
// // err = self.collectRegionMetricOfRds(region, servers)
|
||||
// //case "oss":
|
||||
// // err = self.collectRegionMetricOfOss(region, servers)
|
||||
// //case "elb":
|
||||
// // err = self.collectRegionMetricOfElb(region, servers)
|
||||
//}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package azuremon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -22,6 +23,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
com_api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudmon/collectors/common"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/azure"
|
||||
@@ -50,8 +52,7 @@ func (self *SAzureCloudReport) collectRegionMetricOfHost(region cloudprovider.IC
|
||||
continue
|
||||
}
|
||||
classicKey := "microsoft.classiccompute/virtualmachines"
|
||||
ns := "Microsoft.Compute/virtualMachines"
|
||||
metricSpecs := azureMetricSpecs
|
||||
ns, metricSpecs := self.getMetricSpecs(server)
|
||||
if strings.Contains(strings.ToLower(external_id), classicKey) {
|
||||
ns = classicKey
|
||||
metricSpecs = azureClassicMetricsSpec
|
||||
@@ -75,11 +76,13 @@ func (self *SAzureCloudReport) collectRegionMetricOfHost(region cloudprovider.IC
|
||||
for _, value := range *rtnMetrics.Value {
|
||||
if value.Name.LocalizedValue != nil {
|
||||
if metricName == *(value.Name.LocalizedValue) || (value.Name.Value != nil && *value.Name.Value == metricName) {
|
||||
metric, err := common.FillVMCapacity(server.(*jsonutils.JSONDict))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "fill vm %q capacity", srvPrefix)
|
||||
if self.Operator == string(common.SERVER) {
|
||||
metric, err := common.FillVMCapacity(server.(*jsonutils.JSONDict))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "fill vm %q capacity", srvPrefix)
|
||||
}
|
||||
dataList = append(dataList, metric)
|
||||
}
|
||||
dataList = append(dataList, metric)
|
||||
if value.Timeseries != nil {
|
||||
for _, timeserie := range *value.Timeseries {
|
||||
serverMetric, err := self.collectMetricFromThisServer(server, timeserie, influxDbSpecs)
|
||||
@@ -106,7 +109,7 @@ func (self *SAzureCloudReport) collectMetricFromThisServer(server jsonutils.JSON
|
||||
rtnMetric azure.TimeSeriesElement, influxDbSpecs []string) ([]influxdb.SMetricData, error) {
|
||||
datas := make([]influxdb.SMetricData, 0)
|
||||
for _, data := range *rtnMetric.Data {
|
||||
metric, err := common.JsonToMetric(server.(*jsonutils.JSONDict), "", common.ServerTags, make([]string, 0))
|
||||
metric, err := self.NewMetricFromJson(server)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -153,3 +156,39 @@ func (self *SAzureCloudReport) collectMetricFromThisServer(server jsonutils.JSON
|
||||
|
||||
return datas, nil
|
||||
}
|
||||
|
||||
func (self *SAzureCloudReport) getMetricSpecs(res jsonutils.JSONObject) (string, map[string][]string) {
|
||||
switch common.MonType(self.Operator) {
|
||||
case common.SERVER:
|
||||
return SERVER_METRIC_NAMESPACE, azureMetricSpecs
|
||||
case common.REDIS:
|
||||
return REDIS_METRIC_NAMESPACE, azureRedisMetricsSpec
|
||||
case common.RDS:
|
||||
return self.getRdsMetricSpecsByEngine(res)
|
||||
case common.ELB:
|
||||
return ELB_METRIC_NAMESPACE, azureElbMetricSpecs
|
||||
default:
|
||||
return SERVER_METRIC_NAMESPACE, azureMetricSpecs
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SAzureCloudReport) getRdsMetricSpecsByEngine(res jsonutils.JSONObject) (string, map[string][]string) {
|
||||
engine, _ := res.GetString("engine")
|
||||
externalId, _ := res.GetString("external_id")
|
||||
suffix := "servers"
|
||||
if strings.Contains(externalId, "flexible") {
|
||||
suffix = "flexibleServers"
|
||||
}
|
||||
switch engine {
|
||||
case com_api.DBINSTANCE_TYPE_SQLSERVER:
|
||||
return "Microsoft.Sql/servers/databases", azureRdsMetricsSpec
|
||||
case com_api.DBINSTANCE_TYPE_MYSQL:
|
||||
return fmt.Sprintf("Microsoft.DBforMySQL/%s", suffix), azureRdsMetricsSpec
|
||||
case com_api.DBINSTANCE_TYPE_POSTGRESQL:
|
||||
return fmt.Sprintf("Microsoft.DBforPostgreSQL/%s", suffix), azureRdsMetricsSpec
|
||||
case com_api.DBINSTANCE_TYPE_MARIADB:
|
||||
return "Microsoft.DBforMariaDB/servers", azureRdsMetricsSpec
|
||||
default:
|
||||
return fmt.Sprintf("Microsoft.DBforMySQL/%s", suffix), azureRdsMetricsSpec
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ const (
|
||||
UNIT_MEM = "byte"
|
||||
UNIT_MSEC = "ms"
|
||||
UNIT_COUNT_SEC = "count/s"
|
||||
UNIT_BYTES = "byte"
|
||||
|
||||
//ESC监控指标
|
||||
INFLUXDB_FIELD_CPU_USAGE = "vm_cpu.usage_active"
|
||||
@@ -58,8 +59,11 @@ const (
|
||||
INFLUXDB_FIELD_RDS_DISK_USAGE = "rds_disk.used_percent"
|
||||
INFLUXDB_FIELD_RDS_DISK_READ_BPS = "rds_diskio.read_bps"
|
||||
INFLUXDB_FIELD_RDS_DISK_WRITE_BPS = "rds_diskio.write_bps"
|
||||
INFLUXDB_FIELD_RDS_DISK_IO_PERSENT = "rds_diskio.used_percent"
|
||||
INFLUXDB_FIELD_RDS_CONN_COUNT = "rds_conn.used_count"
|
||||
INFLUXDB_FIELD_RDS_CONN_USAGE = "rds_conn.used_percent"
|
||||
INFLUXDB_FIELD_RDS_CONN_ACTIVE = "rds_conn.active_count"
|
||||
INFLUXDB_FIELD_RDS_CONN_FAILED = "rds_conn.failed_count"
|
||||
|
||||
INFLUXDB_FIELD_RDS_QPS = "rds_qps.query_qps"
|
||||
INFLUXDB_FIELD_RDS_TPS = "rds_tps.trans_qps"
|
||||
@@ -76,6 +80,8 @@ const (
|
||||
INFLUXDB_FIFLD_REDIS_CACHE_KEYS = "dcs_cachekeys.key_count"
|
||||
INFLUXDB_FIFLD_REDIS_CACHE_EXP_KEYS = INFLUXDB_FIFLD_REDIS_CACHE_KEYS + ",exp=expire"
|
||||
INFLUXDB_FIFLD_REDIS_DATA_MEM_USAGE = "dcs_datamem.used_byte"
|
||||
INFLUXDB_FIFLD_REDIS_SERVER_LOAD = "dcs_cpu.server_load"
|
||||
INFLUXDB_FIFLD_REDIS_CONN_ERRORS = "dcs_conn.errors"
|
||||
|
||||
//对象存储OSS监控指标
|
||||
INFLUXDB_FIELD_OSS_NET_BPS_RX = "oss_netio.bps_recv"
|
||||
@@ -94,20 +100,22 @@ const (
|
||||
INFLUXDB_FIELD_OSS_REQ_COUNT_4XX = INFLUXDB_FIELD_OSS_REQ_COUNT + ",request=4xx"
|
||||
|
||||
//负载均衡监控指标
|
||||
INFLUXDB_FIELD_ELB_NET_BPS_RX = "haproxy.bin"
|
||||
INFLUXDB_FIELD_ELB_NET_BPS_TX = "haproxy.bout"
|
||||
INFLUXDB_FIELD_ELB_REQ_RATE = "haproxy.req_rate,request=http"
|
||||
INFLUXDB_FIELD_ELB_CONN_RATE = "haproxy.conn_rate,request=tcp"
|
||||
INFLUXDB_FIELD_ELB_DREQ_COUNT = "haproxy.dreq,request=http"
|
||||
INFLUXDB_FIELD_ELB_DCONN_COUNT = "haproxy.dcon,request=tcp"
|
||||
INFLUXDB_FIELD_ELB_HRSP_COUNT = "haproxy.hrsp_Nxx"
|
||||
INFLUXDB_FIELD_ELB_HRSP_COUNT_2XX = INFLUXDB_FIELD_ELB_HRSP_COUNT + ",request=2xx"
|
||||
INFLUXDB_FIELD_ELB_HRSP_COUNT_3XX = INFLUXDB_FIELD_ELB_HRSP_COUNT + ",request=3xx"
|
||||
INFLUXDB_FIELD_ELB_HRSP_COUNT_4XX = INFLUXDB_FIELD_ELB_HRSP_COUNT + ",request=4xx"
|
||||
INFLUXDB_FIELD_ELB_HRSP_COUNT_5XX = INFLUXDB_FIELD_ELB_HRSP_COUNT + ",request=5xx"
|
||||
INFLUXDB_FIELD_ELB_CHC_STATUS = "haproxy.check_status"
|
||||
INFLUXDB_FIELD_ELB_CHC_CODE = "haproxy.check_code"
|
||||
INFLUXDB_FIELD_ELB_LAST_CHC = "haproxy.last_chk"
|
||||
INFLUXDB_FIELD_ELB_NET_BPS_RX = "haproxy.bin"
|
||||
INFLUXDB_FIELD_ELB_NET_BPS_TX = "haproxy.bout"
|
||||
INFLUXDB_FIELD_ELB_REQ_RATE = "haproxy.req_rate,request=http"
|
||||
INFLUXDB_FIELD_ELB_CONN_RATE = "haproxy.conn_rate,request=tcp"
|
||||
INFLUXDB_FIELD_ELB_DREQ_COUNT = "haproxy.dreq,request=http"
|
||||
INFLUXDB_FIELD_ELB_DCONN_COUNT = "haproxy.dcon,request=tcp"
|
||||
INFLUXDB_FIELD_ELB_HRSP_COUNT = "haproxy.hrsp_Nxx"
|
||||
INFLUXDB_FIELD_ELB_HRSP_COUNT_2XX = INFLUXDB_FIELD_ELB_HRSP_COUNT + ",request=2xx"
|
||||
INFLUXDB_FIELD_ELB_HRSP_COUNT_3XX = INFLUXDB_FIELD_ELB_HRSP_COUNT + ",request=3xx"
|
||||
INFLUXDB_FIELD_ELB_HRSP_COUNT_4XX = INFLUXDB_FIELD_ELB_HRSP_COUNT + ",request=4xx"
|
||||
INFLUXDB_FIELD_ELB_HRSP_COUNT_5XX = INFLUXDB_FIELD_ELB_HRSP_COUNT + ",request=5xx"
|
||||
INFLUXDB_FIELD_ELB_CHC_STATUS = "haproxy.check_status"
|
||||
INFLUXDB_FIELD_ELB_CHC_CODE = "haproxy.check_code"
|
||||
INFLUXDB_FIELD_ELB_LAST_CHC = "haproxy.last_chk"
|
||||
INFLUXDB_FIELD_ELB_SNAT_PORT = "haproxy.used_snat_port"
|
||||
INFLUXDB_FIELD_ELB_SNAT_CONN_COUNT = "haproxy.snat_conn_count"
|
||||
|
||||
KEY_VMS = "vms"
|
||||
KEY_CPUS = "cpus"
|
||||
@@ -133,6 +141,10 @@ const (
|
||||
MetricKeyClassicNetworkOut = "Network Out"
|
||||
MetricKeyClassicDiskReadBPS = "Disk Read Bytes/Sec"
|
||||
MetricKeyClassicDiskWriteBPS = "Disk Write Bytes/Sec"
|
||||
|
||||
SERVER_METRIC_NAMESPACE = "Microsoft.Compute/virtualMachines"
|
||||
REDIS_METRIC_NAMESPACE = "Microsoft.Cache/redis"
|
||||
ELB_METRIC_NAMESPACE = "Microsoft.Network/loadBalancers"
|
||||
)
|
||||
|
||||
var azureMetricSpecs = map[string][]string{
|
||||
@@ -154,3 +166,39 @@ var azureClassicMetricsSpec = map[string][]string{
|
||||
MetricKeyDiskReadOPS: {DEFAULT_STATISTICS, UNIT_COUNT_SEC, INFLUXDB_FIELD_DISK_READ_IOPS},
|
||||
MetricKeyDiskWriteOPS: {DEFAULT_STATISTICS, UNIT_COUNT_SEC, INFLUXDB_FIELD_DISK_WRITE_IOPS},
|
||||
}
|
||||
|
||||
var azureRedisMetricsSpec = map[string][]string{
|
||||
"percentProcessorTime": {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIELD_REDIS_CPU_USAGE},
|
||||
"usedmemorypercentage": {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIELD_REDIS_MEM_USAGE},
|
||||
"connectedclients": {DEFAULT_STATISTICS, UNIT_COUNT, INFLUXDB_FIFLD_REDIS_CONN_USAGE},
|
||||
"operationsPerSecond": {DEFAULT_STATISTICS, UNIT_COUNT, INFLUXDB_FIFLD_REDIS_OPT_SES},
|
||||
"alltotalkeys": {DEFAULT_STATISTICS, UNIT_COUNT, INFLUXDB_FIFLD_REDIS_CACHE_KEYS},
|
||||
"expiredkeys": {DEFAULT_STATISTICS, UNIT_COUNT, INFLUXDB_FIFLD_REDIS_CACHE_EXP_KEYS},
|
||||
"usedmemory": {DEFAULT_STATISTICS, UNIT_BYTES, INFLUXDB_FIFLD_REDIS_DATA_MEM_USAGE},
|
||||
"serverLoad": {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIFLD_REDIS_SERVER_LOAD},
|
||||
"errors": {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIFLD_REDIS_CONN_ERRORS},
|
||||
}
|
||||
|
||||
//mariadb,mysql,postgresql
|
||||
var azureRdsMetricsSpec = map[string][]string{
|
||||
"cpu_percent": {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIELD_RDS_CPU_USAGE},
|
||||
"memory_percent": {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIELD_RDS_MEM_USAGE},
|
||||
"storage_percent": {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIELD_RDS_DISK_USAGE},
|
||||
"network_bytes_ingress": {DEFAULT_STATISTICS, UNIT_BYTES, INFLUXDB_FIELD_RDS_NET_BPS_RX},
|
||||
"network_bytes_egress": {DEFAULT_STATISTICS, UNIT_BYTES, INFLUXDB_FIELD_RDS_NET_BPS_TX},
|
||||
"io_consumption_percent": {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIELD_RDS_DISK_IO_PERSENT},
|
||||
"active_connections": {DEFAULT_STATISTICS, UNIT_COUNT, INFLUXDB_FIELD_RDS_CONN_ACTIVE},
|
||||
"connections_failed": {DEFAULT_STATISTICS, UNIT_COUNT, INFLUXDB_FIELD_RDS_CONN_FAILED},
|
||||
}
|
||||
|
||||
var azureRdsMetricsSpecSqlserver = map[string][]string{
|
||||
"cpu_percent": {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIELD_RDS_CPU_USAGE},
|
||||
"memory_usage_percent": {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIELD_RDS_MEM_USAGE},
|
||||
"storage_percent": {DEFAULT_STATISTICS, UNIT_PERCENT, INFLUXDB_FIELD_RDS_DISK_USAGE},
|
||||
"connections_failed": {DEFAULT_STATISTICS, UNIT_COUNT, INFLUXDB_FIELD_RDS_CONN_FAILED},
|
||||
}
|
||||
|
||||
var azureElbMetricSpecs = map[string][]string{
|
||||
"SnatConnectionCount": {DEFAULT_STATISTICS, UNIT_COUNT, INFLUXDB_FIELD_ELB_SNAT_PORT},
|
||||
"UsedSnatPorts": {DEFAULT_STATISTICS, UNIT_COUNT, INFLUXDB_FIELD_ELB_SNAT_CONN_COUNT},
|
||||
}
|
||||
|
||||
@@ -47,6 +47,24 @@ func (self *CloudReportBase) Report() error {
|
||||
return fmt.Errorf("No Implment the method")
|
||||
}
|
||||
|
||||
func (self *CloudReportBase) GetResourceByOperator() ([]jsonutils.JSONObject, error) {
|
||||
var servers []jsonutils.JSONObject
|
||||
var err error
|
||||
switch MonType(self.Operator) {
|
||||
case REDIS:
|
||||
servers, err = self.GetAllserverOfThisProvider(&modules.ElasticCache)
|
||||
case RDS:
|
||||
servers, err = self.GetAllserverOfThisProvider(&modules.DBInstance)
|
||||
case OSS:
|
||||
servers, err = self.GetAllserverOfThisProvider(&modules.Buckets)
|
||||
case ELB:
|
||||
servers, err = self.GetAllserverOfThisProvider(&modules.Loadbalancers)
|
||||
default:
|
||||
servers, err = self.GetAllserverOfThisProvider(&modules.Servers)
|
||||
}
|
||||
return servers, err
|
||||
}
|
||||
|
||||
func (self *CloudReportBase) GetAllserverOfThisProvider(manager modulebase.Manager) ([]jsonutils.JSONObject, error) {
|
||||
query := jsonutils.NewDict()
|
||||
|
||||
|
||||
@@ -14,6 +14,14 @@
|
||||
|
||||
package cloudprovider
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/gotypes"
|
||||
)
|
||||
|
||||
// +onecloud:model-api-gen
|
||||
type SCdnDomain struct {
|
||||
// cdn加速域名
|
||||
Domain string
|
||||
@@ -28,3 +36,32 @@ type SCdnDomain struct {
|
||||
// 源站类型 domain|ip|bucket
|
||||
OriginType string
|
||||
}
|
||||
|
||||
// +onecloud:model-api-gen
|
||||
type SCdnOrigin struct {
|
||||
Type string
|
||||
Origin string
|
||||
ServerName string
|
||||
Protocol string
|
||||
Path string
|
||||
Port int
|
||||
Enabled string
|
||||
Priority int
|
||||
}
|
||||
|
||||
// +onecloud:model-api-gen
|
||||
type SCdnOrigins []SCdnOrigin
|
||||
|
||||
func (self SCdnOrigins) IsZero() bool {
|
||||
return len(self) == 0
|
||||
}
|
||||
|
||||
func (self SCdnOrigins) String() string {
|
||||
return jsonutils.Marshal(self).String()
|
||||
}
|
||||
|
||||
func init() {
|
||||
gotypes.RegisterSerializable(reflect.TypeOf(&SCdnOrigins{}), func() gotypes.ISerializable {
|
||||
return &SCdnOrigins{}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1508,6 +1508,8 @@ type ICloudCDNDomain interface {
|
||||
|
||||
GetArea() string
|
||||
GetServiceType() string
|
||||
GetCname() string
|
||||
GetOrigins() *SCdnOrigins
|
||||
|
||||
Delete() error
|
||||
}
|
||||
|
||||
@@ -94,9 +94,19 @@ func (man *SProxyEndpointManager) PerformCreateFromServer(ctx context.Context, u
|
||||
return nil, httperrors.NewBadRequestError("cannot find ssh host ip address for this server")
|
||||
}
|
||||
|
||||
name := input.Name
|
||||
if name == "" {
|
||||
name = serverInfo.Server.Name
|
||||
var name string
|
||||
if len(input.Name) > 0 {
|
||||
name = input.Name
|
||||
} else if len(input.GenerateName) > 0 {
|
||||
name, err = db.GenerateName(ctx, man, userCred, input.GenerateName)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "db.GenerateName")
|
||||
}
|
||||
} else {
|
||||
name, err = db.GenerateName(ctx, man, userCred, serverInfo.Server.Name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "db.GenerateName")
|
||||
}
|
||||
}
|
||||
if err := db.NewNameValidator(man, userCred, name, nil); err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
@@ -244,6 +254,26 @@ func (proxyendpoint *SProxyEndpoint) ValidateDeleteCondition(ctx context.Context
|
||||
}
|
||||
}
|
||||
|
||||
func (proxyendpoint *SProxyEndpoint) AllowPerformPurgeForwards(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool {
|
||||
return proxyendpoint.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, proxyendpoint, "purge-forwards")
|
||||
}
|
||||
|
||||
func (proxyendpoint *SProxyEndpoint) PerformPurgeForwards(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
q := ForwardManager.Query().Equals("proxy_endpoint_id", proxyendpoint.Id)
|
||||
forwards := make([]SForward, 0)
|
||||
err := db.FetchModelObjects(ForwardManager, q, &forwards)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to fetch all forwards for proxyendpoint %s", proxyendpoint.Id)
|
||||
}
|
||||
for i := range forwards {
|
||||
err := forwards[i].Delete(ctx, userCred)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to delete forward %s", forwards[i].Id)
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (proxyendpoint *SProxyEndpoint) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
var pms []SProxyMatch
|
||||
q := ProxyMatchManager.Query().Equals("proxy_endpoint_id", proxyendpoint.Id)
|
||||
|
||||
@@ -411,6 +411,10 @@ func (self *SBaseGuestDriver) RequestLiveMigrate(ctx context.Context, guest *mod
|
||||
return fmt.Errorf("Not Implement RequestLiveMigrate")
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, input api.ServerUpdateInput) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) RequestRemoteUpdate(ctx context.Context, guest *models.SGuest, userCred mcclient.TokenCredential, replaceTags bool) error {
|
||||
// nil ops
|
||||
return nil
|
||||
@@ -423,3 +427,20 @@ func (self *SBaseGuestDriver) ValidateRebuildRoot(ctx context.Context, userCred
|
||||
func (self *SBaseGuestDriver) ValidateDetachNetwork(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) ValidateChangeDiskStorage(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, input *api.ServerChangeDiskStorageInput) error {
|
||||
return cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) StartChangeDiskStorageTask(guest *models.SGuest, ctx context.Context, userCred mcclient.TokenCredential, params *api.ServerChangeDiskStorageInternalInput, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "GuestChangeDiskStorageTask", guest, userCred, jsonutils.Marshal(params).(*jsonutils.JSONDict), parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) RequestChangeDiskStorage(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, input *api.ServerChangeDiskStorageInternalInput, task taskman.ITask) error {
|
||||
return cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -638,6 +638,49 @@ func (self *SESXiGuestDriver) RequestLiveMigrate(ctx context.Context, guest *mod
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) RequestStartOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, userCred mcclient.TokenCredential, task taskman.ITask) error {
|
||||
ivm, err := guest.GetIVM()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetIVM")
|
||||
}
|
||||
|
||||
result := jsonutils.NewDict()
|
||||
if ivm.GetStatus() != api.VM_RUNNING {
|
||||
err := ivm.StartVM(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "StartVM")
|
||||
}
|
||||
err = cloudprovider.WaitStatus(ivm, api.VM_RUNNING, time.Second*5, time.Minute*10)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Wait vm running")
|
||||
}
|
||||
guest.SetStatus(userCred, api.VM_RUNNING, "StartOnHost")
|
||||
return task.ScheduleRun(result)
|
||||
}
|
||||
return guest.SetStatus(userCred, api.VM_RUNNING, "StartOnHost")
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) RequestStopOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
ivm, err := guest.GetIVM()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "guest.GetIVM")
|
||||
}
|
||||
opts := &cloudprovider.ServerStopOptions{}
|
||||
task.GetParams().Unmarshal(opts)
|
||||
err = ivm.StopVM(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "ivm.StopVM")
|
||||
}
|
||||
err = cloudprovider.WaitStatus(ivm, api.VM_READY, time.Second*3, time.Minute*5)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "wait server stop after 5 miniutes")
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
return 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 {
|
||||
|
||||
@@ -775,3 +775,44 @@ func (self *SKVMGuestDriver) ValidateDetachNetwork(ctx context.Context, userCred
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) ValidateChangeDiskStorage(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, input *api.ServerChangeDiskStorageInput) error {
|
||||
// kvm guest must in ready status
|
||||
if !utils.IsInStringArray(guest.Status, []string{api.VM_READY}) {
|
||||
return httperrors.NewBadRequestError("Cannot change disk storage in status %s", guest.Status)
|
||||
}
|
||||
|
||||
// backup guest not supported
|
||||
if guest.BackupHostId != "" {
|
||||
return httperrors.NewBadRequestError("Cannot change disk storage in backup guest %s", guest.GetName())
|
||||
}
|
||||
|
||||
// storage must attached on guest's host
|
||||
host, err := guest.GetHost()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Get guest %s host", guest.GetName())
|
||||
}
|
||||
attachedStorages := host.GetAttachedEnabledHostStorages(nil)
|
||||
foundStorage := false
|
||||
for _, storage := range attachedStorages {
|
||||
if storage.GetId() == input.TargetStorageId {
|
||||
foundStorage = true
|
||||
}
|
||||
}
|
||||
if !foundStorage {
|
||||
return httperrors.NewBadRequestError("Storage %s not attached or enabled on host %s", input.TargetStorageId, host.GetName())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) RequestChangeDiskStorage(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, input *api.ServerChangeDiskStorageInternalInput, task taskman.ITask) error {
|
||||
host, err := guest.GetHost()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
body := jsonutils.Marshal(input)
|
||||
header := self.getTaskRequestHeader(task)
|
||||
url := fmt.Sprintf("%s/servers/%s/storage-clone-disk", host.ManagerUri, guest.GetId())
|
||||
_, _, err = httputils.JSONRequest(httputils.GetDefaultClient(), ctx, "POST", url, header, body, false)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -539,6 +539,20 @@ func (self *SManagedVirtualizedGuestDriver) RemoteDeployGuestForCreate(ctx conte
|
||||
return nil, errors.Wrapf(err, "GuestDriver.RemoteDeployGuestForCreate.RetryUntil expect %d disks return %d disks", expect, ret)
|
||||
}
|
||||
|
||||
// 回填IP
|
||||
if len(desc.IpAddr) == 0 {
|
||||
nics, _ := iVM.GetINics()
|
||||
gns, _ := guest.GetNetworks("")
|
||||
if len(nics) > 0 && len(gns) > 0 {
|
||||
db.Update(&gns[0], func() error {
|
||||
gns[0].IpAddr = nics[0].GetIP()
|
||||
gns[0].MacAddr = nics[0].GetMAC()
|
||||
gns[0].Driver = nics[0].GetDriver()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
guest.GetDriver().RemoteActionAfterGuestCreated(ctx, userCred, guest, host, iVM, &desc)
|
||||
|
||||
data := fetchIVMinfo(desc, iVM, guest.Id, desc.Account, desc.Password, desc.PublicKey, "create")
|
||||
|
||||
@@ -265,10 +265,31 @@ func (self *SVirtualizedGuestDriver) RequestStopGuestForDelete(ctx context.Conte
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVirtualizedGuestDriver) ValidateMachineType(machine string) error {
|
||||
if !utils.IsInStringArray(machine, []string{api.VM_MACHINE_TYPE_PC, api.VM_MACHINE_TYPE_Q35}) {
|
||||
return httperrors.NewBadRequestError("Invalid machine %q", machine)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVirtualizedGuestDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, input *api.ServerCreateInput) (*api.ServerCreateInput, error) {
|
||||
if input.Machine != "" {
|
||||
if err := self.ValidateMachineType(input.Machine); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SVirtualizedGuestDriver) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, input api.ServerUpdateInput) error {
|
||||
if input.Machine != nil {
|
||||
if err := self.ValidateMachineType(*input.Machine); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVirtualizedGuestDriver) ValidateCreateDataOnHost(ctx context.Context, userCred mcclient.TokenCredential, bmName string, host *models.SHost, input *api.ServerCreateInput) (*api.ServerCreateInput, error) {
|
||||
if host.HostStatus != api.HOST_ONLINE {
|
||||
return nil, httperrors.NewInvalidStatusError("Host %s is not online", bmName)
|
||||
|
||||
@@ -81,7 +81,7 @@ func (self *SBaremetalHostDriver) CheckAndSetCacheImage(ctx context.Context, hos
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SBaremetalHostDriver) RequestAllocateDiskOnStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, content *jsonutils.JSONDict) error {
|
||||
func (self *SBaremetalHostDriver) RequestAllocateDiskOnStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, input api.DiskAllocateInput) error {
|
||||
return fmt.Errorf("not supported")
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (self *SBaremetalHostDriver) RequestPrepareSaveDiskOnHost(ctx context.Conte
|
||||
return fmt.Errorf("not supported")
|
||||
}
|
||||
|
||||
func (self *SBaremetalHostDriver) RequestRebuildDiskOnStorage(ctx context.Context, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, content *jsonutils.JSONDict) error {
|
||||
func (self *SBaremetalHostDriver) RequestRebuildDiskOnStorage(ctx context.Context, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, input api.DiskAllocateInput) error {
|
||||
return fmt.Errorf("not supported")
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ func (self *SBaseHostDriver) ValidateResetDisk(ctx context.Context, userCred mcc
|
||||
return nil, httperrors.NewNotImplementedError("Not Implement ValidateResetDisk")
|
||||
}
|
||||
|
||||
func (self *SBaseHostDriver) ValidateAttachStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
return httperrors.NewNotImplementedError("Not Implement ValidateAttachStorage")
|
||||
func (self *SBaseHostDriver) ValidateAttachStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, input api.HostStorageCreateInput) (api.HostStorageCreateInput, error) {
|
||||
return input, httperrors.NewNotImplementedError("Not Implement ValidateAttachStorage")
|
||||
}
|
||||
|
||||
func (self *SBaseHostDriver) RequestAttachStorage(ctx context.Context, hoststorage *models.SHoststorage, host *models.SHost, storage *models.SStorage, task taskman.ITask) error {
|
||||
|
||||
@@ -181,29 +181,26 @@ func (self *SESXiHostDriver) CheckAndSetCacheImage(ctx context.Context, host *mo
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SESXiHostDriver) RequestAllocateDiskOnStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, content *jsonutils.JSONDict) error {
|
||||
func (self *SESXiHostDriver) RequestAllocateDiskOnStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, input api.DiskAllocateInput) error {
|
||||
if !host.IsEsxiAgentReady() {
|
||||
return fmt.Errorf("fail to find valid ESXi agent")
|
||||
}
|
||||
|
||||
type specStruct struct {
|
||||
Datastore vcenter.SVCenterAccessInfo
|
||||
HostIp string
|
||||
Format string
|
||||
}
|
||||
|
||||
spec := specStruct{}
|
||||
spec.HostIp = host.AccessIp
|
||||
spec.Format = "vmdk"
|
||||
input.HostIp = host.AccessIp
|
||||
input.Format = "vmdk"
|
||||
|
||||
accessInfo, err := host.GetCloudaccount().GetVCenterAccessInfo(storage.ExternalId)
|
||||
var err error
|
||||
input.Datastore, err = host.GetCloudaccount().GetVCenterAccessInfo(storage.ExternalId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
spec.Datastore = accessInfo
|
||||
|
||||
body := jsonutils.NewDict()
|
||||
body.Add(jsonutils.Marshal(&spec), "disk")
|
||||
body.Add(jsonutils.Marshal(&input), "disk")
|
||||
|
||||
url := fmt.Sprintf("/disks/agent/create/%s", disk.Id)
|
||||
|
||||
|
||||
@@ -59,48 +59,47 @@ func (self *SKVMHostDriver) GetHypervisor() string {
|
||||
return api.HYPERVISOR_KVM
|
||||
}
|
||||
|
||||
func (self *SKVMHostDriver) ValidateAttachStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
func (self *SKVMHostDriver) ValidateAttachStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, input api.HostStorageCreateInput) (api.HostStorageCreateInput, error) {
|
||||
if !utils.IsInStringArray(storage.StorageType, append([]string{api.STORAGE_LOCAL}, api.SHARED_STORAGE...)) {
|
||||
return httperrors.NewUnsupportOperationError("Unsupport attach %s storage for %s host", storage.StorageType, host.HostType)
|
||||
return input, httperrors.NewUnsupportOperationError("Unsupport attach %s storage for %s host", storage.StorageType, host.HostType)
|
||||
}
|
||||
if storage.StorageType == api.STORAGE_RBD {
|
||||
if host.HostStatus != api.HOST_ONLINE {
|
||||
return httperrors.NewInvalidStatusError("Attach rbd storage require host status is online")
|
||||
return input, httperrors.NewInvalidStatusError("Attach rbd storage require host status is online")
|
||||
}
|
||||
pool, _ := storage.StorageConf.GetString("pool")
|
||||
data.Set("mount_point", jsonutils.NewString(fmt.Sprintf("rbd:%s", pool)))
|
||||
input.MountPoint = fmt.Sprintf("rbd:%s", pool)
|
||||
} else if utils.IsInStringArray(storage.StorageType, api.SHARED_FILE_STORAGE) {
|
||||
mountPoint, err := data.GetString("mount_point")
|
||||
if err != nil {
|
||||
return httperrors.NewMissingParameterError("mount_point")
|
||||
if len(input.MountPoint) == 0 {
|
||||
return input, httperrors.NewMissingParameterError("mount_point")
|
||||
}
|
||||
count, err := models.HoststorageManager.Query().Equals("host_id", host.Id).Equals("mount_point", mountPoint).CountWithError()
|
||||
count, err := models.HoststorageManager.Query().Equals("host_id", host.Id).Equals("mount_point", input.MountPoint).CountWithError()
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("Query host storage error %s", err)
|
||||
return input, httperrors.NewInternalServerError("Query host storage error %s", err)
|
||||
}
|
||||
if count > 0 {
|
||||
return httperrors.NewBadRequestError("Host %s already have mount point %s with other storage", host.Name, mountPoint)
|
||||
return input, httperrors.NewBadRequestError("Host %s already have mount point %s with other storage", host.Name, input.MountPoint)
|
||||
}
|
||||
if host.HostStatus != api.HOST_ONLINE {
|
||||
return httperrors.NewInvalidStatusError("Attach nfs storage require host status is online")
|
||||
return input, httperrors.NewInvalidStatusError("Attach nfs storage require host status is online")
|
||||
}
|
||||
if storage.StorageType == api.STORAGE_GPFS {
|
||||
header := http.Header{}
|
||||
header.Set(mcclient.AUTH_TOKEN, userCred.GetTokenString())
|
||||
header.Set(mcclient.REGION_VERSION, "v2")
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("mount_point", jsonutils.NewString(mountPoint))
|
||||
params.Set("mount_point", jsonutils.NewString(input.MountPoint))
|
||||
urlStr := fmt.Sprintf("%s/storages/is-mount-point?%s", host.ManagerUri, params.QueryString())
|
||||
_, res, err := httputils.JSONRequest(httputils.GetDefaultClient(), ctx, "GET", urlStr, header, nil, false)
|
||||
if err != nil {
|
||||
return err
|
||||
return input, err
|
||||
}
|
||||
if !jsonutils.QueryBoolean(res, "is_mount_point", false) {
|
||||
return httperrors.NewBadRequestError("%s is not mount point %s", mountPoint, res)
|
||||
return input, httperrors.NewBadRequestError("%s is not mount point %s", input.MountPoint, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SKVMHostDriver) RequestAttachStorage(ctx context.Context, hoststorage *models.SHoststorage, host *models.SHost, storage *models.SStorage, task taskman.ITask) error {
|
||||
@@ -141,6 +140,7 @@ func (self *SKVMHostDriver) RequestDetachStorage(ctx context.Context, host *mode
|
||||
mountPoint, _ := task.GetParams().GetString("mount_point")
|
||||
body.Set("mount_point", jsonutils.NewString(mountPoint))
|
||||
body.Set("name", jsonutils.NewString(storage.Name))
|
||||
body.Set("storage_id", jsonutils.NewString(storage.Id))
|
||||
_, resp, err := httputils.JSONRequest(httputils.GetDefaultClient(), ctx, "POST", url, headers, body, false)
|
||||
return resp, err
|
||||
}
|
||||
@@ -259,48 +259,44 @@ func (self *SKVMHostDriver) RequestUncacheImage(ctx context.Context, host *model
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMHostDriver) RequestAllocateDiskOnStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, content *jsonutils.JSONDict) error {
|
||||
func (self *SKVMHostDriver) RequestAllocateDiskOnStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, input api.DiskAllocateInput) error {
|
||||
header := task.GetTaskRequestHeader()
|
||||
if snapshotId, err := content.GetString("snapshot"); err == nil {
|
||||
iSnapshot, _ := models.SnapshotManager.FetchById(snapshotId)
|
||||
snapshot := iSnapshot.(*models.SSnapshot)
|
||||
if len(input.SnapshotId) > 0 {
|
||||
snapObj, err := models.SnapshotManager.FetchById(input.SnapshotId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "SnapshotManager.FetchById(%s)", input.SnapshotId)
|
||||
}
|
||||
snapshot := snapObj.(*models.SSnapshot)
|
||||
snapshotStorage := models.StorageManager.FetchStorageById(snapshot.StorageId)
|
||||
if snapshotStorage.StorageType == api.STORAGE_LOCAL {
|
||||
snapshotHost := snapshotStorage.GetMasterHost()
|
||||
if options.Options.SnapshotCreateDiskProtocol == "url" {
|
||||
content.Set("snapshot_url",
|
||||
jsonutils.NewString(fmt.Sprintf("%s/download/snapshots/%s/%s/%s",
|
||||
snapshotHost.ManagerUri, snapshotStorage.Id, snapshot.DiskId, snapshot.Id)))
|
||||
content.Set("snapshot_out_of_chain", jsonutils.NewBool(snapshot.OutOfChain))
|
||||
input.SnapshotUrl = fmt.Sprintf("%s/download/snapshots/%s/%s/%s", snapshotHost.ManagerUri, snapshotStorage.Id, snapshot.DiskId, snapshot.Id)
|
||||
input.SnapshotOutOfChain = snapshot.OutOfChain
|
||||
} else if options.Options.SnapshotCreateDiskProtocol == "fuse" {
|
||||
content.Set("snapshot_url", jsonutils.NewString(fmt.Sprintf("%s/snapshots/%s/%s",
|
||||
snapshotHost.GetFetchUrl(true), snapshot.DiskId, snapshot.Id)))
|
||||
input.SnapshotUrl = fmt.Sprintf("%s/snapshots/%s/%s", snapshotHost.GetFetchUrl(true), snapshot.DiskId, snapshot.Id)
|
||||
}
|
||||
content.Set("protocol", jsonutils.NewString(options.Options.SnapshotCreateDiskProtocol))
|
||||
input.Protocol = options.Options.SnapshotCreateDiskProtocol
|
||||
} else if snapshotStorage.StorageType == api.STORAGE_RBD {
|
||||
pool, _ := snapshotStorage.StorageConf.GetString("pool")
|
||||
content.Set("snapshot_url", jsonutils.NewString(snapshot.Id))
|
||||
content.Set("src_disk_id", jsonutils.NewString(snapshot.DiskId))
|
||||
content.Set("src_pool", jsonutils.NewString(pool))
|
||||
input.SnapshotUrl = snapshot.Id
|
||||
input.SrcDiskId = snapshot.DiskId
|
||||
input.SrcPool, _ = snapshotStorage.StorageConf.GetString("pool")
|
||||
} else {
|
||||
content.Set("snapshot_url", jsonutils.NewString(snapshot.Location))
|
||||
input.SnapshotUrl = snapshot.Location
|
||||
}
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("/disks/%s/create/%s", storage.Id, disk.Id)
|
||||
body := jsonutils.NewDict()
|
||||
body.Add(content, "disk")
|
||||
body.Add(jsonutils.Marshal(input), "disk")
|
||||
_, err := host.Request(ctx, task.GetUserCred(), "POST", url, header, body)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SKVMHostDriver) RequestRebuildDiskOnStorage(ctx context.Context, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, content *jsonutils.JSONDict) error {
|
||||
content.Add(jsonutils.JSONTrue, "rebuild")
|
||||
if task.GetParams().Contains("backing_disk_id") {
|
||||
backingDiskId, _ := task.GetParams().GetString("backing_disk_id")
|
||||
content.Set("backing_disk_id", jsonutils.NewString(backingDiskId))
|
||||
}
|
||||
return self.RequestAllocateDiskOnStorage(ctx, task.GetUserCred(), host, storage, disk, task, content)
|
||||
func (self *SKVMHostDriver) RequestRebuildDiskOnStorage(ctx context.Context, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, input api.DiskAllocateInput) error {
|
||||
input.Rebuild = true
|
||||
input.BackingDiskId, _ = task.GetParams().GetString("backing_disk_id")
|
||||
return self.RequestAllocateDiskOnStorage(ctx, task.GetUserCred(), host, storage, disk, task, input)
|
||||
}
|
||||
|
||||
func (self *SKVMHostDriver) RequestDeallocateDiskOnHost(ctx context.Context, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask) error {
|
||||
|
||||
@@ -237,16 +237,11 @@ func (self *SManagedVirtualizationHostDriver) RequestResizeDiskOnHost(ctx contex
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationHostDriver) RequestAllocateDiskOnStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, content *jsonutils.JSONDict) error {
|
||||
func (self *SManagedVirtualizationHostDriver) RequestAllocateDiskOnStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, input api.DiskAllocateInput) error {
|
||||
iCloudStorage, err := storage.GetIStorage()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
size, err := content.Int("size")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
size = size >> 10
|
||||
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
_cloudprovider := storage.GetCloudprovider()
|
||||
@@ -259,7 +254,7 @@ func (self *SManagedVirtualizationHostDriver) RequestAllocateDiskOnStorage(ctx c
|
||||
}
|
||||
conf := cloudprovider.DiskCreateConfig{
|
||||
Name: disk.GetName(),
|
||||
SizeGb: int(size),
|
||||
SizeGb: input.DiskSizeMb >> 10,
|
||||
ProjectId: projectId,
|
||||
}
|
||||
iDisk, err := iCloudStorage.CreateIDisk(&conf)
|
||||
@@ -333,7 +328,7 @@ func (self *SManagedVirtualizationHostDriver) RequestResetDisk(ctx context.Conte
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationHostDriver) RequestRebuildDiskOnStorage(ctx context.Context, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, content *jsonutils.JSONDict) error {
|
||||
func (self *SManagedVirtualizationHostDriver) RequestRebuildDiskOnStorage(ctx context.Context, host *models.SHost, storage *models.SStorage, disk *models.SDisk, task taskman.ITask, input api.DiskAllocateInput) error {
|
||||
iDisk, err := disk.GetIDisk()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -20,15 +20,18 @@ import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -286,6 +289,10 @@ func (self *SCloudregion) newFromCloudApp(ctx context.Context, userCred mcclient
|
||||
SyncCloudProject(userCred, &app, provider.GetOwnerId(), ext, provider.Id)
|
||||
|
||||
db.OpsLog.LogEvent(&app, db.ACT_CREATE, app.GetShortDesc(ctx), userCred)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &app,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
return &app, nil
|
||||
}
|
||||
@@ -319,11 +326,19 @@ func (a *SApp) purge(ctx context.Context, userCred mcclient.TokenCredential) err
|
||||
}
|
||||
|
||||
func (a *SApp) syncRemoveCloudApp(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return a.purge(ctx, userCred)
|
||||
err := a.purge(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: a,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *SApp) SyncWithCloudApp(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, ext cloudprovider.ICloudApp) error {
|
||||
_, err := db.UpdateWithLock(ctx, a, func() error {
|
||||
diff, err := db.UpdateWithLock(ctx, a, func() error {
|
||||
a.ExternalId = ext.GetGlobalId()
|
||||
a.Status = ext.GetStatus()
|
||||
a.Type = ext.GetType()
|
||||
@@ -342,6 +357,12 @@ func (a *SApp) SyncWithCloudApp(ctx context.Context, userCred mcclient.TokenCred
|
||||
if result.IsError() {
|
||||
return result.AllError()
|
||||
}
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: a,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -397,3 +418,36 @@ func (a *SApp) GetIApp() (cloudprovider.ICloudApp, error) {
|
||||
}
|
||||
return iRegion.GetICloudAppById(a.ExternalId)
|
||||
}
|
||||
|
||||
func (self *SApp) AllowPerformRemoteUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "remote-update")
|
||||
}
|
||||
|
||||
func (self *SApp) PerformRemoteUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.MongoDBRemoteUpdateInput) (jsonutils.JSONObject, error) {
|
||||
err := self.StartRemoteUpdateTask(ctx, userCred, (input.ReplaceTags != nil && *input.ReplaceTags), "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "StartRemoteUpdateTask")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SApp) StartRemoteUpdateTask(ctx context.Context, userCred mcclient.TokenCredential, replaceTags bool, parentTaskId string) error {
|
||||
data := jsonutils.NewDict()
|
||||
data.Add(jsonutils.NewBool(replaceTags), "replace_tags")
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "AppRemoteUpdateTask", self, userCred, data, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "NewTask")
|
||||
}
|
||||
self.SetStatus(userCred, apis.STATUS_UPDATE_TAGS, "StartRemoteUpdateTask")
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SApp) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
if len(self.ExternalId) == 0 {
|
||||
return
|
||||
}
|
||||
err := self.StartRemoteUpdateTask(ctx, userCred, true, "")
|
||||
if err != nil {
|
||||
log.Errorf("StartRemoteUpdateTask fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -232,6 +233,10 @@ func (manager *SBucketManager) newFromCloudBucket(
|
||||
}
|
||||
|
||||
SyncCloudProject(userCred, &bucket, provider.GetOwnerId(), extBucket, provider.Id)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &bucket,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
bucket.SyncShareState(ctx, userCred, provider.getAccountShareInfo())
|
||||
|
||||
syncVirtualResourceMetadata(ctx, userCred, &bucket, extBucket)
|
||||
@@ -308,6 +313,12 @@ func (bucket *SBucket) syncWithCloudBucket(
|
||||
syncVirtualResourceMetadata(ctx, userCred, bucket, extBucket)
|
||||
|
||||
db.OpsLog.LogSyncUpdate(bucket, diff, userCred)
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: bucket,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
if !oStats.Equals(extBucket.GetStats()) {
|
||||
db.OpsLog.LogEvent(bucket, api.BUCKET_OPS_STATS_CHANGE, bucket.GetShortDesc(ctx), userCred)
|
||||
@@ -332,6 +343,10 @@ func (bucket *SBucket) syncRemoveCloudBucket(
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "RealDelete")
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: bucket,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -19,14 +19,17 @@ import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -62,6 +65,10 @@ type SCDNDomain struct {
|
||||
SDeletePreventableResourceBase
|
||||
SManagedResourceBase
|
||||
|
||||
Cname string `list:"user" width:"256"`
|
||||
|
||||
// 源站信息
|
||||
Origins *cloudprovider.SCdnOrigins `list:"user"`
|
||||
// 服务类别
|
||||
ServiceType string `list:"user" width:"32" update:"admin" create:"admin_required"`
|
||||
// 加速区域
|
||||
@@ -165,7 +172,23 @@ func (self *SCDNDomain) syncRemoveCloudCDNDomain(ctx context.Context, userCred m
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "ValidateDeleteCondition")
|
||||
}
|
||||
return self.RealDelete(ctx, userCred)
|
||||
err = self.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// 判断资源是否可以删除
|
||||
func (self *SCDNDomain) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.DisableDelete.IsTrue() {
|
||||
return httperrors.NewInvalidStatusError("CDN is locked, cannot delete")
|
||||
}
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SCDNDomain) GetICloudCDNDomain() (cloudprovider.ICloudCDNDomain, error) {
|
||||
@@ -186,12 +209,20 @@ func (self *SCDNDomain) SyncWithCloudCDNDomain(ctx context.Context, userCred mcc
|
||||
self.Status = ext.GetStatus()
|
||||
self.Area = ext.GetArea()
|
||||
self.ServiceType = ext.GetServiceType()
|
||||
self.Cname = ext.GetCname()
|
||||
self.Origins = ext.GetOrigins()
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
db.OpsLog.LogSyncUpdate(self, diff, userCred)
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
syncMetadata(ctx, userCred, self, ext)
|
||||
|
||||
if provider := self.GetCloudprovider(); provider != nil {
|
||||
@@ -212,6 +243,8 @@ func (self *SCloudprovider) newFromCloudCDNDomain(ctx context.Context, userCred
|
||||
domain.Status = ext.GetStatus()
|
||||
domain.Area = ext.GetArea()
|
||||
domain.ServiceType = ext.GetServiceType()
|
||||
domain.Cname = ext.GetCname()
|
||||
domain.Origins = ext.GetOrigins()
|
||||
|
||||
err := CDNDomainManager.TableSpec().Insert(ctx, &domain)
|
||||
if err != nil {
|
||||
@@ -224,6 +257,10 @@ func (self *SCloudprovider) newFromCloudCDNDomain(ctx context.Context, userCred
|
||||
domain.SyncShareState(ctx, userCred, self.getAccountShareInfo())
|
||||
|
||||
db.OpsLog.LogEvent(&domain, db.ACT_CREATE, domain.GetShortDesc(ctx), userCred)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &domain,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
return &domain, nil
|
||||
}
|
||||
@@ -389,3 +426,36 @@ func (self *SCDNDomain) PerformSyncstatus(ctx context.Context, userCred mcclient
|
||||
func (self *SCDNDomain) StartSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
return StartResourceSyncStatusTask(ctx, userCred, self, "CDNDomainSyncstatusTask", parentTaskId)
|
||||
}
|
||||
|
||||
func (self *SCDNDomain) AllowPerformRemoteUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "remote-update")
|
||||
}
|
||||
|
||||
func (self *SCDNDomain) PerformRemoteUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.MongoDBRemoteUpdateInput) (jsonutils.JSONObject, error) {
|
||||
err := self.StartRemoteUpdateTask(ctx, userCred, (input.ReplaceTags != nil && *input.ReplaceTags), "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "StartRemoteUpdateTask")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SCDNDomain) StartRemoteUpdateTask(ctx context.Context, userCred mcclient.TokenCredential, replaceTags bool, parentTaskId string) error {
|
||||
data := jsonutils.NewDict()
|
||||
data.Add(jsonutils.NewBool(replaceTags), "replace_tags")
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "CDNDomainRemoteUpdateTask", self, userCred, data, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "NewTask")
|
||||
}
|
||||
self.SetStatus(userCred, apis.STATUS_UPDATE_TAGS, "StartRemoteUpdateTask")
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SCDNDomain) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
if len(self.ExternalId) == 0 {
|
||||
return
|
||||
}
|
||||
err := self.StartRemoteUpdateTask(ctx, userCred, true, "")
|
||||
if err != nil {
|
||||
log.Errorf("StartRemoteUpdateTask fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -622,9 +622,11 @@ func (self *SCloudaccount) PerformSync(ctx context.Context, userCred mcclient.To
|
||||
if !self.GetEnabled() {
|
||||
return nil, httperrors.NewInvalidStatusError("Account disabled")
|
||||
}
|
||||
if self.EnableAutoSync {
|
||||
return nil, httperrors.NewInvalidStatusError("Account auto sync enabled")
|
||||
|
||||
if self.EnableAutoSync && self.SyncStatus != api.CLOUD_PROVIDER_SYNC_STATUS_IDLE {
|
||||
return nil, httperrors.NewInvalidStatusError("Account is not idle")
|
||||
}
|
||||
|
||||
syncRange := SSyncRange{}
|
||||
err := data.Unmarshal(&syncRange)
|
||||
if err != nil {
|
||||
|
||||
@@ -50,7 +50,7 @@ type SCloudproviderCapability struct {
|
||||
|
||||
CloudproviderId string `width:"36" charset:"ascii" nullable:"false" primary:"true"`
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" default:"" primary:"true"`
|
||||
Capability string `width:"18" charset:"ascii" nullable:"false" primary:"true"`
|
||||
Capability string `width:"36" charset:"ascii" nullable:"false" primary:"true"`
|
||||
}
|
||||
|
||||
func (self *SCloudproviderCapability) GetId() string {
|
||||
|
||||
@@ -145,6 +145,7 @@ func (manager *SCloudproviderregionManager) FetchCustomizeColumns(
|
||||
rows[i].Cloudprovider = manager.Name
|
||||
account := manager.GetCloudaccount()
|
||||
rows[i].EnableAutoSync = false
|
||||
rows[i].CloudproviderSyncStatus = manager.SyncStatus
|
||||
if account != nil {
|
||||
rows[i].CloudaccountId = account.Id
|
||||
rows[i].Cloudaccount = account.Name
|
||||
|
||||
@@ -642,8 +642,8 @@ func (self *SCloudprovider) PerformSync(ctx context.Context, userCred mcclient.T
|
||||
if !account.GetEnabled() {
|
||||
return nil, httperrors.NewInvalidStatusError("Cloudaccount disabled")
|
||||
}
|
||||
if account.EnableAutoSync {
|
||||
return nil, httperrors.NewInvalidStatusError("Account auto sync enabled")
|
||||
if account.EnableAutoSync && self.SyncStatus != api.CLOUD_PROVIDER_SYNC_STATUS_IDLE {
|
||||
return nil, httperrors.NewInvalidStatusError("Cloudprovider is not idle")
|
||||
}
|
||||
syncRange := SSyncRange{}
|
||||
err := data.Unmarshal(&syncRange)
|
||||
@@ -1482,6 +1482,7 @@ func (self *SCloudprovider) RealDelete(ctx context.Context, userCred mcclient.To
|
||||
MongoDBManager,
|
||||
ElasticSearchManager,
|
||||
KafkaManager,
|
||||
CDNDomainManager,
|
||||
NetworkInterfaceManager,
|
||||
CloudproviderRegionManager,
|
||||
CloudregionManager,
|
||||
|
||||
@@ -38,6 +38,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -1492,7 +1493,15 @@ func (manager *SDBInstanceManager) SyncDBInstances(ctx context.Context, userCred
|
||||
}
|
||||
|
||||
func (self *SDBInstance) syncRemoveCloudDBInstance(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return self.Purge(ctx, userCred)
|
||||
err := self.Purge(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SDBInstance) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
@@ -1704,6 +1713,12 @@ func (self *SDBInstance) SyncWithCloudDBInstance(ctx context.Context, userCred m
|
||||
}
|
||||
syncVirtualResourceMetadata(ctx, userCred, self, extInstance)
|
||||
db.OpsLog.LogSyncUpdate(self, diff, userCred)
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1793,6 +1808,11 @@ func (manager *SDBInstanceManager) newFromCloudDBInstance(ctx context.Context, u
|
||||
|
||||
db.OpsLog.LogEvent(&instance, db.ACT_CREATE, instance.GetShortDesc(ctx), userCred)
|
||||
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &instance,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
return &instance, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -693,34 +693,35 @@ func (self *SDisk) StartAllocate(ctx context.Context, host *SHost, storage *SSto
|
||||
templateId := self.GetTemplateId()
|
||||
fsFormat := self.GetFsFormat()
|
||||
|
||||
content := jsonutils.NewDict()
|
||||
content.Add(jsonutils.NewString(self.DiskFormat), "format")
|
||||
content.Add(jsonutils.NewInt(int64(self.DiskSize)), "size")
|
||||
input := api.DiskAllocateInput{
|
||||
Format: self.DiskFormat,
|
||||
DiskSizeMb: self.DiskSize,
|
||||
SnapshotId: snapshot,
|
||||
}
|
||||
if len(snapshot) > 0 {
|
||||
content.Add(jsonutils.NewString(snapshot), "snapshot")
|
||||
if utils.IsInStringArray(storage.StorageType, api.FIEL_STORAGE) {
|
||||
SnapshotManager.AddRefCount(self.SnapshotId, 1)
|
||||
self.SetMetadata(ctx, "merge_snapshot", jsonutils.JSONTrue, userCred)
|
||||
}
|
||||
} else if len(templateId) > 0 {
|
||||
content.Add(jsonutils.NewString(templateId), "image_id")
|
||||
input.ImageId = templateId
|
||||
}
|
||||
if len(fsFormat) > 0 {
|
||||
content.Add(jsonutils.NewString(fsFormat), "fs_format")
|
||||
input.FsFormat = fsFormat
|
||||
if fsFormat == "ext4" {
|
||||
name := strings.ToLower(self.GetName())
|
||||
for _, key := range []string{"encrypt", "secret", "cipher", "private"} {
|
||||
if strings.Index(key, name) > 0 {
|
||||
content.Add(jsonutils.JSONTrue, "encryption")
|
||||
input.Encryption = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if rebuild {
|
||||
return host.GetHostDriver().RequestRebuildDiskOnStorage(ctx, host, storage, self, task, content)
|
||||
return host.GetHostDriver().RequestRebuildDiskOnStorage(ctx, host, storage, self, task, input)
|
||||
} else {
|
||||
return host.GetHostDriver().RequestAllocateDiskOnStorage(ctx, userCred, host, storage, self, task, content)
|
||||
return host.GetHostDriver().RequestAllocateDiskOnStorage(ctx, userCred, host, storage, self, task, input)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1462,7 +1463,15 @@ func (self *SDisk) syncRemoveCloudDisk(ctx context.Context, userCred mcclient.To
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return self.RealDelete(ctx, userCred)
|
||||
err = self.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SDisk) syncWithCloudDisk(ctx context.Context, userCred mcclient.TokenCredential, provider cloudprovider.ICloudProvider, extDisk cloudprovider.ICloudDisk, index int, syncOwnerId mcclient.IIdentityProvider, managerId string) error {
|
||||
@@ -1535,6 +1544,13 @@ func (self *SDisk) syncWithCloudDisk(ctx context.Context, userCred mcclient.Toke
|
||||
}
|
||||
db.OpsLog.LogSyncUpdate(self, diff, userCred)
|
||||
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
syncVirtualResourceMetadata(ctx, userCred, self, extDisk)
|
||||
|
||||
if len(guests) == 0 {
|
||||
@@ -1565,6 +1581,13 @@ func (manager *SDiskManager) newFromCloudDisk(ctx context.Context, userCred mccl
|
||||
|
||||
disk.IsEmulated = extDisk.IsEmulated()
|
||||
|
||||
if templateId := extDisk.GetTemplateId(); len(templateId) > 0 {
|
||||
cachedImage, err := db.FetchByExternalId(CachedimageManager, templateId)
|
||||
if err == nil && cachedImage != nil {
|
||||
disk.TemplateId = cachedImage.GetId()
|
||||
}
|
||||
}
|
||||
|
||||
if provider.GetFactory().IsSupportPrepaidResources() {
|
||||
disk.BillingType = extDisk.GetBillingType()
|
||||
if expired := extDisk.GetExpiredAt(); !expired.IsZero() {
|
||||
@@ -1609,6 +1632,11 @@ func (manager *SDiskManager) newFromCloudDisk(ctx context.Context, userCred mccl
|
||||
|
||||
db.OpsLog.LogEvent(&disk, db.ACT_CREATE, disk.GetShortDesc(ctx), userCred)
|
||||
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &disk,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
return &disk, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -223,6 +224,10 @@ func (self *SDnsZoneCache) syncRemove(ctx context.Context, userCred mcclient.Tok
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "dnsZone.RealDelete for %s(%s)", dnsZone.Name, dnsZone.Id)
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
|
||||
return self.RealDelete(ctx, userCred)
|
||||
}
|
||||
@@ -288,6 +293,10 @@ func (self *SDnsZoneCache) SyncWithCloudDnsZone(ctx context.Context, userCred mc
|
||||
dnsZone.AddVpc(ctx, add.(string))
|
||||
}
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -457,6 +457,10 @@ func (manager *SDnsZoneManager) newFromCloudDnsZone(ctx context.Context, userCre
|
||||
dnsZone.AddVpc(ctx, vpcId)
|
||||
}
|
||||
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: dnsZone,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
SyncCloudDomain(userCred, dnsZone, account.GetOwnerId())
|
||||
dnsZone.SyncShareState(ctx, userCred, account.getAccountShareInfo())
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -392,7 +393,15 @@ func (self *SElasticSearch) GetIElasticSearch() (cloudprovider.ICloudElasticSear
|
||||
}
|
||||
|
||||
func (self *SElasticSearch) syncRemoveCloudElasticSearch(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return self.RealDelete(ctx, userCred)
|
||||
err := self.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// 同步资源属性
|
||||
@@ -471,6 +480,12 @@ func (self *SElasticSearch) SyncWithCloudElasticSearch(ctx context.Context, user
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "db.Update")
|
||||
}
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
syncVirtualResourceMetadata(ctx, userCred, self, ext)
|
||||
if provider := self.GetCloudprovider(); provider != nil {
|
||||
@@ -570,6 +585,10 @@ func (self *SCloudregion) newFromCloudElasticSearch(ctx context.Context, userCre
|
||||
return nil, errors.Wrapf(err, "newFromCloudElasticSearch.Insert")
|
||||
}
|
||||
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &es,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
// 同步标签
|
||||
syncVirtualResourceMetadata(ctx, userCred, &es, ext)
|
||||
// 同步项目归属
|
||||
|
||||
@@ -37,6 +37,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -576,7 +577,15 @@ func (self *SElasticcache) syncRemoveCloudElasticcache(ctx context.Context, user
|
||||
self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_ERROR, "sync to delete")
|
||||
return errors.Wrap(err, "ValidateDeleteCondition")
|
||||
}
|
||||
return self.SVirtualResourceBase.Delete(ctx, userCred)
|
||||
err = self.SVirtualResourceBase.Delete(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SElasticcache) SyncWithCloudElasticcache(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, extInstance cloudprovider.ICloudElasticcache) error {
|
||||
@@ -620,6 +629,12 @@ func (self *SElasticcache) SyncWithCloudElasticcache(ctx context.Context, userCr
|
||||
}
|
||||
syncVirtualResourceMetadata(ctx, userCred, self, extInstance)
|
||||
db.OpsLog.LogSyncUpdate(self, diff, userCred)
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -739,6 +754,11 @@ func (manager *SElasticcacheManager) newFromCloudElasticcache(ctx context.Contex
|
||||
SyncCloudProject(userCred, &instance, ownerId, extInstance, provider.Id)
|
||||
db.OpsLog.LogEvent(&instance, db.ACT_CREATE, instance.GetShortDesc(ctx), userCred)
|
||||
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &instance,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
return &instance, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -388,7 +389,15 @@ func (self *SElasticip) syncRemoveCloudEip(ctx context.Context, userCred mcclien
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
return self.RealDelete(ctx, userCred)
|
||||
err := self.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SElasticip) SyncInstanceWithCloudEip(ctx context.Context, userCred mcclient.TokenCredential, ext cloudprovider.ICloudEIP) error {
|
||||
@@ -485,6 +494,13 @@ func (self *SElasticip) SyncWithCloudEip(ctx context.Context, userCred mcclient.
|
||||
}
|
||||
db.OpsLog.LogSyncUpdate(self, diff, userCred)
|
||||
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
err = self.SyncInstanceWithCloudEip(ctx, userCred, ext)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "fail to sync associated instance of EIP")
|
||||
@@ -563,6 +579,10 @@ func (manager *SElasticipManager) newFromCloudEip(ctx context.Context, userCred
|
||||
}
|
||||
|
||||
db.OpsLog.LogEvent(&eip, db.ACT_CREATE, eip.GetShortDesc(ctx), userCred)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &eip,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
return &eip, nil
|
||||
}
|
||||
@@ -996,7 +1016,7 @@ func (self *SElasticip) PerformAssociate(ctx context.Context, userCred mcclient.
|
||||
// IMPORTANT: this serves as a guard against a guest to have multiple
|
||||
// associated elastic_ips
|
||||
seip, _ := server.GetEipOrPublicIp()
|
||||
if seip != nil {
|
||||
if seip != nil && (seip.Mode == api.EIP_MODE_STANDALONE_EIP || seip.GetProviderName() != api.CLOUD_PROVIDER_AWS) {
|
||||
return input, httperrors.NewInvalidStatusError("instance is already associated with eip")
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
@@ -381,7 +382,15 @@ func (self *SFileSystem) syncRemove(ctx context.Context, userCred mcclient.Token
|
||||
return self.SetStatus(userCred, api.NAS_STATUS_UNKNOWN, "sync to delete")
|
||||
}
|
||||
|
||||
return self.RealDelete(ctx, userCred)
|
||||
err = self.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SFileSystem) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
@@ -436,7 +445,7 @@ func (self *SFileSystem) SyncAllWithCloudFileSystem(ctx context.Context, userCre
|
||||
}
|
||||
|
||||
func (self *SFileSystem) SyncWithCloudFileSystem(ctx context.Context, userCred mcclient.TokenCredential, fs cloudprovider.ICloudFileSystem) error {
|
||||
_, err := db.Update(self, func() error {
|
||||
diff, err := db.Update(self, func() error {
|
||||
self.Status = fs.GetStatus()
|
||||
self.StorageType = fs.GetStorageType()
|
||||
self.Protocol = fs.GetProtocol()
|
||||
@@ -456,6 +465,12 @@ func (self *SFileSystem) SyncWithCloudFileSystem(ctx context.Context, userCred m
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "db.Update")
|
||||
}
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
syncMetadata(ctx, userCred, self, fs)
|
||||
return nil
|
||||
}
|
||||
@@ -490,7 +505,7 @@ func (self *SCloudregion) newFromCloudFileSystem(ctx context.Context, userCred m
|
||||
if zoneId := fs.GetZoneId(); len(zoneId) > 0 {
|
||||
nas.ZoneId, _ = self.getZoneIdBySuffix(zoneId)
|
||||
}
|
||||
return func() (*SFileSystem, error) {
|
||||
fileSystem, err := func() (*SFileSystem, error) {
|
||||
lockman.LockRawObject(ctx, FileSystemManager.Keyword(), "name")
|
||||
defer lockman.ReleaseRawObject(ctx, FileSystemManager.Keyword(), "name")
|
||||
|
||||
@@ -502,6 +517,14 @@ func (self *SCloudregion) newFromCloudFileSystem(ctx context.Context, userCred m
|
||||
|
||||
return &nas, FileSystemManager.TableSpec().Insert(ctx, &nas)
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &nas,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
return fileSystem, nil
|
||||
}
|
||||
|
||||
func (self *SFileSystem) AllowPerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
|
||||
@@ -2545,7 +2545,15 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T
|
||||
var diskIdx = 1
|
||||
for i := range input.Disks {
|
||||
disk := input.Disks[i]
|
||||
if len(disk.Backend) == 0 {
|
||||
if len(disk.SnapshotId) > 0 {
|
||||
snapObj, err := SnapshotManager.FetchById(disk.SnapshotId)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewResourceNotFoundError("snapshot %s not found", disk.SnapshotId)
|
||||
}
|
||||
snap := snapObj.(*SSnapshot)
|
||||
disk.Storage = snap.StorageId
|
||||
}
|
||||
if len(disk.Backend) == 0 && len(disk.Storage) == 0 {
|
||||
disk.Backend = self.getDefaultStorageType()
|
||||
}
|
||||
if disk.SizeMb > 0 {
|
||||
@@ -5313,3 +5321,79 @@ func (self *SGuest) PerformListForward(ctx context.Context, userCred mcclient.To
|
||||
}
|
||||
return resp.JSON(), nil
|
||||
}
|
||||
|
||||
func (self *SGuest) AllowPerformChangeDiskStorage(ctx context.Context, userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "change-disk-storage")
|
||||
}
|
||||
|
||||
func (self *SGuest) PerformChangeDiskStorage(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.ServerChangeDiskStorageInput) (*api.ServerChangeDiskStorageInput, error) {
|
||||
// validate input
|
||||
if input.DiskId == "" {
|
||||
return nil, httperrors.NewNotEmptyError("Disk id is empty")
|
||||
}
|
||||
if input.TargetStorageId == "" {
|
||||
return nil, httperrors.NewNotEmptyError("Storage id is empty")
|
||||
}
|
||||
|
||||
// validate disk
|
||||
disks, err := self.GetDisks()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Get server %s disks", self.GetName())
|
||||
}
|
||||
var srcDisk *SDisk
|
||||
for _, disk := range disks {
|
||||
if input.DiskId == disk.GetId() || input.DiskId == disk.GetName() {
|
||||
srcDisk = &disk
|
||||
input.DiskId = disk.GetId()
|
||||
break
|
||||
}
|
||||
}
|
||||
if srcDisk == nil {
|
||||
return nil, httperrors.NewNotFoundError("Disk %s not found on server %s", input.DiskId, self.GetName())
|
||||
}
|
||||
|
||||
// validate storage
|
||||
storageObj, err := StorageManager.FetchByIdOrName(userCred, input.TargetStorageId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Found storage by %s", input.TargetStorageId)
|
||||
}
|
||||
storage := storageObj.(*SStorage)
|
||||
input.TargetStorageId = storage.GetId()
|
||||
|
||||
// driver validate
|
||||
drv := self.GetDriver()
|
||||
if err := drv.ValidateChangeDiskStorage(ctx, userCred, self, input); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// create a disk on target storage from source disk
|
||||
diskConf := &api.DiskConfig{
|
||||
Index: -1,
|
||||
ImageId: srcDisk.TemplateId,
|
||||
Format: srcDisk.DiskFormat,
|
||||
SizeMb: srcDisk.DiskSize,
|
||||
Fs: srcDisk.FsFormat,
|
||||
DiskType: srcDisk.DiskType,
|
||||
}
|
||||
|
||||
targetDisk, err := self.createDiskOnStorage(ctx, userCred, storage, diskConf, nil, true, true)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Create target disk on storage %s", storage.GetName())
|
||||
}
|
||||
|
||||
internalInput := &api.ServerChangeDiskStorageInternalInput{
|
||||
ServerChangeDiskStorageInput: *input,
|
||||
StorageId: srcDisk.StorageId,
|
||||
TargetDiskId: targetDisk.GetId(),
|
||||
}
|
||||
|
||||
return nil, self.StartChangeDiskStorageTask(ctx, userCred, internalInput, "")
|
||||
}
|
||||
|
||||
func (self *SGuest) StartChangeDiskStorageTask(ctx context.Context, userCred mcclient.TokenCredential, input *api.ServerChangeDiskStorageInternalInput, parentTaskId string) error {
|
||||
reason := fmt.Sprintf("Change disk %s to storage %s", input.DiskId, input.TargetStorageId)
|
||||
self.SetStatus(userCred, api.VM_DISK_CHANGE_STORAGE, reason)
|
||||
return self.GetDriver().StartChangeDiskStorageTask(self, ctx, userCred, input, "")
|
||||
}
|
||||
|
||||
@@ -377,6 +377,25 @@ func (guest *SGuest) sshableTry(
|
||||
return ok
|
||||
}
|
||||
|
||||
func (guest *SGuest) AllowPerformHaveAgent(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool {
|
||||
return guest.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, guest, "have-agent")
|
||||
}
|
||||
|
||||
func (guest *SGuest) PerformHaveAgent(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input compute_api.GuestHaveAgentInput) (compute_api.GuestHaveAgentOutput, error) {
|
||||
var output compute_api.GuestHaveAgentOutput
|
||||
v := guest.GetMetadata("__monitor_agent", userCred)
|
||||
if v == "true" {
|
||||
output.Have = true
|
||||
return output, nil
|
||||
}
|
||||
v = guest.GetMetadata("sys:monitor_agent", userCred)
|
||||
if v == "true" {
|
||||
output.Have = true
|
||||
return output, nil
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func (guest *SGuest) AllowPerformMakeSshable(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
|
||||
@@ -205,11 +205,16 @@ type IGuestDriver interface {
|
||||
RequestMigrate(ctx context.Context, guest *SGuest, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, task taskman.ITask) error
|
||||
RequestLiveMigrate(ctx context.Context, guest *SGuest, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, task taskman.ITask) error
|
||||
|
||||
ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, input api.ServerUpdateInput) error
|
||||
RequestRemoteUpdate(ctx context.Context, guest *SGuest, userCred mcclient.TokenCredential, replaceTags bool) error
|
||||
|
||||
RequestOpenForward(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest, req *guestdriver_types.OpenForwardRequest) (*guestdriver_types.OpenForwardResponse, error)
|
||||
RequestListForward(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest, req *guestdriver_types.ListForwardRequest) (*guestdriver_types.ListForwardResponse, error)
|
||||
RequestCloseForward(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest, req *guestdriver_types.CloseForwardRequest) (*guestdriver_types.CloseForwardResponse, error)
|
||||
|
||||
ValidateChangeDiskStorage(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest, input *api.ServerChangeDiskStorageInput) error
|
||||
StartChangeDiskStorageTask(guest *SGuest, ctx context.Context, userCred mcclient.TokenCredential, params *api.ServerChangeDiskStorageInternalInput, parentTaskId string) error
|
||||
RequestChangeDiskStorage(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest, input *api.ServerChangeDiskStorageInternalInput, task taskman.ITask) error
|
||||
}
|
||||
|
||||
var guestDrivers map[string]IGuestDriver
|
||||
|
||||
@@ -212,7 +212,7 @@ func (manager *SGuestnetworkManager) GenerateMac(netId string, suggestion string
|
||||
log.Errorf("generate random mac failed: %s", err)
|
||||
continue
|
||||
}
|
||||
mac = fmt.Sprintf("00:22:%02x:%02x:%02x:%02x", b[0], b[1], b[2], b[3])
|
||||
mac = fmt.Sprintf("%s:%02x:%02x:%02x:%02x", options.Options.GlobalMacPrefix, b[0], b[1], b[2], b[3])
|
||||
}
|
||||
q := manager.Query().Equals("mac_addr", mac)
|
||||
if len(netId) > 0 {
|
||||
|
||||
@@ -46,6 +46,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/userdata"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -313,6 +314,7 @@ func (manager *SGuestManager) ListItemFilter(
|
||||
}
|
||||
}
|
||||
|
||||
var eipMode string
|
||||
usableServerForEipFilter := query.UsableServerForEip
|
||||
if len(usableServerForEipFilter) > 0 {
|
||||
eipObj, err := ElasticipManager.FetchByIdOrName(userCred, usableServerForEipFilter)
|
||||
@@ -324,6 +326,10 @@ func (manager *SGuestManager) ListItemFilter(
|
||||
}
|
||||
eip := eipObj.(*SElasticip)
|
||||
|
||||
if eip.GetProviderName() == api.CLOUD_PROVIDER_AWS {
|
||||
eipMode = api.EIP_MODE_STANDALONE_EIP
|
||||
}
|
||||
|
||||
if len(eip.NetworkId) > 0 {
|
||||
sq := GuestnetworkManager.Query("guest_id").Equals("network_id", eip.NetworkId).SubQuery()
|
||||
q = q.NotIn("id", sq)
|
||||
@@ -404,6 +410,9 @@ func (manager *SGuestManager) ListItemFilter(
|
||||
eips := ElasticipManager.Query().SubQuery()
|
||||
sq := eips.Query(eips.Field("associate_id")).Equals("associate_type", api.EIP_ASSOCIATE_TYPE_SERVER)
|
||||
sq = sq.IsNotNull("associate_id").IsNotEmpty("associate_id")
|
||||
if len(eipMode) > 0 {
|
||||
sq = sq.Equals("mode", eipMode)
|
||||
}
|
||||
|
||||
if withEip {
|
||||
q = q.In("id", sq)
|
||||
@@ -976,6 +985,42 @@ func (self *SGuest) ValidateUpdateData(ctx context.Context, userCred mcclient.To
|
||||
return input, httperrors.NewInputParameterError("name is too short")
|
||||
}
|
||||
|
||||
if input.Vdi != nil {
|
||||
if !utils.IsInStringArray(*input.Vdi, []string{"vnc", "spice"}) {
|
||||
return input, httperrors.NewInputParameterError("unsupported vdi protocol")
|
||||
}
|
||||
}
|
||||
|
||||
if input.Vga != nil || input.Vdi != nil {
|
||||
vdi := self.Vdi
|
||||
if input.Vdi != nil {
|
||||
vdi = *input.Vdi
|
||||
}
|
||||
if vdi != "vnc" && vdi != "spice" {
|
||||
vdi = "vnc"
|
||||
input.Vdi = &vdi
|
||||
}
|
||||
var candidateVga []string
|
||||
switch vdi {
|
||||
case "vnc":
|
||||
candidateVga = []string{"std", "qxl", "virtio"}
|
||||
case "spice":
|
||||
candidateVga = []string{"qxl", "virtio"}
|
||||
}
|
||||
vga := self.Vga
|
||||
if input.Vga != nil {
|
||||
vga = *input.Vga
|
||||
}
|
||||
if !utils.IsInStringArray(vga, candidateVga) {
|
||||
vga = candidateVga[0]
|
||||
input.Vga = &vga
|
||||
}
|
||||
}
|
||||
|
||||
if err := self.GetDriver().ValidateUpdateData(ctx, userCred, input); err != nil {
|
||||
return input, err
|
||||
}
|
||||
|
||||
var err error
|
||||
input.VirtualResourceBaseUpdateInput, err = self.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, input.VirtualResourceBaseUpdateInput)
|
||||
if err != nil {
|
||||
@@ -2376,7 +2421,14 @@ func (self *SGuest) syncRemoveCloudVM(ctx context.Context, userCred mcclient.Tok
|
||||
|
||||
if options.SyncPurgeRemovedResources.Contains(self.Keyword()) {
|
||||
log.Debugf("purge removed resource %s", self.Name)
|
||||
return self.purge(ctx, userCred)
|
||||
err := self.purge(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
}
|
||||
|
||||
if !lostNamePattern.MatchString(self.Name) {
|
||||
@@ -2495,6 +2547,13 @@ func (self *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.Token
|
||||
|
||||
db.OpsLog.LogSyncUpdate(self, diff, userCred)
|
||||
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
syncVirtualResourceMetadata(ctx, userCred, self, extVM)
|
||||
SyncCloudProject(userCred, self, syncOwnerId, extVM, host.ManagerId)
|
||||
|
||||
@@ -2598,6 +2657,11 @@ func (manager *SGuestManager) newCloudVM(ctx context.Context, userCred mcclient.
|
||||
|
||||
db.OpsLog.LogEvent(&guest, db.ACT_CREATE, guest.GetShortDesc(ctx), userCred)
|
||||
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &guest,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
if guest.Status == api.VM_RUNNING {
|
||||
db.OpsLog.LogEvent(&guest, db.ACT_START, guest.GetShortDesc(ctx), userCred)
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ type IHostDriver interface {
|
||||
RequestPrepareSaveDiskOnHost(ctx context.Context, host *SHost, disk *SDisk, imageId string, task taskman.ITask) error
|
||||
RequestSaveUploadImageOnHost(ctx context.Context, host *SHost, disk *SDisk, imageId string, task taskman.ITask, data jsonutils.JSONObject) error
|
||||
|
||||
RequestAllocateDiskOnStorage(ctx context.Context, userCred mcclient.TokenCredential, host *SHost, storage *SStorage, disk *SDisk, task taskman.ITask, content *jsonutils.JSONDict) error
|
||||
RequestRebuildDiskOnStorage(ctx context.Context, host *SHost, storage *SStorage, disk *SDisk, task taskman.ITask, content *jsonutils.JSONDict) error
|
||||
RequestAllocateDiskOnStorage(ctx context.Context, userCred mcclient.TokenCredential, host *SHost, storage *SStorage, disk *SDisk, task taskman.ITask, input api.DiskAllocateInput) error
|
||||
RequestRebuildDiskOnStorage(ctx context.Context, host *SHost, storage *SStorage, disk *SDisk, task taskman.ITask, input api.DiskAllocateInput) error
|
||||
|
||||
RequestDeallocateDiskOnHost(ctx context.Context, host *SHost, storage *SStorage, disk *SDisk, task taskman.ITask) error
|
||||
RequestDeallocateBackupDiskOnHost(ctx context.Context, host *SHost, storage *SStorage, disk *SDisk, task taskman.ITask) error
|
||||
@@ -59,7 +59,7 @@ type IHostDriver interface {
|
||||
IsReachStoragecacheCapacityLimit(host *SHost, cachedImages []SCachedimage) bool
|
||||
GetStoragecacheQuota(host *SHost) int
|
||||
|
||||
ValidateAttachStorage(ctx context.Context, userCred mcclient.TokenCredential, host *SHost, storage *SStorage, data *jsonutils.JSONDict) error
|
||||
ValidateAttachStorage(ctx context.Context, userCred mcclient.TokenCredential, host *SHost, storage *SStorage, input api.HostStorageCreateInput) (api.HostStorageCreateInput, error)
|
||||
RequestAttachStorage(ctx context.Context, hoststorage *SHoststorage, host *SHost, storage *SStorage, task taskman.ITask) error
|
||||
RequestDetachStorage(ctx context.Context, host *SHost, storage *SStorage, task taskman.ITask) error
|
||||
RequestSyncOnHost(ctx context.Context, host *SHost, task taskman.ITask) error
|
||||
|
||||
@@ -1029,7 +1029,16 @@ func (self *SHostManager) GetPropertyNodeCount(ctx context.Context, userCred mcc
|
||||
}
|
||||
|
||||
func (self *SHostManager) getCount(ctx context.Context, userCred mcclient.TokenCredential, q *sqlchemy.SQuery, query api.HostListInput) (jsonutils.JSONObject, error) {
|
||||
q, err := self.ListItemFilter(ctx, q, userCred, query)
|
||||
filterAny := false
|
||||
if query.FilterAny != nil {
|
||||
filterAny = *query.FilterAny
|
||||
}
|
||||
q, err := db.ApplyListItemsGeneralFilters(self, q, userCred, query.Filter, filterAny)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
q, err = self.ListItemFilter(ctx, q, userCred, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -3548,8 +3557,12 @@ func (self *SHost) PostUpdate(ctx context.Context, userCred mcclient.TokenCreden
|
||||
}
|
||||
}
|
||||
|
||||
if err := self.startSyncConfig(ctx, userCred, "", true); err != nil {
|
||||
log.Errorf("start sync host %q config after updated", self.GetName())
|
||||
notSyncConf, _ := data.Bool("not_sync_config")
|
||||
|
||||
if !notSyncConf {
|
||||
if err := self.startSyncConfig(ctx, userCred, "", true); err != nil {
|
||||
log.Errorf("start sync host %q config after updated", self.GetName())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -137,42 +138,28 @@ func (self *SHoststorage) GetStorage() *SStorage {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SHoststorageManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
storageId, _ := data.GetString("storage_id")
|
||||
if len(storageId) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("storage_id")
|
||||
}
|
||||
storageTmp, _ := StorageManager.FetchById(storageId)
|
||||
if storageTmp == nil {
|
||||
return nil, httperrors.NewResourceNotFoundError("failed to find storage %s to attach host", storageId)
|
||||
}
|
||||
storage := storageTmp.(*SStorage)
|
||||
|
||||
hostId, _ := data.GetString("host_id")
|
||||
if len(hostId) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("host_id")
|
||||
}
|
||||
hostTmp, _ := HostManager.FetchById(hostId)
|
||||
if hostTmp == nil {
|
||||
return nil, httperrors.NewResourceNotFoundError("failed to find host %s to attach storage", hostId)
|
||||
}
|
||||
host := hostTmp.(*SHost)
|
||||
|
||||
if err := host.GetHostDriver().ValidateAttachStorage(ctx, userCred, host, storage, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
input := apis.JoinResourceBaseCreateInput{}
|
||||
err := data.Unmarshal(&input)
|
||||
func (manager *SHoststorageManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input api.HostStorageCreateInput) (api.HostStorageCreateInput, error) {
|
||||
storageObj, err := validators.ValidateModel(userCred, StorageManager, &input.StorageId)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInternalServerError("unmarshal JoinResourceBaseCreateInput fail %s", err)
|
||||
return input, err
|
||||
}
|
||||
input, err = manager.SJointResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input)
|
||||
storage := storageObj.(*SStorage)
|
||||
hostObj, err := validators.ValidateModel(userCred, HostManager, &input.HostId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return input, err
|
||||
}
|
||||
data.Update(jsonutils.Marshal(input))
|
||||
return data, nil
|
||||
host := hostObj.(*SHost)
|
||||
|
||||
input, err = host.GetHostDriver().ValidateAttachStorage(ctx, userCred, host, storage, input)
|
||||
if err != nil {
|
||||
return input, err
|
||||
}
|
||||
|
||||
input.JoinResourceBaseCreateInput, err = manager.SJointResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.JoinResourceBaseCreateInput)
|
||||
if err != nil {
|
||||
return input, err
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SHoststorage) syncLocalStorageShare(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -389,7 +390,15 @@ func (self *SKafka) GetIKafka() (cloudprovider.ICloudKafka, error) {
|
||||
}
|
||||
|
||||
func (self *SKafka) syncRemoveCloudKafka(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return self.RealDelete(ctx, userCred)
|
||||
err := self.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// 同步资源属性
|
||||
@@ -469,6 +478,12 @@ func (self *SKafka) SyncWithCloudKafka(ctx context.Context, userCred mcclient.To
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "db.Update")
|
||||
}
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
syncVirtualResourceMetadata(ctx, userCred, self, ext)
|
||||
if provider := self.GetCloudprovider(); provider != nil {
|
||||
@@ -568,6 +583,10 @@ func (self *SCloudregion) newFromCloudKafka(ctx context.Context, userCred mcclie
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "newFromCloudKafka.Insert")
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &kafka,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
// 同步标签
|
||||
syncVirtualResourceMetadata(ctx, userCred, &kafka, ext)
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -344,6 +345,10 @@ func (man *SCachedLoadbalancerCertificateManager) newFromCloudLoadbalancerCertif
|
||||
SyncCloudProject(userCred, &lbcert, projectId, extCertificate, lbcert.ManagerId)
|
||||
|
||||
db.OpsLog.LogEvent(&lbcert, db.ACT_CREATE, lbcert.GetShortDesc(ctx), userCred)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &lbcert,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
return &lbcert, nil
|
||||
}
|
||||
@@ -375,6 +380,12 @@ func (lbcert *SCachedLoadbalancerCertificate) SyncWithCloudLoadbalancerCertifica
|
||||
}
|
||||
}
|
||||
db.OpsLog.LogSyncUpdate(lbcert, diff, userCred)
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: lbcert,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
SyncCloudProject(userCred, lbcert, projectId, extCertificate, lbcert.ManagerId)
|
||||
|
||||
@@ -390,6 +401,10 @@ func (lbcert *SCachedLoadbalancerCertificate) syncRemoveCloudLoadbalancerCertifi
|
||||
err = lbcert.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
err = lbcert.DoPendingDelete(ctx, userCred)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: lbcert,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -1022,6 +1023,11 @@ func (man *SLoadbalancerManager) newFromCloudLoadbalancer(ctx context.Context, u
|
||||
|
||||
db.OpsLog.LogEvent(&lb, db.ACT_CREATE, lb.GetShortDesc(ctx), userCred)
|
||||
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &lb,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
lb.syncLoadbalancerNetwork(ctx, userCred, lbNetworkIds)
|
||||
return &lb, nil
|
||||
}
|
||||
@@ -1035,6 +1041,10 @@ func (lb *SLoadbalancer) syncRemoveCloudLoadbalancer(ctx context.Context, userCr
|
||||
return lb.SetStatus(userCred, api.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
} else {
|
||||
lb.LBPendingDelete(ctx, userCred)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: lb,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -1217,6 +1227,13 @@ func (lb *SLoadbalancer) SyncWithCloudLoadbalancer(ctx context.Context, userCred
|
||||
|
||||
db.OpsLog.LogSyncUpdate(lb, diff, userCred)
|
||||
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: lb,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
networkIds := getExtLbNetworkIds(extLb, lb.ManagerId)
|
||||
SyncCloudProject(userCred, lb, syncOwnerId, extLb, provider.Id)
|
||||
lb.syncLoadbalancerNetwork(ctx, userCred, networkIds)
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -457,7 +458,15 @@ func (self *SCloudregion) SyncMongoDBs(ctx context.Context, userCred mcclient.To
|
||||
}
|
||||
|
||||
func (self *SMongoDB) syncRemoveCloudMongoDB(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return self.RealDelete(ctx, userCred)
|
||||
err := self.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SMongoDB) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
@@ -529,6 +538,12 @@ func (self *SMongoDB) SyncWithCloudMongoDB(ctx context.Context, userCred mcclien
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "db.Update")
|
||||
}
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
syncVirtualResourceMetadata(ctx, userCred, self, ext)
|
||||
if provider := self.GetCloudprovider(); provider != nil {
|
||||
SyncCloudProject(userCred, self, provider.GetOwnerId(), ext, provider.Id)
|
||||
@@ -617,6 +632,10 @@ func (self *SCloudregion) newFromCloudMongoDB(ctx context.Context, userCred mccl
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "newFromCloudMongoDB.Insert")
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &ins,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
syncVirtualResourceMetadata(ctx, userCred, &ins, ext)
|
||||
SyncCloudProject(userCred, &ins, provider.GetOwnerId(), ext, provider.Id)
|
||||
@@ -784,17 +803,13 @@ func (self *SMongoDB) PerformRemoteUpdate(ctx context.Context, userCred mcclient
|
||||
|
||||
func (self *SMongoDB) StartRemoteUpdateTask(ctx context.Context, userCred mcclient.TokenCredential, replaceTags bool, parentTaskId string) error {
|
||||
data := jsonutils.NewDict()
|
||||
if replaceTags {
|
||||
data.Add(jsonutils.JSONTrue, "replace_tags")
|
||||
data.Add(jsonutils.NewBool(replaceTags), "replace_tags")
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "MongoDBRemoteUpdateTask", self, userCred, data, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "NewTask")
|
||||
}
|
||||
if task, err := taskman.TaskManager.NewTask(ctx, "MongoDBRemoteUpdateTask", self, userCred, data, parentTaskId, "", nil); err != nil {
|
||||
log.Errorln(err)
|
||||
return errors.Wrap(err, "Start ElasticcacheRemoteUpdateTask")
|
||||
} else {
|
||||
self.SetStatus(userCred, api.DBINSTANCE_UPDATE_TAGS, "StartRemoteUpdateTask")
|
||||
task.ScheduleRun(nil)
|
||||
}
|
||||
return nil
|
||||
self.SetStatus(userCred, apis.STATUS_UPDATE_TAGS, "StartRemoteUpdateTask")
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SMongoDB) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
@@ -426,7 +427,6 @@ func (manager *SNatGatewayManager) SyncNatGateways(ctx context.Context, userCred
|
||||
syncResult.UpdateError(err)
|
||||
continue
|
||||
}
|
||||
syncMetadata(ctx, userCred, &commondb[i], commonext[i])
|
||||
localNatGateways = append(localNatGateways, commondb[i])
|
||||
remoteNatGateways = append(remoteNatGateways, commonext[i])
|
||||
syncResult.Update()
|
||||
@@ -438,7 +438,6 @@ func (manager *SNatGatewayManager) SyncNatGateways(ctx context.Context, userCred
|
||||
syncResult.AddError(err)
|
||||
continue
|
||||
}
|
||||
syncMetadata(ctx, userCred, routeTableNew, added[i])
|
||||
localNatGateways = append(localNatGateways, *routeTableNew)
|
||||
remoteNatGateways = append(remoteNatGateways, added[i])
|
||||
syncResult.Add()
|
||||
@@ -456,7 +455,15 @@ func (self *SNatGateway) syncRemoveCloudNatGateway(ctx context.Context, userCred
|
||||
if err != nil { // cannot delete
|
||||
return self.SetStatus(userCred, api.NAT_STATUS_UNKNOWN, "sync to delete")
|
||||
}
|
||||
return self.purge(ctx, userCred)
|
||||
err = self.purge(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SNatGateway) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
@@ -505,9 +512,16 @@ func (self *SNatGateway) SyncWithCloudNatGateway(ctx context.Context, userCred m
|
||||
return err
|
||||
}
|
||||
|
||||
syncMetadata(ctx, userCred, self, extNat)
|
||||
SyncCloudDomain(userCred, self, provider.GetOwnerId())
|
||||
|
||||
db.OpsLog.LogSyncUpdate(self, diff, userCred)
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -564,8 +578,13 @@ func (manager *SNatGatewayManager) newFromCloudNatGateway(ctx context.Context, u
|
||||
}
|
||||
|
||||
SyncCloudDomain(userCred, &nat, provider.GetOwnerId())
|
||||
syncMetadata(ctx, userCred, &nat, extNat)
|
||||
|
||||
db.OpsLog.LogEvent(&nat, db.ACT_CREATE, nat.GetShortDesc(ctx), userCred)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &nat,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
return &nat, nil
|
||||
}
|
||||
@@ -1088,3 +1107,36 @@ func (manager *SNatGatewayManager) DeleteExpiredPostpaids(ctx context.Context, u
|
||||
nats[i].StartNatGatewayDeleteTask(ctx, userCred, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SNatGateway) AllowPerformRemoteUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "remote-update")
|
||||
}
|
||||
|
||||
func (self *SNatGateway) PerformRemoteUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.MongoDBRemoteUpdateInput) (jsonutils.JSONObject, error) {
|
||||
err := self.StartRemoteUpdateTask(ctx, userCred, (input.ReplaceTags != nil && *input.ReplaceTags), "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "StartRemoteUpdateTask")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SNatGateway) StartRemoteUpdateTask(ctx context.Context, userCred mcclient.TokenCredential, replaceTags bool, parentTaskId string) error {
|
||||
data := jsonutils.NewDict()
|
||||
data.Add(jsonutils.NewBool(replaceTags), "replace_tags")
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "NatGatewayRemoteUpdateTask", self, userCred, data, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "NewTask")
|
||||
}
|
||||
self.SetStatus(userCred, apis.STATUS_UPDATE_TAGS, "StartRemoteUpdateTask")
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SNatGateway) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
if len(self.ExternalId) == 0 {
|
||||
return
|
||||
}
|
||||
err := self.StartRemoteUpdateTask(ctx, userCred, true, "")
|
||||
if err != nil {
|
||||
log.Errorf("StartRemoteUpdateTask fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -655,7 +656,12 @@ func (self *SNetwork) syncRemoveCloudNetwork(ctx context.Context, userCred mccli
|
||||
err = self.SetStatus(userCred, api.NETWORK_STATUS_UNKNOWN, "Sync to remove")
|
||||
} else {
|
||||
err = self.RealDelete(ctx, userCred)
|
||||
|
||||
if err == nil {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -680,6 +686,12 @@ func (self *SNetwork) SyncWithCloudNetwork(ctx context.Context, userCred mcclien
|
||||
return err
|
||||
}
|
||||
db.OpsLog.LogSyncUpdate(self, diff, userCred)
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
syncVirtualResourceMetadata(ctx, userCred, self, extNet)
|
||||
SyncCloudProject(userCred, self, syncOwnerId, extNet, vpc.ManagerId)
|
||||
@@ -751,6 +763,10 @@ func (manager *SNetworkManager) newFromCloudNetwork(ctx context.Context, userCre
|
||||
}
|
||||
|
||||
db.OpsLog.LogEvent(&net, db.ACT_CREATE, net.GetShortDesc(ctx), userCred)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &net,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
return &net, nil
|
||||
}
|
||||
|
||||
@@ -2046,3 +2046,21 @@ func (manager *SKafkaManager) purgeAll(ctx context.Context, userCred mcclient.To
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SCDNDomainManager) purgeAll(ctx context.Context, userCred mcclient.TokenCredential, providerId string) error {
|
||||
domains := []SCDNDomain{}
|
||||
err := fetchByManagerId(manager, providerId, &domains)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "fetchByManagerId")
|
||||
}
|
||||
for i := range domains {
|
||||
lockman.LockObject(ctx, &domains[i])
|
||||
defer lockman.ReleaseObject(ctx, &domains[i])
|
||||
|
||||
err := domains[i].RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "cdn domain delete")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -571,10 +571,10 @@ func (stm *SScheduledTaskManager) timeScope(median time.Time, interval time.Dura
|
||||
}
|
||||
}
|
||||
|
||||
var timerQueue = make(chan struct{}, cop.Options.ScheduledTaskQueueSize)
|
||||
var timerQueue chan struct{}
|
||||
|
||||
func (stm *SScheduledTaskManager) Timer(ctx context.Context, userCred mcclient.TokenCredential, isStart bool) {
|
||||
if len(timerQueue) == 0 {
|
||||
if timerQueue == nil {
|
||||
timerQueue = make(chan struct{}, cop.Options.ScheduledTaskQueueSize)
|
||||
}
|
||||
// 60 is for fault tolerance
|
||||
@@ -588,12 +588,16 @@ func (stm *SScheduledTaskManager) Timer(ctx context.Context, userCred mcclient.T
|
||||
return
|
||||
}
|
||||
log.Debugf("timeScope: start: %s, end: %s", timeScope.Start, timeScope.End)
|
||||
waitQueue := make(chan struct{}, len(sts))
|
||||
for i := range sts {
|
||||
log.Infof("sts[%d]: %s", i, jsonutils.Marshal(sts[i]))
|
||||
st := sts[i]
|
||||
timerQueue <- struct{}{}
|
||||
waitQueue <- struct{}{}
|
||||
go func(ctx context.Context) {
|
||||
defer func() {
|
||||
<-timerQueue
|
||||
<-waitQueue
|
||||
}()
|
||||
if st.NextTime.Before(timeScope.Start) {
|
||||
// For unknown reasons, the scalingTimer did not execute at the specified time
|
||||
@@ -619,6 +623,9 @@ func (stm *SScheduledTaskManager) Timer(ctx context.Context, userCred mcclient.T
|
||||
}(ctx)
|
||||
}
|
||||
// wait all finish
|
||||
for i := 0; i < len(sts); i++ {
|
||||
waitQueue <- struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -478,6 +479,10 @@ func (manager *SSecurityGroupCacheManager) SyncSecurityGroupCaches(ctx context.C
|
||||
syncResult.DeleteError(err)
|
||||
} else {
|
||||
syncResult.Delete()
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &removed[i],
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -338,6 +338,10 @@ func (self *SSecurityGroupRule) ValidateUpdateData(ctx context.Context, userCred
|
||||
return input, httperrors.NewOutOfRangeError("Invalid priority %d, must be in range or 1 ~ 100", input.Priority)
|
||||
}
|
||||
|
||||
if len(input.CIDR) == 0 {
|
||||
input.CIDR = self.CIDR
|
||||
}
|
||||
|
||||
if len(input.PeerSecgroupId) > 0 {
|
||||
_, err := validators.ValidateModel(userCred, SecurityGroupManager, &input.PeerSecgroupId)
|
||||
if err != nil {
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -629,6 +630,10 @@ func (self *SSecurityGroup) PostCreate(ctx context.Context, userCred mcclient.To
|
||||
|
||||
SecurityGroupRuleManager.TableSpec().Insert(ctx, rule)
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionCreate,
|
||||
})
|
||||
}
|
||||
|
||||
func (manager *SSecurityGroupManager) FetchSecgroupById(secId string) (*SSecurityGroup, error) {
|
||||
@@ -1140,6 +1145,10 @@ func (manager *SSecurityGroupManager) newFromCloudSecgroup(ctx context.Context,
|
||||
rules, _ := secgroup.SyncSecurityGroupRules(ctx, userCred, dest)
|
||||
|
||||
db.OpsLog.LogEvent(&secgroup, db.ACT_CREATE, secgroup.GetShortDesc(ctx), userCred)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: &secgroup,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
return &secgroup, rules, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
@@ -520,6 +521,12 @@ func (self *SVpc) syncRemoveCloudVpc(ctx context.Context, userCred mcclient.Toke
|
||||
}
|
||||
} else {
|
||||
err = self.RealDelete(ctx, userCred)
|
||||
if err == nil {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionDelete,
|
||||
})
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -1139,6 +1146,28 @@ func (manager *SVpcManager) ListItemFilter(
|
||||
}
|
||||
}
|
||||
|
||||
if len(query.ZoneId) > 0 {
|
||||
zoneObj, err := validators.ValidateModel(userCred, ZoneManager, &query.ZoneId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
region, err := zoneObj.(*SZone).GetRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "get zone %s region", zoneObj.GetName())
|
||||
}
|
||||
q = q.Equals("cloudregion_id", region.Id)
|
||||
wires := WireManager.Query().SubQuery()
|
||||
networks := NetworkManager.Query().SubQuery()
|
||||
sq := wires.Query(wires.Field("vpc_id")).Join(networks, sqlchemy.Equals(wires.Field("id"), networks.Field("wire_id"))).Filter(
|
||||
sqlchemy.OR(
|
||||
sqlchemy.Equals(wires.Field("zone_id"), query.ZoneId),
|
||||
sqlchemy.IsNullOrEmpty(wires.Field("zone_id")),
|
||||
),
|
||||
)
|
||||
q = q.In("id", sq.SubQuery())
|
||||
|
||||
}
|
||||
|
||||
if query.IsDefault != nil {
|
||||
if *query.IsDefault {
|
||||
q = q.IsTrue("is_default")
|
||||
|
||||
@@ -19,14 +19,17 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -382,7 +385,15 @@ func (self *SWafInstance) RealDelete(ctx context.Context, userCred mcclient.Toke
|
||||
}
|
||||
|
||||
func (self *SWafInstance) syncRemove(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return self.RealDelete(ctx, userCred)
|
||||
err := self.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SWafInstance) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
@@ -409,13 +420,19 @@ func (self *SWafInstance) GetICloudWafInstance() (cloudprovider.ICloudWafInstanc
|
||||
}
|
||||
|
||||
func (self *SWafInstance) SyncWithCloudWafInstance(ctx context.Context, userCred mcclient.TokenCredential, ext cloudprovider.ICloudWafInstance) error {
|
||||
_, err := db.Update(self, func() error {
|
||||
diff, err := db.Update(self, func() error {
|
||||
self.ExternalId = ext.GetGlobalId()
|
||||
self.SetEnabled(ext.GetEnabled())
|
||||
self.DefaultAction = ext.GetDefaultAction()
|
||||
self.Status = ext.GetStatus()
|
||||
return nil
|
||||
})
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -444,6 +461,10 @@ func (self *SCloudregion) newFromCloudWafInstance(ctx context.Context, userCred
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: waf,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
return waf, nil
|
||||
}
|
||||
|
||||
@@ -474,3 +495,36 @@ func (self *SWafInstance) AllowPerformSyncstatus(ctx context.Context, userCred m
|
||||
func (self *SWafInstance) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.WafSyncstatusInput) (jsonutils.JSONObject, error) {
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, self, "WafSyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (self *SWafInstance) AllowPerformRemoteUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "remote-update")
|
||||
}
|
||||
|
||||
func (self *SWafInstance) PerformRemoteUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.MongoDBRemoteUpdateInput) (jsonutils.JSONObject, error) {
|
||||
err := self.StartRemoteUpdateTask(ctx, userCred, (input.ReplaceTags != nil && *input.ReplaceTags), "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "StartRemoteUpdateTask")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SWafInstance) StartRemoteUpdateTask(ctx context.Context, userCred mcclient.TokenCredential, replaceTags bool, parentTaskId string) error {
|
||||
data := jsonutils.NewDict()
|
||||
data.Add(jsonutils.NewBool(replaceTags), "replace_tags")
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "WafInstanceRemoteUpdateTask", self, userCred, data, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "NewTask")
|
||||
}
|
||||
self.SetStatus(userCred, apis.STATUS_UPDATE_TAGS, "StartRemoteUpdateTask")
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SWafInstance) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
if len(self.ExternalId) == 0 {
|
||||
return
|
||||
}
|
||||
err := self.StartRemoteUpdateTask(ctx, userCred, true, "")
|
||||
if err != nil {
|
||||
log.Errorf("StartRemoteUpdateTask fail: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,6 +175,8 @@ type ComputeOptions struct {
|
||||
|
||||
ProhibitRefreshingCloudImage bool `help:"Prohibit refreshing cloud image"`
|
||||
|
||||
GlobalMacPrefix string `help:"Global prefix of MAC address, default to 00:22" default:"00:22"`
|
||||
|
||||
esxi.EsxiOptions
|
||||
}
|
||||
|
||||
|
||||
94
pkg/compute/tasks/app_remote_update_task.go
Normal file
94
pkg/compute/tasks/app_remote_update_task.go
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type AppRemoteUpdateTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(AppRemoteUpdateTask{})
|
||||
}
|
||||
|
||||
func (self *AppRemoteUpdateTask) taskFail(ctx context.Context, app *models.SApp, err error) {
|
||||
app.SetStatus(self.UserCred, apis.STATUS_UPDATE_TAGS_FAILED, err.Error())
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
}
|
||||
|
||||
func (self *AppRemoteUpdateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
app := obj.(*models.SApp)
|
||||
replaceTags := jsonutils.QueryBoolean(self.Params, "replace_tags", false)
|
||||
|
||||
iApp, err := app.GetIApp()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, app, errors.Wrapf(err, "GetIApp"))
|
||||
return
|
||||
}
|
||||
|
||||
oldTags, err := iApp.GetTags()
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
self.OnRemoteUpdateComplete(ctx, app, nil)
|
||||
return
|
||||
}
|
||||
self.taskFail(ctx, app, errors.Wrapf(err, "GetTags"))
|
||||
return
|
||||
}
|
||||
tags, err := app.GetAllUserMetadata()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, app, errors.Wrapf(err, "GetAllUserMetadata"))
|
||||
return
|
||||
}
|
||||
tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags}
|
||||
err = cloudprovider.SetTags(ctx, iApp, app.ManagerId, tags, replaceTags)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
self.OnRemoteUpdateComplete(ctx, app, nil)
|
||||
return
|
||||
}
|
||||
logclient.AddActionLogWithStartable(self, app, logclient.ACT_UPDATE_TAGS, err, self.GetUserCred(), false)
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
return
|
||||
}
|
||||
logclient.AddActionLogWithStartable(self, app, logclient.ACT_UPDATE_TAGS, tagsUpdateInfo, self.GetUserCred(), true)
|
||||
self.OnRemoteUpdateComplete(ctx, app, nil)
|
||||
}
|
||||
|
||||
func (self *AppRemoteUpdateTask) OnRemoteUpdateComplete(ctx context.Context, app *models.SApp, data jsonutils.JSONObject) {
|
||||
self.SetStage("OnSyncStatusComplete", nil)
|
||||
models.StartResourceSyncStatusTask(ctx, self.UserCred, app, "AppSyncstatusTask", self.GetTaskId())
|
||||
}
|
||||
|
||||
func (self *AppRemoteUpdateTask) OnSyncStatusComplete(ctx context.Context, app *models.SApp, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *AppRemoteUpdateTask) OnSyncStatusCompleteFailed(ctx context.Context, app *models.SApp, data jsonutils.JSONObject) {
|
||||
self.SetStageFailed(ctx, data)
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
@@ -68,5 +69,10 @@ func (self *CDNDomainDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneM
|
||||
return
|
||||
}
|
||||
|
||||
notifyclient.EventNotify(ctx, self.UserCred, notifyclient.SEventNotifyParam{
|
||||
Obj: domain,
|
||||
Action: notifyclient.ActionDelete,
|
||||
})
|
||||
|
||||
self.taskComplete(ctx, domain)
|
||||
}
|
||||
|
||||
94
pkg/compute/tasks/cdn_domain_remote_update_task.go
Normal file
94
pkg/compute/tasks/cdn_domain_remote_update_task.go
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type CDNDomainRemoteUpdateTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(CDNDomainRemoteUpdateTask{})
|
||||
}
|
||||
|
||||
func (self *CDNDomainRemoteUpdateTask) taskFail(ctx context.Context, cdn *models.SCDNDomain, err error) {
|
||||
cdn.SetStatus(self.UserCred, apis.STATUS_UPDATE_TAGS_FAILED, err.Error())
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
}
|
||||
|
||||
func (self *CDNDomainRemoteUpdateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
cdn := obj.(*models.SCDNDomain)
|
||||
replaceTags := jsonutils.QueryBoolean(self.Params, "replace_tags", false)
|
||||
|
||||
iCDNDomain, err := cdn.GetICloudCDNDomain()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, cdn, errors.Wrapf(err, "GetICloudCDNDomain"))
|
||||
return
|
||||
}
|
||||
|
||||
oldTags, err := iCDNDomain.GetTags()
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
self.OnRemoteUpdateComplete(ctx, cdn, nil)
|
||||
return
|
||||
}
|
||||
self.taskFail(ctx, cdn, errors.Wrapf(err, "GetTags"))
|
||||
return
|
||||
}
|
||||
tags, err := cdn.GetAllUserMetadata()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, cdn, errors.Wrapf(err, "GetAllUserMetadata"))
|
||||
return
|
||||
}
|
||||
tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags}
|
||||
err = cloudprovider.SetTags(ctx, iCDNDomain, cdn.ManagerId, tags, replaceTags)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
self.OnRemoteUpdateComplete(ctx, cdn, nil)
|
||||
return
|
||||
}
|
||||
logclient.AddActionLogWithStartable(self, cdn, logclient.ACT_UPDATE_TAGS, err, self.GetUserCred(), false)
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
return
|
||||
}
|
||||
logclient.AddActionLogWithStartable(self, cdn, logclient.ACT_UPDATE_TAGS, tagsUpdateInfo, self.GetUserCred(), true)
|
||||
self.OnRemoteUpdateComplete(ctx, cdn, nil)
|
||||
}
|
||||
|
||||
func (self *CDNDomainRemoteUpdateTask) OnRemoteUpdateComplete(ctx context.Context, cdn *models.SCDNDomain, data jsonutils.JSONObject) {
|
||||
self.SetStage("OnSyncStatusComplete", nil)
|
||||
models.StartResourceSyncStatusTask(ctx, self.UserCred, cdn, "CDNDomainSyncstatusTask", self.GetTaskId())
|
||||
}
|
||||
|
||||
func (self *CDNDomainRemoteUpdateTask) OnSyncStatusComplete(ctx context.Context, cdn *models.SCDNDomain, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *CDNDomainRemoteUpdateTask) OnSyncStatusCompleteFailed(ctx context.Context, cdn *models.SCDNDomain, data jsonutils.JSONObject) {
|
||||
self.SetStageFailed(ctx, data)
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user