Compare commits

...

144 Commits

Author SHA1 Message Date
Zexi Li
8c74fe459c Merge pull request #15204 from zexi/ansible-run-time
fix(ansibleserver): force sleep 50s before running
2022-10-18 10:48:45 +08:00
Zexi Li
f239e34d1b fix(ansibleserver): force sleep 50s before running 2022-10-18 10:23:48 +08:00
屈轩
9c733ff130 fix(websonsole): vnc query (#15197) 2022-10-15 22:05:26 +08:00
屈轩
aacdf17099 fix(glance): esxi vmdk requre streamOptimized (#15181) 2022-10-15 22:03:44 +08:00
Zexi Li
07f6572159 Merge pull request #15200 from gouqi11/automated-cherry-pick-of-#15198-upstream-release-3.9
Automated cherry pick of #15198: fix/huawei-aksk-createdAt
2022-10-14 21:12:33 +08:00
mhf
234741d0c4 fix/huawei-aksk-createdAt 2022-10-14 19:38:23 +08:00
Zexi Li
e842e970ba Merge pull request #15193 from zexi/automated-cherry-pick-of-#15192-upstream-release-3.9
Automated cherry pick of #15192: fix(scheduler): check free capacity of each storage
2022-10-14 13:33:06 +08:00
Zexi Li
acbbb6d6f5 fix(scheduler): check free capacity of each storage 2022-10-14 12:40:26 +08:00
Zexi Li
3769869a08 Merge pull request #15188 from ioito/automated-cherry-pick-of-#15187-upstream-release-3.9
Automated cherry pick of #15187: fix(region): optimized sku list
2022-10-14 10:35:13 +08:00
Zexi Li
4b0bdcfe8b Merge pull request #15184 from ioito/automated-cherry-pick-of-#15183-upstream-release-3.9
Automated cherry pick of #15183: fix(region): skip account check
2022-10-14 10:33:52 +08:00
ioito
9151709473 fix(region): optimized sku list 2022-10-13 18:12:31 +08:00
ioito
fb0645e837 fix(region): skip account check 2022-10-13 17:00:12 +08:00
Zexi Li
cfa36774e7 Merge pull request #15180 from ioito/automated-cherry-pick-of-#15179-upstream-release-3.9
Automated cherry pick of #15179: fix(region): skip duplicate account check
2022-10-13 12:14:38 +08:00
ioito
b4516df1a4 fix(region): skip duplicate account check 2022-10-13 12:07:22 +08:00
Zexi Li
6ccd2801f0 Merge pull request #15178 from swordqiu/automated-cherry-pick-of-#15177-upstream-release-3.9
Automated cherry pick of #15177: fix: disk fallocate support
2022-10-13 09:47:44 +08:00
Zexi Li
0baca192e3 Merge pull request #15164 from swordqiu/automated-cherry-pick-of-#15163-upstream-release-3.9
Automated cherry pick of #15163: fix: ssd(rotation_rate=1) option only applicable to scsi-hd device
2022-10-13 09:46:30 +08:00
Zexi Li
fe7cbbfee8 Merge pull request #15157 from ioito/automated-cherry-pick-of-#15156-upstream-release-3.9
Automated cherry pick of #15156: fix(region): openstack vnc
2022-10-13 09:46:00 +08:00
Zexi Li
fdbf01e158 Merge pull request #15171 from ioito/automated-cherry-pick-of-#15170-upstream-release-3.9
Automated cherry pick of #15170: fix(region): purge vm by tags
2022-10-13 09:45:19 +08:00
Zexi Li
e86e4d64e4 Merge pull request #15173 from ioito/automated-cherry-pick-of-#15172-upstream-release-3.9
Automated cherry pick of #15172: fix(cloudmon): show unmarshal error
2022-10-13 09:44:54 +08:00
Jian Qiu
fc916a22f2 fix: no etcd watching if endpoint type is not internal (#15176)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2022-10-13 09:36:52 +08:00
Qiu Jian
2887c8196f fix: disk fallocate support 2022-10-13 02:37:50 +08:00
ioito
3e7a321ad3 fix(cloudmon): show unmarshal error 2022-10-12 17:41:30 +08:00
ioito
dcf7bde095 fix(region): purge vm by tags 2022-10-12 16:36:25 +08:00
Zexi Li
9b2208a565 Merge pull request #15166 from ioito/automated-cherry-pick-of-#15165-upstream-release-3.9
Automated cherry pick of #15165: fix(region): avoid panic
2022-10-12 16:32:41 +08:00
ioito
4dad40e3b2 fix(region): avoid panic 2022-10-12 15:15:09 +08:00
屈轩
4142d03cce fix: climc image cache (#15153) 2022-10-12 14:55:49 +08:00
wanyaoqi
39bcd4c471 fix(region): only kvm use qgs set password in guest running status (#15159)
Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
2022-10-12 14:55:12 +08:00
Qiu Jian
9ad72f63f2 fix: ssd(rotation_rate=1) option only applicable to scsi-hd device 2022-10-12 14:54:05 +08:00
Jian Qiu
5150d3d86d fix: debian 11 support missing at release/3.8 (#15161)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2022-10-11 21:18:14 +08:00
ioito
47024114c6 fix(region): openstack vnc 2022-10-11 16:52:41 +08:00
Zexi Li
34266ad52e Merge pull request #15151 from wanyaoqi/automated-cherry-pick-of-#15150-upstream-release-3.9
Automated cherry pick of #15150: fix(host-image): cancel auth host-image http requests
2022-10-11 10:45:27 +08:00
Zexi Li
8e942046e6 Merge pull request #15141 from ioito/automated-cherry-pick-of-#15137-upstream-release-3.9
Automated cherry pick of #15137: fix(region): snapshot time zone
2022-10-11 10:43:56 +08:00
Zexi Li
b3afdc7b93 Merge pull request #15135 from swordqiu/automated-cherry-pick-of-#15134-upstream-release-3.9
Automated cherry pick of #15134: fix: override valid os info in metadata
2022-10-11 10:42:38 +08:00
Zexi Li
08411e3061 Merge pull request #15139 from ioito/automated-cherry-pick-of-#15138-upstream-release-3.9
Automated cherry pick of #15138: fix(region): lb sync panic
2022-10-11 10:40:58 +08:00
Zexi Li
d08864d9e7 Merge pull request #15155 from ioito/automated-cherry-pick-of-#15154-upstream-release-3.9
Automated cherry pick of #15154: fix(region): oss permission
2022-10-11 10:38:59 +08:00
ioito
62362a1887 fix(region): oss permission 2022-10-10 19:15:00 +08:00
Zexi Li
167d3d25e8 Merge pull request #15149 from ioito/automated-cherry-pick-of-#15148-upstream-release-3.9
Automated cherry pick of #15148: fix(region): apsara region endpoint
2022-10-10 15:50:47 +08:00
wanyaoqi
a92e4d72a2 fix(host-image): cancel auth host-image http requests 2022-10-10 10:51:07 +08:00
ioito
4d6490e7a1 fix(region): apsara region endpoint 2022-10-10 10:38:40 +08:00
Qiu Jian
807631b7ca fix: override valid os info in metadata 2022-10-09 23:55:34 +08:00
wanyaoqi
be9bd32824 fix(region): recover code remove by #14996 (#15145)
Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
2022-10-09 23:53:49 +08:00
wanyaoqi
8742ba05d5 fix(host): marshal cycle struct guest (#15146)
Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
2022-10-09 23:49:00 +08:00
ioito
8271d86911 fix(region): snapshot time zone 2022-10-09 16:21:56 +08:00
ioito
04ac34755c fix(region): lb sync panic 2022-10-09 15:46:39 +08:00
Zexi Li
3e6d9f0a59 Merge pull request #15103 from ioito/automated-cherry-pick-of-#15102-upstream-release-3.9
Automated cherry pick of #15102: fix(region): azure resource group
2022-10-09 15:36:09 +08:00
Zexi Li
2fea602ecd Merge pull request #15132 from ioito/automated-cherry-pick-of-#15131-upstream-release-3.9
Automated cherry pick of #15131: fix(region): add project tag short desc
2022-10-09 00:26:16 +08:00
Zexi Li
31540c1feb Merge pull request #15129 from ioito/automated-cherry-pick-of-#15128-upstream-release-3.9
Automated cherry pick of #15128: fix(cloudid): aliyun saml provider name
2022-10-09 00:25:17 +08:00
ioito
c66e16190b fix(region): azure resource group 2022-10-08 21:28:31 +08:00
Zexi Li
8b3f7ef336 optimize(scheduler): global cache for schedtag (#15120)
* optimize(scheduler): global cache for schedtag

* feat(scheduler): informer of schedtag
2022-10-08 20:49:26 +08:00
ioito
57005da632 fix(region): add project tag short desc 2022-10-08 18:21:40 +08:00
ioito
68a98c8eb6 fix(cloudid): aliyun saml provider name 2022-10-08 15:39:25 +08:00
Zexi Li
8dd802204f Merge pull request #15123 from ioito/automated-cherry-pick-of-#15122-upstream-release-3.9
Automated cherry pick of #15122: fix(region): modelarts change config
2022-10-08 14:45:54 +08:00
ioito
043b24cca1 fix(region): modelarts change config 2022-10-08 14:28:34 +08:00
Zexi Li
4534f951b1 Merge pull request #15117 from zexi/monitor-error-msg
fix(monitor): monitor error message
2022-10-08 12:03:24 +08:00
Zexi Li
02447ea1f9 fix(monitor): monitor error message 2022-10-08 11:49:18 +08:00
Jian Qiu
3b64b8709e fix: preserve os info of instance (#15115)
Co-authored-by: QIU Jian <qiujian@yunionyun.com>
2022-10-08 11:19:51 +08:00
Jian Qiu
117c5d60f4 update vendor wireguard 20221005 (#15113)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2022-10-05 17:17:53 +08:00
Zexi Li
5c9016bd0c Merge pull request #15110 from gouqi11/automated-cherry-pick-of-#15109-upstream-release-3.9
Automated cherry pick of #15109: fix modelarts status bug
2022-09-30 11:53:28 +08:00
mhf
c8c80dc95d fix modelarts status bug 2022-09-30 11:39:13 +08:00
Zexi Li
43154ddc00 Merge pull request #15106 from swordqiu/automated-cherry-pick-of-#15105-upstream-release-3.9
Automated cherry pick of #15105: fix: do not resize partition of unsupported fs
2022-09-29 10:08:07 +08:00
Qiu Jian
60d45f698b fix: do not resize partition of unsupported fs 2022-09-29 00:56:26 +08:00
Zexi Li
a7ee027326 Merge pull request #15101 from ioito/automated-cherry-pick-of-#15100-upstream-release-3.9
Automated cherry pick of #15100: fix(cloudmon): remove cloudmon metadata tag
2022-09-28 19:32:08 +08:00
ioito
b98983a2df fix(cloudmon): remove cloudmon metadata tag 2022-09-28 18:16:58 +08:00
Zexi Li
1b50d263c4 Merge pull request #15097 from zexi/ansible-sleep
fix(ansibleserver): force sleep 15s before running playbook
2022-09-28 17:38:52 +08:00
Zexi Li
24a3ff8fa9 fix(ansibleserver): force sleep 15s before running playbook 2022-09-28 17:21:56 +08:00
wanyaoqi
6d2e8fdfc1 fix(region): check migration bandwidth is nil (#15095) 2022-09-28 16:41:45 +08:00
Zexi Li
6a9dc28b72 Merge pull request #15096 from gouqi11/automated-cherry-pick-of-#15094-upstream-release-3.9
Automated cherry pick of #15094: add modelarts nodecount
2022-09-28 16:11:34 +08:00
mhf
de65b32a47 add modelarts nodecount 2022-09-28 15:49:30 +08:00
屈轩
e715a725db fix(cloudid): azure cloudgroup (#15093) 2022-09-28 15:27:28 +08:00
屈轩
6119e60c46 fix(monitor): rename tags to tag_pairs (#15088) 2022-09-28 15:26:40 +08:00
wanyaoqi
20b7b9b9f6 fix(host): rbd snap delete (#15083) 2022-09-28 15:25:27 +08:00
wanyaoqi
7d0a88a605 Automated cherry pick of #15067: fix(region): host health use sync map (#15085)
* fix(region): host health use sync map

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>

* fix auto migrate on host shutdown

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
2022-09-28 14:12:56 +08:00
Zexi Li
0516f72f46 fix(cloudcommon): notify event of specific resources (#15089) 2022-09-28 13:00:56 +08:00
Zexi Li
c4f0cb4dcd fix(host): out of range when list GPU devices (#15081) 2022-09-28 07:52:56 +08:00
屈轩
f8ef56cf38 fix(region): secgroup rule sync (#15076) 2022-09-27 21:23:00 +08:00
屈轩
aa99aa449e fix(climc): add debug for esxicli (#15060) 2022-09-27 21:22:08 +08:00
Zexi Li
386467927a fix(monitor): not depend taskman to execute async task (#15064) 2022-09-27 21:14:21 +08:00
Zexi Li
f9281c738d fix(cloudcommon): invoke model.PostUpdate when differences exist (#15069) 2022-09-27 21:10:52 +08:00
屈轩
ed8af7fc6f fix(cloudid): azure clouduser (#15073) 2022-09-27 21:10:04 +08:00
屈轩
077390519d fix(cloudmon): remove special characters (#15063) 2022-09-27 21:04:13 +08:00
Zexi Li
791e0753c4 Merge pull request #15058 from zexi/automated-cherry-pick-of-#15053-upstream-release-3.9
Automated cherry pick of #15053: feat(host): deploy telegraf in windows guest
2022-09-27 11:32:14 +08:00
wanyaoqi
ad0d7fde15 feat(host): deploy telegraf in windows guest
depends on telegraf service install command.
2022-09-27 11:31:51 +08:00
Zexi Li
59780e863d Merge pull request #15034 from wanyaoqi/automated-cherry-pick-of-#15033-upstream-release-3.9
Automated cherry pick of #15033: fix(region): migrate forecase add rescue mode
2022-09-26 15:22:59 +08:00
Zexi Li
fec651c425 Merge pull request #15050 from zexi/baremetal-storage
feat(region): is_baremetal option for storage list
2022-09-26 15:20:07 +08:00
Zexi Li
968cd4e6ff Merge pull request #15049 from ioito/automated-cherry-pick-of-#15048-upstream-release-3.9
Automated cherry pick of #15048: fix(monitor): influx query
2022-09-26 15:04:51 +08:00
Zexi Li
ee78115b44 feat(region): is_baremetal option for storage list 2022-09-26 15:02:33 +08:00
ioito
dac5f69abe fix(monitor): influx query 2022-09-26 15:01:24 +08:00
Zexi Li
309c69dcfd Merge pull request #15047 from ioito/automated-cherry-pick-of-#15046-upstream-release-3.9
Automated cherry pick of #15046: Hotfix/qx monitor misc
2022-09-26 14:06:09 +08:00
小林仔
12cbc9c697 support simple query 2022-09-26 13:28:19 +08:00
Zexi Li
8b3bb04adc Merge pull request #15042 from ioito/automated-cherry-pick-of-#15041-upstream-release-3.9
Automated cherry pick of #15041: fix(cloudid): role obs iam
2022-09-23 17:06:08 +08:00
ioito
cc56f30de8 fix(cloudid): role obs iam 2022-09-23 16:47:47 +08:00
Zexi Li
f0d7c4ea09 Merge pull request #15040 from swordqiu/automated-cherry-pick-of-#15039-upstream-release-3.9
Automated cherry pick of #15039: fix: ihost add cpu_architecture interface
2022-09-23 16:07:39 +08:00
QIU Jian
5b54fe3256 fix: ihost add cpu_architecture interface 2022-09-23 14:50:20 +08:00
wanyaoqi
4dd3a6a163 Automated cherry pick of #14996: fix(host): live migrate optimize (#15020)
* fix(host): live migrate optimize

- support set live migrate bandwidth
- support cancel migrate
- live migrate enable multifd
- cancel set live migrate max downtime in init live migrate
- save and sync guest desc and start script on sync config

* feat(region,host): server-monitor support qmp

server-montior add qmp option, default is hmp.

usage:
    climc server-monitor --qmp <ID> <COMMAND>

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
2022-09-23 14:09:47 +08:00
Jian Qiu
32931791cf fix: splitable duplicate records (#15038)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2022-09-23 14:09:11 +08:00
屈轩
6c680c9294 fix(region): avoid panic when show dns zone (#15036) 2022-09-23 13:52:53 +08:00
wanyaoqi
7db9a50f79 fix(region): migrate forecase add rescue mode
Signed-off-by: wanyaoqi <wanyaoqi@yunion.cn>
2022-09-23 11:02:04 +08:00
Zexi Li
bf98f587b8 Merge pull request #15023 from swordqiu/automated-cherry-pick-of-#15022-upstream-release-3.9
Automated cherry pick of #15022: fix: esxi save image fail
2022-09-23 10:12:58 +08:00
Zexi Li
9f9e5361f3 Merge pull request #15029 from ioito/automated-cherry-pick-of-#15028-upstream-release-3.9
Automated cherry pick of #15028: fix(cloudid): obs iam
2022-09-23 10:11:04 +08:00
ioito
201443dcec fix(cloudid): obs iam 2022-09-22 22:58:00 +08:00
Zexi Li
034c743ba6 Merge pull request #15027 from gouqi11/automated-cherry-pick-of-#15024-upstream-release-3.9
Automated cherry pick of #15024: HCSO modelarts monitor
2022-09-22 20:42:33 +08:00
mhf
2dca05c9c2 delete huaweiClient 2022-09-22 18:45:39 +08:00
Qiu Jian
2462128a32 fix: esxi save image fail 2022-09-22 02:10:15 +08:00
Zexi Li
6d6e46083d Merge pull request #15021 from gouqi11/automated-cherry-pick-of-#15018-upstream-release-3.9
Automated cherry pick of #15018: [WIP]add hcso modelarts
2022-09-21 20:56:26 +08:00
mhf
a0efef4c4d resert endpoint 2022-09-21 17:55:14 +08:00
mhf
5cd9d07115 add hcso modelarts 2022-09-21 17:55:14 +08:00
Zexi Li
c9fa13c63b Merge pull request #15014 from ioito/automated-cherry-pick-of-#15013-upstream-release-3.9
Automated cherry pick of #15013: fix(region): qcloud and google system tag
2022-09-21 14:35:39 +08:00
Zexi Li
9379930c21 Merge pull request #15017 from gouqi11/automated-cherry-pick-of-#15011-upstream-release-3.9
Automated cherry pick of #15011: add hcso aksk
2022-09-20 20:26:02 +08:00
mhf
0a1307bb4d add hcso aksk 2022-09-20 20:23:33 +08:00
Zexi Li
905dc803b9 Merge pull request #15016 from ioito/automated-cherry-pick-of-#15015-upstream-release-3.9
Automated cherry pick of #15015: fix(hostman): host and vm metric id
2022-09-20 18:41:34 +08:00
Zexi Li
a7824c6e42 Merge pull request #15012 from ioito/automated-cherry-pick-of-#15009-upstream-release-3.9
Automated cherry pick of #15009: fix(cloudid): clear cloudid error
2022-09-20 18:40:08 +08:00
ioito
ce6d4da16b fix(hostman): host and vm metric id 2022-09-20 18:03:59 +08:00
ioito
fdfd9ad858 fix(region): qcloud and google system tag 2022-09-20 17:41:36 +08:00
ioito
f68f09f067 fix(cloudid): clear cloudid error 2022-09-20 16:30:00 +08:00
Zexi Li
44fc286a9c Merge pull request #15005 from zexi/update-net-vlan-id
fix(climc): always net vlan_id to 1 when updating network
2022-09-20 10:46:28 +08:00
Zexi Li
3491ebdcb9 fix(climc): always net vlan_id to 1 when updating network 2022-09-20 10:44:08 +08:00
Zexi Li
409dd98850 Merge pull request #15002 from zexi/bm-no-cache
feat(baremetal,region): support disable_image_cache for baremetalagent
2022-09-20 10:29:35 +08:00
Zexi Li
21b831252d feat(baremetal,region): support disable_image_cache for baremetalagent 2022-09-20 10:04:21 +08:00
屈轩
26c351796f fix(cloudmon): unified metric id with resource id (#14998) 2022-09-19 22:55:30 +08:00
Zexi Li
7b78f205a9 Merge pull request #14955 from wanyaoqi/automated-cherry-pick-of-#14954-upstream-release-3.9
Automated cherry pick of #14954: feat(region,host): check disk type of gpfs mountpoint
2022-09-19 22:31:16 +08:00
Zexi Li
ea99da1fb5 Merge pull request #15004 from zexi/automated-cherry-pick-of-#14954-upstream-release-3.9
Automated cherry pick of #14954: feat(region,host): check disk type of gpfs mountpoint
2022-09-19 22:28:58 +08:00
wanyaoqi
b13417cba2 feat(region,host): check disk type of gpfs mountpoint
Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
2022-09-19 22:28:27 +08:00
Zexi Li
3a573a2242 Merge pull request #15000 from gouqi11/automated-cherry-pick-of-#14987-upstream-release-3.9
Automated cherry pick of #14987: fix modelarts create bug
2022-09-19 21:23:39 +08:00
mhf
7554a59eea fix modelarts create bug 2022-09-19 19:43:58 +08:00
屈轩
16d3cdc7aa fix(region): cloudaccount options (#14991) 2022-09-17 19:38:36 +08:00
wanyaoqi
f272e65780 feat(region,host): check disk type of gpfs mountpoint
Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
2022-09-16 18:27:48 +08:00
Zexi Li
5d6a431902 fix(monitor,region,climc): use commonalert api for scaling policy (#14979)
* fix(monitor,region,climc): use commonalert api for scaling policy

* fix(monitor): use commonalert as nodealert's backend
2022-09-16 10:33:59 +08:00
Zexi Li
a9c27a2273 Merge pull request #14975 from ioito/automated-cherry-pick-of-#14974-upstream-release-3.9
Automated cherry pick of #14974: fix(cloudmon): azure windows disk usage
2022-09-16 03:06:25 +08:00
wanyaoqi
7cbf045638 fix(host): get gpu qemu params (#14982)
Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
2022-09-15 22:48:53 +08:00
Zexi Li
1de4e19670 Merge pull request #14984 from gouqi11/automated-cherry-pick-of-#14983-upstream-release-3.9
Automated cherry pick of #14983: bugfix(modelarts)
2022-09-15 21:42:07 +08:00
mhf
e8228e4e3c modelartsBugFix 2022-09-15 21:40:07 +08:00
Zexi Li
077fd3f891 fix(host): no vm_scaling_group_id in hostmetrics (#14976) 2022-09-15 01:16:23 +08:00
ioito
4975acb914 fix(cloudmon): azure windows disk usage 2022-09-14 19:41:12 +08:00
Zexi Li
85c5e33cf9 Merge pull request #14973 from gouqi11/automated-cherry-pick-of-#14972-upstream-release-3.9
Automated cherry pick of #14972: modelarts
2022-09-14 16:00:44 +08:00
mhf
6671cf9fab modelarts 2022-09-14 15:34:19 +08:00
Zexi Li
6e987b0ba7 Merge pull request #14963 from ioito/automated-cherry-pick-of-#14962-upstream-release-3.9
Automated cherry pick of #14962: fix(region): azure win disk usage percent
2022-09-14 10:12:07 +08:00
Zexi Li
c9b3a4e95c Merge pull request #14964 from zexi/alert-not-recover
fix(monitor): alert resource not recorverd
2022-09-14 10:05:27 +08:00
Zexi Li
6a0b463874 Merge pull request #14968 from swordqiu/automated-cherry-pick-of-#14967-upstream-release-3.9
Automated cherry pick of #14967: fix: set vfs_cache_pressure to 350
2022-09-14 01:05:50 +08:00
Qiu Jian
cfa1f8d3a1 fix: set vfs_cache_pressure to 350 2022-09-13 17:01:29 +08:00
Zexi Li
91b1236e3f fix(monitor): alert resource not recorverd 2022-09-13 13:43:46 +08:00
ioito
586fb7f7cf fix(region): azure win disk usage percent 2022-09-13 10:40:11 +08:00
Zexi Li
8fee86088b Merge pull request #14960 from swordqiu/automated-cherry-pick-of-#14959-upstream-release-3.9
Automated cherry pick of #14959: fix: remove irrelevant common options
2022-09-13 08:56:55 +08:00
Qiu Jian
77f0dcb4c8 fix: remove irrelevant common options 2022-09-12 18:23:29 +08:00
Zexi Li
0e215facb9 fix(baremetal): clean UEFI info for baremetal host (#14956) 2022-09-12 18:19:51 +08:00
394 changed files with 22210 additions and 17150 deletions

View File

@@ -15,7 +15,10 @@
package cloudid
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/cmd/climc/shell"
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
modules "yunion.io/x/onecloud/pkg/mcclient/modules/cloudid"
"yunion.io/x/onecloud/pkg/mcclient/options/cloudid"
)
@@ -35,4 +38,10 @@ func init() {
cmd.Perform("reset-password", &cloudid.ClouduserResetPasswordOptions{})
cmd.Perform("cloud-user-join-group", &cloudid.ClouduserGroupOptions{})
cmd.Perform("cloud-user-leave-group", &cloudid.ClouduserGroupOptions{})
cmd.GetWithCustomShow("access-keys", func(result jsonutils.JSONObject) {
ret := modulebase.JSON2ListResult(result)
shell.PrintList(ret, nil)
}, &cloudid.ClouduserListAccessKeyInput{})
cmd.Perform("delete-access-key", &cloudid.ClouduserDeleteAccessKeyInput{})
cmd.Perform("create-access-key", &cloudid.ClouduserCreateAccessKeyInput{})
}

View File

@@ -17,69 +17,90 @@ package compute
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/cmd/climc/shell"
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type BaremetalAgentListOptions struct {
options.BaseListOptions
}
R(&BaremetalAgentListOptions{}, "agent-list", "List all agent", func(s *mcclient.ClientSession, args *BaremetalAgentListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Baremetalagents.List(s, params)
if err != nil {
return err
}
printList(result, modules.Baremetalagents.GetColumns(s))
return nil
})
type BaremetalAgentOpsOperations struct {
ID string `help:"ID or name of agent"`
}
R(&BaremetalAgentOpsOperations{}, "agent-show", "Show details of an agent", func(s *mcclient.ClientSession, args *BaremetalAgentOpsOperations) error {
result, err := modules.Baremetalagents.Get(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})
R(&BaremetalAgentOpsOperations{}, "agent-enable", "Enable agent", func(s *mcclient.ClientSession, args *BaremetalAgentOpsOperations) error {
result, err := modules.Baremetalagents.PerformAction(s, args.ID, "enable", nil)
if err != nil {
return err
}
printObject(result)
return nil
})
R(&BaremetalAgentOpsOperations{}, "agent-disable", "Disable agent", func(s *mcclient.ClientSession, args *BaremetalAgentOpsOperations) error {
result, err := modules.Baremetalagents.PerformAction(s, args.ID, "disable", nil)
if err != nil {
return err
}
printObject(result)
return nil
})
R(&BaremetalAgentOpsOperations{}, "agent-delete", "Delete agent", func(s *mcclient.ClientSession, args *BaremetalAgentOpsOperations) error {
result, err := modules.Baremetalagents.Delete(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})
type AgentListOptions struct {
options.BaseListOptions
}
func (o AgentListOptions) Params() (jsonutils.JSONObject, error) {
return o.BaseListOptions.Params()
}
func (o AgentListOptions) Description() string {
return "List all agent"
}
type AgentOpsOperations struct {
ID string `help:"ID or name of agent"`
}
func (o AgentOpsOperations) GetId() string {
return o.ID
}
func (o AgentOpsOperations) Params() (jsonutils.JSONObject, error) {
return nil, nil
}
type AgentShowOpt struct {
AgentOpsOperations
}
func (o AgentShowOpt) Description() string {
return "Show details of an agent"
}
type AgentEnableOpt struct {
AgentOpsOperations
}
func (o AgentEnableOpt) Description() string {
return "Enable agent"
}
type AgentDisableOpt struct {
AgentOpsOperations
}
func (o AgentDisableOpt) Description() string {
return "Disable agent"
}
type AgentDeleteOpt struct {
AgentOpsOperations
}
func (o AgentDeleteOpt) Description() string {
return "Delete agent"
}
type AgentEnableImageCacheOpt struct {
AgentOpsOperations
}
func (o AgentEnableImageCacheOpt) Description() string {
return "Enable cache image of a agent"
}
type AgentDisableImageCacheOpt struct {
AgentOpsOperations
}
func (o AgentDisableImageCacheOpt) Description() string {
return "Disable cache image of a agent"
}
func init() {
cmd := shell.NewResourceCmd(&modules.Baremetalagents).WithKeyword("agent")
cmd.List(new(AgentListOptions))
cmd.Show(new(AgentShowOpt))
cmd.Perform("enable", new(AgentEnableOpt))
cmd.Perform("disable", new(AgentDisableOpt))
cmd.Perform("enable-image-cache", new(AgentEnableImageCacheOpt))
cmd.Perform("disable-image-cache", new(AgentDisableImageCacheOpt))
cmd.Delete(new(AgentDeleteOpt))
}

View File

@@ -47,7 +47,7 @@ func init() {
return
}
for k, v := range rc {
fmt.Printf(`export %s="%s"`+"\n", k, v)
fmt.Printf(`export %s='%s'`+"\n", k, v)
}
}, &options.BaseIdOptions{})
cmd.Get("storage-classes", &compute.CloudproviderStorageClassesOptions{})

View File

@@ -0,0 +1,31 @@
// 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/cmd/climc/shell"
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
"yunion.io/x/onecloud/pkg/mcclient/options"
"yunion.io/x/onecloud/pkg/mcclient/options/compute"
)
func init() {
cmd := shell.NewResourceCmd(&modules.ModelartsPools).WithKeyword("modelarts-pool")
cmd.List(&compute.ModelartsPoolListOptions{})
cmd.Delete(&options.BaseIdOptions{})
cmd.Create(&compute.ModelartsPoolCreateOption{})
cmd.Perform("syncstatus", &compute.ModelartsPoolSyncstatusOption{})
cmd.Perform("change-config", &compute.ModelartsPoolChangeConfigOption{})
}

View File

@@ -0,0 +1,26 @@
// 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/cmd/climc/shell"
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
"yunion.io/x/onecloud/pkg/mcclient/options/compute"
)
func init() {
cmd := shell.NewResourceCmd(&modules.ModelartsPoolSku).WithKeyword("modelarts-pool-sku")
cmd.List(&compute.ModelartsPoolSkuListOptions{})
}

View File

@@ -66,6 +66,8 @@ func init() {
cmd.PrintObjectYAML().Perform("migrate-forecast", new(options.ServerMigrateForecastOptions))
cmd.Perform("migrate", new(options.ServerMigrateOptions))
cmd.Perform("live-migrate", new(options.ServerLiveMigrateOptions))
cmd.BatchPerform("cancel-live-migrate", new(options.ServerIdsOptions))
cmd.Perform("set-live-migrate-params", new(options.ServerSetLiveMigrateParamsOptions))
cmd.Perform("modify-src-check", new(options.ServerModifySrcCheckOptions))
cmd.Perform("set-secgroup", new(options.ServerSecGroupsOptions))
cmd.Perform("add-secgroup", new(options.ServerSecGroupsOptions))
@@ -108,6 +110,7 @@ func init() {
cmd.Perform("qga-set-password", &options.ServerQgaSetPassword{})
cmd.Perform("qga-command", &options.ServerQgaCommand{})
cmd.Perform("set-password", &options.ServerSetPasswordOptions{})
cmd.Perform("monitor", &options.ServerMonitorOptions{})
cmd.Get("vnc", new(options.ServerIdOptions))
cmd.Get("desc", new(options.ServerIdOptions))
@@ -309,23 +312,6 @@ func init() {
return nil
})
R(&options.ServerMonitorOptions{}, "server-monitor", "Send commands to qemu monitor", func(s *mcclient.ClientSession, opts *options.ServerMonitorOptions) error {
params, err := baseoptions.StructToParams(opts)
if err != nil {
return err
}
ret, err := modules.Servers.PerformAction(s, opts.ID, "monitor", params)
if err != nil {
return err
}
result, err := ret.GetString("results")
if err != nil {
return err
}
fmt.Println(result)
return nil
})
type ServerDiskSnapshotOptions struct {
SERVER string `help:"server ID or Name"`
DISK string `help:"create snapshot disk id"`

View File

@@ -29,7 +29,7 @@ import (
func init() {
cmd := NewResourceCmd(monitor.Alerts)
cmd.List(new(options.AlertListOptions))
cmd.Create(new(options.AlertCreateOptions))
// cmd.Create(new(options.AlertCreateOptions))
cmd.Show(new(options.AlertShowOptions))
cmd.Update(new(options.AlertUpdateOptions))
cmd.BatchDelete(new(options.AlertDeleteOptions))

View File

@@ -20,7 +20,8 @@ import (
)
func init() {
cmd := NewResourceCmd(modules.CommonAlertManager)
cmd := NewResourceCmd(modules.CommonAlerts)
cmd.Create(new(options.CommonAlertCreateOptions))
cmd.List(new(options.CommonAlertListOptions))
cmd.Show(new(options.CommonAlertShowOptions))
cmd.Perform("enable", &options.CommonAlertShowOptions{})

View File

@@ -0,0 +1,26 @@
// 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 monitor
import (
"yunion.io/x/onecloud/cmd/climc/shell"
"yunion.io/x/onecloud/pkg/mcclient/modules/monitor"
options "yunion.io/x/onecloud/pkg/mcclient/options/monitor"
)
func init() {
cmd := shell.NewResourceCmd(monitor.UnifiedMonitorManager).WithKeyword("monitor")
cmd.Show(&options.SimpleQueryOptions{})
}

View File

@@ -35,6 +35,8 @@ type BaseOptions struct {
Port int `help:"Service port" default:"$VMWARE_PORT" metavar:"VMWARE_PORT"`
Account string `help:"VCenter or ESXi Account" default:"$VMWARE_ACCOUNT" metavar:"VMWARE_ACCOUNT"`
Password string `help:"Password" default:"$VMWARE_PASSWORD" metavar:"VMWARE_PASSWORD"`
Debug bool
Format string `choices:"xml|json" default:"json"`
SUBCOMMAND string `help:"aliyuncli subcommand" subcommand:"true"`
}
@@ -101,7 +103,7 @@ func newClient(options *BaseOptions) (*esxi.SESXiClient, error) {
cloudprovider.ProviderConfig{
ProxyFunc: proxyFunc,
},
),
).Debug(options.Debug).Format(options.Format),
)
}

18
go.mod
View File

@@ -82,15 +82,15 @@ require (
github.com/vmware/govmomi v0.20.1
go.etcd.io/etcd/api/v3 v3.5.0
go.etcd.io/etcd/client/v3 v3.5.0
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/net v0.0.0-20210525063256-abc453219eb5
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
golang.org/x/net v0.0.0-20220418201149-a630d4f3e7a2
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261
golang.org/x/text v0.3.7
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20191008142428-8d021180e987
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20220916014741-473347a5e6e3
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.27.1
gopkg.in/fatih/set.v0 v0.2.1
@@ -102,15 +102,17 @@ require (
k8s.io/cluster-bootstrap v0.19.3
moul.io/http2curl/v2 v2.3.0
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
yunion.io/x/jsonutils v1.0.0
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
yunion.io/x/log v1.0.0
yunion.io/x/ovsdb v0.0.0-20200526071744-27bf0940cbc7
yunion.io/x/pkg v1.0.1-0.20220630095420-9925accd7c5e
yunion.io/x/pkg v1.0.1-0.20220819080140-55b265a8658e
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
yunion.io/x/sqlchemy v1.1.2-0.20220704015412-b0c3988ceaa2
yunion.io/x/sqlchemy v1.1.2-0.20220923040147-ddd3e96868af
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6
)
require github.com/google/uuid v1.3.0
require (
cloud.google.com/go v0.65.0 // indirect
github.com/Azure/go-autorest/autorest/adal v0.8.2 // indirect
@@ -175,10 +177,8 @@ require (
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/googleapis/gnostic v0.4.1 // indirect
github.com/googollee/go-engine.io v0.0.0-20180829091931-e2f255711dcb // indirect
@@ -242,7 +242,7 @@ require (
go.uber.org/zap v1.17.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/tools v0.1.2 // indirect
google.golang.org/api v0.30.0 // indirect
google.golang.org/appengine v1.6.6 // indirect

47
go.sum
View File

@@ -308,6 +308,7 @@ github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptG
github.com/golang-plus/errors v1.0.0 h1:9Rh4itnph6OYO7wm9u3FUTLMFMKCoL07+bLiYKELxWw=
github.com/golang-plus/errors v1.0.0/go.mod h1:YTFZjOTBcUFieeZe4q+7Umfu/sceSr3XQyBIkTkzpd8=
github.com/golang-plus/testing v1.0.0 h1:azmFWFV44LHK/j/jAkNTbzB2G2b6HdmqF358r73m8kg=
github.com/golang-plus/testing v1.0.0/go.mod h1:psANDlKPZ0ycedUzCS0Trf8h98sFyOyB51FlqyU+Ltc=
github.com/golang-plus/uuid v1.0.0 h1:ga84hG89vda++AGpup4N/cbfbM3O4d3R5ON9/jcN6AY=
github.com/golang-plus/uuid v1.0.0/go.mod h1:pBDDRrdgRHHqyYlj1d1i2gwyBq62Zc+sP2cDiCDkBLI=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@@ -431,7 +432,6 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGw
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
@@ -512,10 +512,6 @@ github.com/mdlayher/arp v0.0.0-20190313224443-98a83c8a2717/go.mod h1:eOj1DDj3NAZ
github.com/mdlayher/ethernet v0.0.0-20190313224307-5b5fc417d966/go.mod h1:5s5p/sMJ6sNsFl6uCh85lkFGV8kLuIYJCRJLavVJwvg=
github.com/mdlayher/ethernet v0.0.0-20190606142754-0394541c37b7 h1:lez6TS6aAau+8wXUP3G9I3TGlmPFEq2CTxBaRqY6AGE=
github.com/mdlayher/ethernet v0.0.0-20190606142754-0394541c37b7/go.mod h1:U6ZQobyTjI/tJyq2HG+i/dfSoFUt8/aZCM+GKtmFk/Y=
github.com/mdlayher/genetlink v0.0.0-20191004171646-5cf585d3b847/go.mod h1:LNhNWFVJapYK8zEjVHUIle4gy+Oahfc3UtcaqZ8Dz98=
github.com/mdlayher/netlink v0.0.0-20190409211403-11939a169225/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA=
github.com/mdlayher/netlink v0.0.0-20191004170026-3c8695cb0643/go.mod h1:KxeJAFOFLG6AjpyDkQ/iIhxygIUKD+vcwqcnu43w/+M=
github.com/mdlayher/netlink v0.0.0-20191008140946-2a17fd90af51/go.mod h1:KxeJAFOFLG6AjpyDkQ/iIhxygIUKD+vcwqcnu43w/+M=
github.com/mdlayher/raw v0.0.0-20190313224157-43dbcdd7739d/go.mod h1:r1fbeITl2xL/zLbVnNHFyOzQJTgr/3fpf1lJX/cjzR8=
github.com/mdlayher/raw v0.0.0-20190606142536-fef19f00fc18/go.mod h1:7EpbotpCmVZcu+KCX4g9WaRNuu11uyhiW7+Le1dKawg=
github.com/mdlayher/raw v0.0.0-20190606144222-a54781e5f38f h1:Xjvm7UTnKTwrlhbs+8qA6I0v1iX77rY3QxftSgvOVRk=
@@ -526,7 +522,6 @@ github.com/mholt/caddy v0.10.11 h1:s8X+R8DuBbrrMuUTcWSxlDe567B0s5EDmiDBKSYsioY=
github.com/mholt/caddy v0.10.11/go.mod h1:Wb1PlT4DAYSqOEd03MsqkdkXnTxA8v9pKjdpxbqM1kY=
github.com/miekg/dns v1.1.25 h1:dFwPR6SfLtrSwgDcIq2bcU/gVutB4sNApq2HBdqcakg=
github.com/miekg/dns v1.1.25/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721/go.mod h1:Ickgr2WtCLZ2MDGd4Gr0geeCH5HybhRJbonOgQpvSxc=
github.com/minio/cli v1.20.0/go.mod h1:bYxnK0uS629N3Bq+AOZZ+6lwF77Sodk4+UL9vNuXhOY=
github.com/minio/minio-go v6.0.14+incompatible h1:fnV+GD28LeqdN6vT2XdGKW8Qe/IfjJDswNVuni6km9o=
github.com/minio/minio-go v6.0.14+incompatible/go.mod h1:7guKYtitv8dktvNUGrhzmNlA5wrAABTQXCoesZdFQO8=
@@ -742,15 +737,13 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -805,10 +798,7 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191003171128-d98b1b443823/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191007182048-72f939374954/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -827,8 +817,9 @@ golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220418201149-a630d4f3e7a2 h1:6mzvA99KwZxbOrxww4EvWVQUnN1+xEu9tafK5ZxkYeA=
golang.org/x/net v0.0.0-20220418201149-a630d4f3e7a2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -858,7 +849,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190411185658-b44545bcd369/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190418153312-f0ce4c0180be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -868,15 +858,11 @@ golang.org/x/sys v0.0.0-20190606122018-79a91cf218c4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190830023255-19e00faab6ad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191003212358-c178f38b412c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -915,8 +901,8 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 h1:v6hYoSR9T5oet+pMXwUWkbiVqx/63mlHjefrHmxwfeY=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -986,9 +972,8 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.zx2c4.com/wireguard v0.0.20190908/go.mod h1:LhfXh5z6bLC2lW2ve6BzYZFwnnsXK3OQjySR0Yh2dO8=
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20191008142428-8d021180e987 h1:26OAgqBTufVr8WKonCEhhjO1oKsYhHv0iM5Dg92G1TM=
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20191008142428-8d021180e987/go.mod h1:7hq1rEDsx7/FWl8IEEnfH2Xhs6M2MNnjUfN0PeI8Rm0=
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20220916014741-473347a5e6e3 h1:ARxNdT6I+00ZyY5yRT/ZECkQti4iGrMZX9dvG/ao/LY=
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20220916014741-473347a5e6e3/go.mod h1:yp4gl6zOlnDGOZeWeDfMwQcsdOIQnMdhuPx9mwwWBL4=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
@@ -1148,8 +1133,9 @@ sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
yunion.io/x/jsonutils v1.0.0 h1:ySgXdIoRqUZRYA0t8QVqRkWgV8IWJlh2JtGovqqc+iI=
yunion.io/x/jsonutils v1.0.0/go.mod h1:p0nyMqGA/apTxxyLIU/o1k4V7Vujl2O6ey30L594sYE=
yunion.io/x/jsonutils v0.0.0-20220106020632-953b71a4c3a8/go.mod h1:p0nyMqGA/apTxxyLIU/o1k4V7Vujl2O6ey30L594sYE=
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd h1:QUAIH9oqQoDRz/byjE8id4yZE1qbCc53QzhsfcLzQp8=
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd/go.mod h1:L5QYTYqiL+f56wzir14TWHurE3Vcn9elaFiQpPWhXsg=
yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b/go.mod h1:+gauLs73omeJAPlsXcevLsJLKixV+sR/E7WSYTSx1fE=
yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d/go.mod h1:LC6f/4FozL0iaAbnFt2eDX9jlsyo3WiOUPm03d7+U4U=
yunion.io/x/log v1.0.0 h1:VPgssPi8Om+KAHjlEjf6RDU86du//yO+X0upu+h6fZM=
@@ -1159,11 +1145,12 @@ yunion.io/x/ovsdb v0.0.0-20200526071744-27bf0940cbc7/go.mod h1:0vLkNEhlmA64HViPB
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v1.0.1-0.20220630095420-9925accd7c5e h1:p/Cb7z6gyJbZKnGMeOPL3pTmnphB9GLCU+8qMsln7qA=
yunion.io/x/pkg v1.0.1-0.20220630095420-9925accd7c5e/go.mod h1:nYOMflWG1wQC6301rGVglQva9bYbJxHThEJUxRAgMFc=
yunion.io/x/pkg v1.0.1-0.20220819080140-55b265a8658e h1:enPKN/yaKmRjw3PWEdA7HDd6VDqewvczIJbSRpO7R8E=
yunion.io/x/pkg v1.0.1-0.20220819080140-55b265a8658e/go.mod h1:nYOMflWG1wQC6301rGVglQva9bYbJxHThEJUxRAgMFc=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
yunion.io/x/sqlchemy v1.1.2-0.20220704015412-b0c3988ceaa2 h1:Kz+Np1WHxYIyn2SQJEolFrMifLoT1yNF6J34W0zbRc8=
yunion.io/x/sqlchemy v1.1.2-0.20220704015412-b0c3988ceaa2/go.mod h1:xXVfJLIxxTRTnPEaVIIoRZXqWyO8+takIOYhc+zO5KE=
yunion.io/x/sqlchemy v1.0.1/go.mod h1:FTdwPdGhMgh4E+UFXc9klI1Ok34fMuybTT+jLhOaIjI=
yunion.io/x/sqlchemy v1.1.2-0.20220923040147-ddd3e96868af h1:WjaARkzdxBQBD6j5I1MDMlJ0Z3WOHzEp5bTQl+TScaU=
yunion.io/x/sqlchemy v1.1.2-0.20220923040147-ddd3e96868af/go.mod h1:xXVfJLIxxTRTnPEaVIIoRZXqWyO8+takIOYhc+zO5KE=
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6 h1:WuWXhY3DvhdRTzWCJ/kwt3Ss6KIq7+KqJwb+esvNGwU=
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=

View File

@@ -149,6 +149,9 @@ func (apb *SAnsiblePlaybookV2) runPlaybook(ctx context.Context, userCred mcclien
return fmt.Errorf("playbook is already running")
}
// hack: force Sleep 50s to wait some host ssh service started
time.Sleep(50 * time.Second)
var (
privateKey string
err error

View File

@@ -145,10 +145,8 @@ func (h *AuthHandlers) GetRegionsResponse(ctx context.Context, w http.ResponseWr
Domains: []string{},
ReturnFullDomains: false,
Idps: []agapi.SIdp{},
SCommonConfig: agapi.SCommonConfig{
ApiServer: options.Options.ApiServer,
},
EncryptPasswd: true,
EncryptPasswd: true,
ApiServer: options.Options.ApiServer,
}
s := auth.GetAdminSession(ctx, regions[0])
@@ -195,12 +193,10 @@ func (h *AuthHandlers) GetRegionsResponse(ctx context.Context, w http.ResponseWr
// fetch this option directly from Keystone
commonCfg, err := modules.ServicesV3.GetSpecific(s, "common", "config", nil)
if err == nil && commonCfg != nil {
config := agapi.SCommonConfig{}
commonCfg.Unmarshal(&config, "config", "default")
if len(config.ApiServer) > 0 {
ret.ApiServer = config.ApiServer
apiServer, _ := commonCfg.GetString("config", "default", "api_server")
if len(apiServer) > 0 {
ret.ApiServer = apiServer
}
ret.IsForgetLoginUser = config.IsForgetLoginUser
}
return ret, nil
}

View File

@@ -23,11 +23,6 @@ type SIdp struct {
IsDefault bool `json:"is_default"`
}
type SCommonConfig struct {
ApiServer string `json:"api_server,allowempty"`
IsForgetLoginUser bool `json:"is_forget_login_user"`
}
type SRegionsReponse struct {
Regions []string `json:"regions,allowempty"`
Domains []string `json:"domains,allowempty"`
@@ -37,5 +32,5 @@ type SRegionsReponse struct {
EncryptPasswd bool `json:"encrypt_passwd"`
SCommonConfig
ApiServer string `json:"api_server,allowempty"`
}

View File

@@ -268,3 +268,14 @@ type ClouduserChangeOwnerInput struct {
// 本地用户Id
UserId string `json:"user_id"`
}
type ClouduserCreateAccessKeyInput struct {
Name string `json:"name"`
}
type ClouduserDeleteAccessKeyInput struct {
AccessKey string `json:"access_key"`
}
type ClouduserListAccessKeyInput struct {
}

View File

@@ -580,6 +580,8 @@ type GuestBatchMigrateRequest struct {
SkipCpuCheck bool `json:"skip_cpu_check"`
SkipKernelCheck bool `json:"skip_kernel_check"`
EnableTLS *bool `json:"enable_tls"`
MaxBandwidthMb *int64 `json:"max_bandwidth_mb"`
QuciklyFinish *bool `json:"quickly_finish"`
}
type GuestBatchMigrateParams struct {
@@ -590,6 +592,8 @@ type GuestBatchMigrateParams struct {
EnableTLS *bool
RescueMode bool
OldStatus string
MaxBandwidthMb *int64
QuciklyFinish *bool
}
type HostLoginInfo struct {

View File

@@ -16,7 +16,6 @@ package compute
import (
"net/http"
"strings"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/regutils"
@@ -66,6 +65,7 @@ type BucketDetails struct {
func (self BucketDetails) GetMetricTags() map[string]string {
ret := map[string]string{
"id": self.Id,
"brand": self.Brand,
"cloudregion": self.Cloudregion,
"cloudregion_id": self.CloudregionId,
@@ -77,11 +77,7 @@ func (self BucketDetails) GetMetricTags() map[string]string {
"status": self.Status,
"tenant": self.Project,
"tenant_id": self.ProjectId,
}
for k, v := range self.Metadata {
if strings.HasPrefix(k, apis.USER_TAG_PREFIX) {
ret[k] = v
}
"external_id": self.ExternalId,
}
return ret
}

View File

@@ -17,7 +17,6 @@ package compute
import (
"fmt"
"reflect"
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/gotypes"
@@ -146,6 +145,9 @@ type CloudaccountCreateInput struct {
// swagger:ignore
AccountId string
// 跳过重复账号注册检查
SkipDuplicateAccountCheck bool
// 指定云平台品牌, 此参数默认和provider相同
// requried: false
//
@@ -321,17 +323,13 @@ type CloudaccountDetail struct {
func (self CloudaccountDetail) GetMetricTags() map[string]string {
ret := map[string]string{
"id": self.Id,
"cloudaccount_id": self.Id,
"cloudaccount_name": self.Name,
"brand": self.Brand,
"domain_id": self.DomainId,
"project_domain": self.ProjectDomain,
}
for k, v := range self.Metadata {
if strings.HasPrefix(k, apis.USER_TAG_PREFIX) {
ret[k] = v
}
}
return ret
}

View File

@@ -324,6 +324,7 @@ type DBInstanceDetails struct {
func (self DBInstanceDetails) GetMetricTags() map[string]string {
ret := map[string]string{
"id": self.Id,
"rds_id": self.Id,
"rds_name": self.Name,
"zone": self.Zone1Name,
@@ -339,15 +340,11 @@ func (self DBInstanceDetails) GetMetricTags() map[string]string {
"brand": self.Brand,
"domain_id": self.DomainId,
"project_domain": self.ProjectDomain,
"external_id": self.ExternalId,
}
if len(self.IpAddrs) > 0 {
ret["rds_ip"] = strings.ReplaceAll(self.IpAddrs, ",", "|")
}
for k, v := range self.Metadata {
if strings.HasPrefix(k, apis.USER_TAG_PREFIX) {
ret[k] = v
}
}
return ret
}

View File

@@ -15,7 +15,6 @@
package compute
import (
"strings"
"time"
"yunion.io/x/onecloud/pkg/apis"
@@ -40,6 +39,7 @@ type ElasticcacheDetails struct {
func (self ElasticcacheDetails) GetMetricTags() map[string]string {
ret := map[string]string{
"id": self.Id,
"redis_id": self.Id,
"redis_ip": self.PrivateIpAddr,
"redis_name": self.Name,
@@ -55,11 +55,7 @@ func (self ElasticcacheDetails) GetMetricTags() map[string]string {
"brand": self.Brand,
"domain_id": self.DomainId,
"project_domain": self.ProjectDomain,
}
for k, v := range self.Metadata {
if strings.HasPrefix(k, apis.USER_TAG_PREFIX) {
ret[k] = v
}
"external_id": self.ExternalId,
}
return ret
}

View File

@@ -71,6 +71,7 @@ const (
VM_START_MIGRATE = "start_migrate"
VM_MIGRATING = "migrating"
VM_LIVE_MIGRATING = "live_migrating"
VM_MIGRATE_FAILED = "migrate_failed"
VM_CHANGE_FLAVOR = "change_flavor"

View File

@@ -16,7 +16,6 @@ package compute
import (
"fmt"
"strings"
"time"
"yunion.io/x/jsonutils"
@@ -248,6 +247,7 @@ type ServerDetails struct {
func (self ServerDetails) GetMetricTags() map[string]string {
ret := map[string]string{
"id": self.Id,
"res_type": "guest",
"is_vm": "true",
"paltform": self.Hypervisor,
@@ -271,11 +271,7 @@ func (self ServerDetails) GetMetricTags() map[string]string {
"project_domain": self.ProjectDomain,
"account": self.Account,
"account_id": self.AccountId,
}
for k, v := range self.Metadata {
if strings.HasPrefix(k, apis.USER_TAG_PREFIX) {
ret[k] = v
}
"external_id": self.ExternalId,
}
return ret
}
@@ -439,6 +435,12 @@ type GuestLiveMigrateInput struct {
SkipKernelCheck *bool `json:"skip_kernel_check"`
// 是否启用 tls
EnableTLS *bool `json:"enable_tls"`
// 迁移带宽限制
MaxBandwidthMb *int64 `json:"max_bandwidth_mb"`
// 快速完成,内存同步一定周期后调整 downtime
QuicklyFinish *bool `json:"quickly_finish"`
KeepDestGuestOnFailed *bool `json:"keep_dest_guest_on_failed"`
}
type GuestSetSecgroupInput struct {
@@ -618,6 +620,7 @@ type ServerMigrateForecastInput struct {
LiveMigrate bool `json:"live_migrate"`
SkipCpuCheck bool `json:"skip_cpu_check"`
SkipKernelCheck bool `json:"skip_kernel_check"`
IsRescueMode bool `json:"is_rescue_mode"`
}
type ServerResizeDiskInput struct {
@@ -778,7 +781,7 @@ type GuestJsonDesc struct {
UserData string `json:"user_data"`
PendingDeleted bool `json:"pending_deleted"`
ScallingGroupId string `json:"scalling_group_id"`
ScalingGroupId string `json:"scaling_group_id"`
// baremetal
DiskConfig jsonutils.JSONObject `json:"disk_config"`
@@ -887,6 +890,11 @@ type ServerGetCPUSetCoresResp struct {
HostUsedCores []int `json:"host_used_cores"`
}
type ServerMonitorInput struct {
COMMAND string
QMP bool
}
type ServerQemuInfo struct {
Version string `json:"version"`
Cmdline string `json:"cmdline"`
@@ -909,3 +917,8 @@ type ServerSetPasswordInput struct {
ResetPassword bool
AutoStart bool
}
type ServerSetLiveMigrateParamsInput struct {
MaxBandwidthMB *int64
DowntimeLimitMS *int64
}

View File

@@ -15,8 +15,6 @@
package compute
import (
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/apis"
@@ -232,6 +230,7 @@ type HostDetails struct {
func (self HostDetails) GetMetricTags() map[string]string {
ret := map[string]string{
"id": self.Id,
"host_id": self.Id,
"host_ip": self.AccessIp,
"host": self.Name,
@@ -248,11 +247,7 @@ func (self HostDetails) GetMetricTags() map[string]string {
"account": self.Account,
"res_type": "host",
"account_id": self.AccountId,
}
for k, v := range self.Metadata {
if strings.HasPrefix(k, apis.USER_TAG_PREFIX) {
ret[k] = v
}
"external_id": self.ExternalId,
}
return ret
}

View File

@@ -53,6 +53,7 @@ type KubeClusterDetails struct {
func (self KubeClusterDetails) GetMetricTags() map[string]string {
ret := map[string]string{
"id": self.ExternalClusterId,
"res_type": "kube_cluster",
"cluster_id": self.ExternalClusterId,
"cluster_name": self.Name,
@@ -64,6 +65,7 @@ func (self KubeClusterDetails) GetMetricTags() map[string]string {
"project_domain": self.ProjectDomain,
"account": self.Account,
"account_id": self.AccountId,
"external_id": self.ExternalId,
}
return ret
}

View File

@@ -0,0 +1,87 @@
// 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/apis"
)
const (
MODELARTS_POOL_STATUS_RUNNING = "running"
MODELARTS_POOL_STATUS_ABNORMAL = "abnormal"
MODELARTS_POOL_STATUS_CREATING = "creating"
MODELARTS_POOL_STATUS_DELETING = "deleting"
MODELARTS_POOL_STATUS_CHANGE_CONFIG = "change_config"
MODELARTS_POOL_STATUS_ERROR = "error"
MODELARTS_POOL_STATUS_UNKNOWN = "unknown"
)
type ModelartsPoolCreateInput struct {
apis.VirtualResourceCreateInput
DeletePreventableCreateInput
CloudregionResourceInput
CloudproviderResourceInput
NodeCount int
}
type ModelartsPoolUpdateInput struct {
apis.StatusInfrasResourceBaseCreateInput
CloudproviderResourceInput
WorkType string `json:"work_type"`
}
// 资源返回详情
type ModelartsPoolDetails struct {
apis.SVirtualResourceBase
apis.VirtualResourceDetails
apis.SExternalizedResourceBase
SBillingResourceBase
ManagedResourceInfo
CloudregionResourceInfo
}
func (self ModelartsPoolDetails) GetMetricTags() map[string]string {
ret := map[string]string{
"id": self.Id,
"modelarts_pool_id": self.Id,
"modelarts_pool_name": self.Name,
"status": self.Status,
"tenant_id": self.ProjectId,
"brand": self.Brand,
"domain_id": self.DomainId,
"account_id": self.AccountId,
"account": self.Account,
"external_id": self.ExternalId,
}
return ret
}
type ModelartsPoolListInput struct {
apis.VirtualResourceListInput
apis.ExternalizedResourceBaseListInput
ManagedResourceListInput
RegionalFilterListInput
apis.DeletePreventableResourceBaseListInput
}
type ModelartsPoolSyncstatusInput struct {
}
type ModelartsPoolChangeConfigInput struct {
NodeCount int
}

View File

@@ -0,0 +1,36 @@
// 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/apis"
type ModelartsPoolSkuDetails struct {
apis.EnabledStatusStandaloneResourceDetails
ManagedResourceInfo
CloudregionResourceInfo
}
const (
MODELARTS_POOL_SKU_AVAILABLE = "available"
MODELARTS_POOL_SKU_SOLDOUT = "soldout"
)
type ModelartsPoolSkuListInput struct {
apis.EnabledStatusStandaloneResourceListInput
apis.ExternalizedResourceBaseListInput
RegionalFilterListInput
ManagedResourceListInput
}

View File

@@ -16,7 +16,6 @@ package compute
import (
"strconv"
"strings"
"yunion.io/x/jsonutils"
@@ -152,16 +151,13 @@ type StorageDetails struct {
func (self StorageDetails) GetMetricTags() map[string]string {
ret := map[string]string{
"id": self.Id,
"storage_id": self.Id,
"storage_name": self.Name,
"brand": self.Brand,
"domain_id": self.DomainId,
"project_domain": self.ProjectDomain,
}
for k, v := range self.Metadata {
if strings.HasPrefix(k, apis.USER_TAG_PREFIX) {
ret[k] = v
}
"external_id": self.ExternalId,
}
return ret
}

View File

@@ -236,4 +236,7 @@ type StorageListInput struct {
// filter storages which attached the specified host
HostId string `json:"host_id"`
// filter storages of baremetal host
IsBaremetal *bool `json:"is_baremetal"`
}

View File

@@ -104,7 +104,6 @@ var (
"default": []string{
"enable_quota_check",
"default_quota_value",
"enable_rbac",
"non_default_domain_projects",
"time_zone",
"domainized_namespace",
@@ -115,9 +114,6 @@ var (
"ignore_nonrunning_guests",
"platform_name",
"platform_names",
"is_forget_login_user",
"enable_organization",
"enable_tls_migration",
},
}

View File

@@ -20,6 +20,13 @@ import (
"yunion.io/x/onecloud/pkg/apis"
)
const (
AlertNotificationUsedByMeterAlert = "meter_alert"
AlertNotificationUsedByNodeAlert = "node_alert"
AlertNotificationUsedByCommonAlert = "common_alert"
AlertNotificationUsedByMigrationAlert = "migration_alert"
)
type AlertJointResourceBaseDetails struct {
apis.JointResourceBaseDetails
SAlertJointsBase

View File

@@ -54,6 +54,7 @@ type AlertRecordDetails struct {
func (self AlertRecordDetails) GetMetricTags() map[string]string {
ret := map[string]string{
"id": self.Id,
"alert_id": self.AlertId,
"alert_name": self.AlertName,
"domain_id": self.DomainId,

View File

@@ -21,8 +21,9 @@ const (
ALERT_STATUS_DELETING = "deleting"
ALERT_STATUS_DELETED = "deleted"
CommonAlertSystemAlertType = "system"
CommonAlertNomalAlertType = "normal"
CommonAlertSystemAlertType = "system"
CommonAlertNomalAlertType = "normal"
CommonAlertServiceAlertType = "service"
MonitorComponentType = "default-monitor"
MonitorComponentPort = 30093
@@ -40,16 +41,15 @@ const (
METRIC_QUERY_TYPE_NO_DATA = "nodata_query"
METRIC_QUERY_NO_DATA_THESHOLD = "nodata"
CommonAlertLevelNormal = "normal"
CommonAlertLevelImportant = "important"
CommonAlertLevelFatal = "fatal"
)
var CommonAlertLevels = []string{"normal", "important", "fatal"}
var CommonAlertLevels = []string{CommonAlertLevelNormal, CommonAlertLevelImportant, CommonAlertLevelFatal}
type CommonAlertCreateInput struct {
CommonMetricInputQuery
AlertCreateInput
// 查询指标周期
Period string `json:"period"`
type CommonAlertCreateBaseInput struct {
// 报警连续持续周期数
AlertDuration int64 `json:"alert_duration"`
// 通知方式, 比如: email, mobile
@@ -76,6 +76,15 @@ type CommonAlertCreateInput struct {
Description string `json:"description"`
}
type CommonAlertCreateInput struct {
CommonMetricInputQuery
AlertCreateInput
CommonAlertCreateBaseInput
// 查询指标周期
Period string `json:"period"`
}
type CommonMetricInputQuery struct {
From string `json:"from"`
To string `json:"to"`

View File

@@ -15,7 +15,7 @@
package monitor
import (
"time"
"strings"
)
const (
@@ -51,39 +51,79 @@ type NodeAlertCreateInput struct {
NodeName string `json:"node_name"`
// 监控资源 Id
NodeId string `json:"node_id"`
// CommonAlertCreateInput injected by server and do not pass it through API
CommonAlertCreateInput *CommonAlertCreateInput `json:"common_alert_create_input,omitempty"`
}
func (input NodeAlertCreateInput) ToAlertCreateInput(
func (input NodeAlertCreateInput) ToCommonAlertCreateInput(
name string,
field string,
measurement string,
db string) AlertCreateInput {
freq, _ := time.ParseDuration(input.Window)
ret := AlertCreateInput{
Name: name,
Frequency: int64(freq / time.Second),
Level: input.Level,
Settings: AlertSetting{
Conditions: []AlertCondition{
db string) CommonAlertCreateInput {
ret := CommonAlertCreateInput{
AlertCreateInput: AlertCreateInput{
Name: name,
Level: input.Level,
},
CommonAlertCreateBaseInput: CommonAlertCreateBaseInput{
Channel: strings.Split(input.Channel, ","),
Recipients: strings.Split(input.Recipients, ","),
AlertType: CommonAlertNomalAlertType,
},
CommonMetricInputQuery: CommonMetricInputQuery{
MetricQuery: []*CommonAlertQuery{
{
Type: "query",
Operator: "and",
Query: AlertQuery{
AlertQuery: &AlertQuery{
Model: input.GetQuery(field, measurement, db),
From: input.Period,
To: "now",
},
Evaluator: input.GetEvaluator(),
Reducer: Condition{
Type: "avg",
},
Comparator: input.Comparator,
Threshold: input.Threshold,
ConditionType: "query",
Reduce: "avg",
},
},
},
Period: input.Window,
}
ret.UsedBy = AlertNotificationUsedByNodeAlert
return ret
}
// func (input NodeAlertCreateInput) ToAlertCreateInput(
// name string,
// field string,
// measurement string,
// db string) AlertCreateInput {
// freq, _ := time.ParseDuration(input.Window)
// ret := AlertCreateInput{
// Name: name,
// Frequency: int64(freq / time.Second),
// Level: input.Level,
// Settings: AlertSetting{
// Conditions: []AlertCondition{
// {
// Type: "query",
// Operator: "and",
// Query: AlertQuery{
// Model: input.GetQuery(field, measurement, db),
// From: input.Period,
// To: "now",
// },
// Evaluator: input.GetEvaluator(),
// Reducer: Condition{
// Type: "avg",
// },
// },
// },
// },
// }
// return ret
// }
func (input NodeAlertCreateInput) GetQuery(field, measurement, db string) MetricQuery {
return GetNodeAlertQuery(input.Type, field, measurement, db, input.NodeId)
}
@@ -102,8 +142,9 @@ func GetNodeAlertQuery(typ, field, measurement, db, nodeId string) MetricQuery {
Selects: sels,
Tags: []MetricQueryTag{
{
Key: idField,
Value: nodeId,
Key: idField,
Operator: "=",
Value: nodeId,
},
},
GroupBy: []MetricQueryPart{
@@ -145,7 +186,7 @@ type V1AlertListInput struct {
}
type NodeAlertListInput struct {
V1AlertListInput
AlertListInput
// 监控指标名称
Metric string `json:"metric"`
@@ -157,6 +198,13 @@ type NodeAlertListInput struct {
NodeId string `json:"node_id"`
}
func (o NodeAlertListInput) ToCommonAlertListInput() CommonAlertListInput {
return CommonAlertListInput{
AlertListInput: o.AlertListInput,
Metric: o.Metric,
}
}
type AlertV1Details struct {
AlertDetails
@@ -185,7 +233,7 @@ type NodeAlertDetails struct {
}
type NodeAlertUpdateInput struct {
V1AlertUpdateInput
AlertUpdateInput
// 监控指标名称
Metric *string `json:"metric"`

View File

@@ -14,6 +14,8 @@
package monitor
import "time"
var (
UNIFIED_MONITOR_FIELD_OPT_TYPE = []string{"Aggregations", "Selectors"}
UNIFIED_MONITOR_GROUPBY_OPT_TYPE = []string{"time", "tag", "fill"}
@@ -83,3 +85,25 @@ type MetricInputQuery struct {
Signature string `json:"signature"`
ShowMeta bool `json:"show_meta"`
}
type SimpleQueryInput struct {
// 资源Id, 可以不填, 代表查询指定监控的所有监控数据
Id string `json:"id"`
// 查询指定数据库
// default: telegraf
Database string `json:"database"`
// 监控指标: https://github.com/codelinz/cloudpods/blob/monitor/pkg/cloudprovider/metrics.go
MetricName string `json:"metric_name"`
// 开始时间
StartTime time.Time `json:"start_time"`
// 结束时间
EndTime time.Time `json:"end_time"`
// 指定标签
Tags map[string]string `json:"tag_pairs"`
}
type SimpleQueryOutput struct {
Id string `json:"id"`
Time time.Time `json:"time"`
Value float64 `json:"value"`
}

View File

@@ -41,11 +41,9 @@ var (
baremetalAgent *SBaremetalAgent
)
//
// BaremetalAgent has two types of address
// - AccessAddress/Address: this is the address controller to accesss the agent
// - ListenAddress: this is the address baremetal to access the agent
//
type SBaremetalAgent struct {
agent.SBaseAgent
@@ -84,6 +82,10 @@ func (agent *SBaremetalAgent) GetAdminSession() *mcclient.ClientSession {
return auth.GetAdminSession(context.TODO(), o.Options.Region)
}
func (agent *SBaremetalAgent) GetPublicAdminSession() *mcclient.ClientSession {
return auth.GetAdminSessionWithPublic(context.TODO(), o.Options.Region)
}
func (agent *SBaremetalAgent) GetListenIP() (net.IP, error) {
return agent.FindListenIP(o.Options.ListenAddress)
}

View File

@@ -41,6 +41,7 @@ import (
"yunion.io/x/onecloud/pkg/apis"
api "yunion.io/x/onecloud/pkg/apis/compute"
apiidenty "yunion.io/x/onecloud/pkg/apis/identity"
o "yunion.io/x/onecloud/pkg/baremetal/options"
"yunion.io/x/onecloud/pkg/baremetal/profiles"
"yunion.io/x/onecloud/pkg/baremetal/pxe"
@@ -100,6 +101,10 @@ func (m *SBaremetalManager) GetClientSession() *mcclient.ClientSession {
return m.Agent.GetAdminSession()
}
func (m *SBaremetalManager) GetPublicClientSession() *mcclient.ClientSession {
return m.Agent.GetPublicAdminSession()
}
func (m *SBaremetalManager) GetZoneId() string {
return m.Agent.Zone.Id
}
@@ -549,6 +554,10 @@ func (b *SBaremetalInstance) GetClientSession() *mcclient.ClientSession {
return b.manager.GetClientSession()
}
func (b *SBaremetalInstance) GetPublicClientSession() *mcclient.ClientSession {
return b.manager.GetPublicClientSession()
}
func (b *SBaremetalInstance) Keyword() string {
return "host"
}
@@ -1061,7 +1070,15 @@ func (b *SBaremetalInstance) getTftpFileUrl(filename string) string {
return fmt.Sprintf("http://%s/tftp/%s", endpoint, filename)
}
func (b *SBaremetalInstance) GetImageCacheUrl() string {
func (b *SBaremetalInstance) GetImageUrl(disableImageCache bool) string {
if disableImageCache {
url, err := b.GetPublicClientSession().GetServiceURL(apis.SERVICE_TYPE_IMAGE, apiidenty.EndpointInterfacePublic, "")
if err != nil {
log.Errorf("Get image public url: %v", err)
return ""
}
return url
}
serverIP, err := b.manager.Agent.GetDHCPServerIP()
if err != nil {
log.Errorf("Get http file server: %v", err)
@@ -1607,7 +1624,7 @@ func (b *SBaremetalInstance) adjustUEFIWrapper(cli *ssh.Client, f func() error)
return errors.Wrap(err, "Check is uefi boot")
}
if !isUEFI {
return nil
return b.CleanUEFIInfo()
}
return f()
}
@@ -1625,13 +1642,8 @@ func (b *SBaremetalInstance) AdjustUEFICurrentBootOrder(hostCli *ssh.Client) err
})
}
func (b *SBaremetalInstance) SendUEFIInfo(mgr *uefi.BootMgr) error {
info, err := mgr.ToEFIBootMgrInfo()
if err != nil {
return err
}
func (b *SBaremetalInstance) updateUEFIInfo(uefiData jsonutils.JSONObject) error {
desc := b.desc
uefiData := jsonutils.Marshal(info)
desc.Add(uefiData, "uefi_info")
if err := b.SaveDesc(desc); err != nil {
return errors.Wrap(err, "Save uefi_info")
@@ -1644,6 +1656,24 @@ func (b *SBaremetalInstance) SendUEFIInfo(mgr *uefi.BootMgr) error {
return nil
}
func (b *SBaremetalInstance) CleanUEFIInfo() error {
if err := b.updateUEFIInfo(jsonutils.NewDict()); err != nil {
return errors.Wrap(err, "CleanUEFIInfo")
}
return nil
}
func (b *SBaremetalInstance) SendUEFIInfo(mgr *uefi.BootMgr) error {
info, err := mgr.ToEFIBootMgrInfo()
if err != nil {
return err
}
if err := b.updateUEFIInfo(jsonutils.Marshal(info)); err != nil {
return errors.Wrap(err, "SendUEFIInfo")
}
return nil
}
func (b *SBaremetalInstance) adjustServerUEFIBootOrder(srvCli *ssh.Client) error {
return b.adjustUEFIWrapper(srvCli, func() error {
info, err := b.GetUEFIInfo()
@@ -2651,10 +2681,10 @@ func replaceHostAddr(urlStr string, addr string) string {
return urlComp.String()
}
func (s *SBaremetalServer) doCreateRoot(term *ssh.Client, devName string) error {
func (s *SBaremetalServer) doCreateRoot(term *ssh.Client, devName string, disableImageCache bool) error {
session := s.baremetal.GetClientSession()
token := session.GetToken().GetTokenString()
urlStr := s.baremetal.GetImageCacheUrl()
urlStr := s.baremetal.GetImageUrl(disableImageCache)
imageId := s.GetRootTemplateId()
cmd := fmt.Sprintf("/lib/mos/rootcreate.sh %s %s %s %s", token, urlStr, imageId, devName)
log.Infof("rootcreate cmd: %q", cmd)
@@ -2664,7 +2694,7 @@ func (s *SBaremetalServer) doCreateRoot(term *ssh.Client, devName string) error
return nil
}
func (s *SBaremetalServer) DoPartitionDisk(tool *disktool.SSHPartitionTool, term *ssh.Client) ([]*disktool.Partition, error) {
func (s *SBaremetalServer) DoPartitionDisk(tool *disktool.SSHPartitionTool, term *ssh.Client, disableImageCache bool) ([]*disktool.Partition, error) {
raid, nonRaid, pcie, err := detect_storages.DetectStorageInfo(term, false)
if err != nil {
return nil, err
@@ -2697,7 +2727,7 @@ func (s *SBaremetalServer) DoPartitionDisk(tool *disktool.SSHPartitionTool, term
if len(rootImageId) > 0 {
rootDisk := disks[0]
rootSize, _ := rootDisk.Int("size")
err = s.doCreateRoot(term, tool.GetRootDisk().GetDevName())
err = s.doCreateRoot(term, tool.GetRootDisk().GetDevName(), disableImageCache)
if err != nil {
return nil, errors.Wrap(err, "Failed to create root")
}
@@ -2739,7 +2769,7 @@ func (s *SBaremetalServer) DoPartitionDisk(tool *disktool.SSHPartitionTool, term
return tool.GetPartitions(), nil
}
func (s *SBaremetalServer) DoRebuildRootDisk(tool *disktool.SSHPartitionTool, term *ssh.Client) ([]*disktool.Partition, error) {
func (s *SBaremetalServer) DoRebuildRootDisk(tool *disktool.SSHPartitionTool, term *ssh.Client, disableImageCache bool) ([]*disktool.Partition, error) {
// raid, nonRaid, pcie, err := detect_storages.DetectStorageInfo(term, false)
// if err != nil {
// return nil, err
@@ -2770,7 +2800,7 @@ func (s *SBaremetalServer) DoRebuildRootDisk(tool *disktool.SSHPartitionTool, te
rootDisk := disks[0]
rootSize, _ := rootDisk.Int("size")
rd := tool.GetRootDisk()
err := s.doCreateRoot(term, rd.GetDevName())
err := s.doCreateRoot(term, rd.GetDevName(), disableImageCache)
if err != nil {
return nil, fmt.Errorf("Failed to create root: %v", err)
}

View File

@@ -69,6 +69,10 @@ func (self *SBaremetalServerBaseDeployTask) NeedPXEBoot() bool {
return self.needPXEBoot
}
func (self *SBaremetalServerBaseDeployTask) IsDisableImageCache() bool {
return jsonutils.QueryBoolean(self.data, "disable_image_cache", false)
}
func (self *SBaremetalServerBaseDeployTask) GetFinishAction() string {
if self.data != nil {
action, _ := self.data.GetString("on_finish")

View File

@@ -97,7 +97,7 @@ func (self *SBaremetalCdromTask) DoInsertISO(ctx context.Context, args interface
if !fileutils2.Exists(localImagePath) {
return errors.Error("image not cached")
}
imageBaseUrl := self.Baremetal.GetImageCacheUrl()
imageBaseUrl := self.Baremetal.GetImageUrl(true)
if len(imageBaseUrl) == 0 {
return errors.Error("empty image base url")
}

View File

@@ -61,7 +61,7 @@ func (self *SBaremetalServerCreateTask) DoDeploys(term *ssh.Client) (jsonutils.J
return nil, self.onError(term, err)
}
time.Sleep(2 * time.Second)
parts, err := self.Baremetal.GetServer().DoPartitionDisk(tool, term)
parts, err := self.Baremetal.GetServer().DoPartitionDisk(tool, term, self.IsDisableImageCache())
if err != nil {
return nil, self.onError(term, err)
}

View File

@@ -62,7 +62,7 @@ type IBaremetal interface {
GenerateBootISO() error
SendNicInfo(nic *types.SNicDevInfo, idx int, nicType string, reset bool, ipAddr string, reserve bool) error
DoNTPConfig() error
GetImageCacheUrl() string
GetImageUrl(needImageCache bool) string
RemoveServer()
InitializeServer(session *mcclient.ClientSession, name string) error

View File

@@ -55,7 +55,7 @@ func (self *SBaremetalServerRebuildTask) DoDeploys(term *ssh.Client) (jsonutils.
if err != nil {
return nil, errors.Wrap(err, "NewConfigedSSHPartitionTool")
}
parts, err := self.Baremetal.GetServer().DoRebuildRootDisk(tool, term)
parts, err := self.Baremetal.GetServer().DoRebuildRootDisk(tool, term, self.IsDisableImageCache())
if err != nil {
return nil, fmt.Errorf("Rebuild root disk: %v", err)
}

View File

@@ -31,9 +31,9 @@ type IBaremetalServer interface {
DoDiskUnconfig(term *ssh.Client) error
DoDiskConfig(term *ssh.Client) (*disktool.SSHPartitionTool, error)
DoEraseDisk(term *ssh.Client) error
DoPartitionDisk(tool *disktool.SSHPartitionTool, term *ssh.Client) ([]*disktool.Partition, error)
DoPartitionDisk(tool *disktool.SSHPartitionTool, term *ssh.Client, disableImageCache bool) ([]*disktool.Partition, error)
NewConfigedSSHPartitionTool(term *ssh.Client) (*disktool.SSHPartitionTool, error)
DoRebuildRootDisk(tool *disktool.SSHPartitionTool, term *ssh.Client) ([]*disktool.Partition, error)
DoRebuildRootDisk(tool *disktool.SSHPartitionTool, term *ssh.Client, disableImageCache bool) ([]*disktool.Partition, error)
SyncPartitionSize(term *ssh.Client, parts []*disktool.Partition) ([]jsonutils.JSONObject, error)
DoDeploy(tool *disktool.SSHPartitionTool, term *ssh.Client, data jsonutils.JSONObject, isInit bool) (jsonutils.JSONObject, error)
SaveDesc(desc jsonutils.JSONObject) error

View File

@@ -18,7 +18,9 @@ import "fmt"
func GetYunionOSConfig(sleepTime int, httpSite, kernel string, kernelArgs string, initrd string) string {
kernel = fmt.Sprintf("(http,${http_site})/tftp/%s", kernel)
// kernel = fmt.Sprintf("(tftp,10.127.100.2)/%s", kernel)
initrd = fmt.Sprintf("(http,${http_site})/tftp/%s", initrd)
// initrd = fmt.Sprintf("(tftp,10.127.100.2)/%s", initrd)
return fmt.Sprintf(`
set timeout=%d
set http_site=%s

View File

@@ -62,7 +62,11 @@ func InitAuth(options *common_options.CommonOptions, authComplete auth.AuthCompl
if options.SessionEndpointType != "" {
if !utils.IsInStringArray(options.SessionEndpointType,
[]string{identity.EndpointInterfacePublic, identity.EndpointInterfaceInternal}) {
[]string{
identity.EndpointInterfacePublic,
identity.EndpointInterfaceInternal,
identity.EndpointInterfaceApigateway,
}) {
log.Fatalf("Invalid session endpoint type %s", options.SessionEndpointType)
}
auth.SetEndpointType(options.SessionEndpointType)
@@ -85,10 +89,12 @@ func InitAuth(options *common_options.CommonOptions, authComplete auth.AuthCompl
InitBaseAuth(&options.BaseOptions)
watcher := newEndpointChangeManager()
watcher.StartWatching(&identity_modules.EndpointsV3)
if options.SessionEndpointType == identity.EndpointInterfaceInternal {
watcher := newEndpointChangeManager()
watcher.StartWatching(&identity_modules.EndpointsV3)
startEtcdEndpointPuller()
startEtcdEndpointPuller()
}
}
func InitBaseAuth(options *common_options.BaseOptions) {
@@ -106,7 +112,7 @@ func FetchEtcdServiceInfo() (*identity.EndpointDetails, error) {
func startEtcdEndpointPuller() {
retryInterval := 60
etecdUrl, err := auth.GetServiceURL(apis.SERVICE_TYPE_ETCD, consts.GetRegion(), "", "")
etecdUrl, err := auth.GetServiceURL(apis.SERVICE_TYPE_ETCD, consts.GetRegion(), "", identity.EndpointInterfaceInternal)
if err != nil {
log.Errorf("[etcd] GetServiceURL fail %s, retry after %d seconds", err, retryInterval)
} else if len(etecdUrl) == 0 {

View File

@@ -1684,6 +1684,7 @@ func updateItem(manager IModelManager, item IModel, ctx context.Context, userCre
if len(diff) > 0 {
OpsLog.LogEvent(item, ACT_UPDATE, diff, userCred)
logclient.AddActionLogWithContext(ctx, item, logclient.ACT_UPDATE, diff, userCred, true)
CallUpdateNotifyHook(ctx, userCred, item)
}
item.PostUpdate(ctx, userCred, query, data)

View File

@@ -692,6 +692,17 @@ func IsMetadataKeySystemAdmin(key string) bool {
return strings.HasPrefix(key, SYSTEM_ADMIN_PREFIX)
}
func IsMetadataKeyPrivateKey(key string) bool {
for _, k := range []string{"admin", "project"} {
for _, v := range []string{"ssh-private-key", "ssh-public-key"} {
if key == fmt.Sprintf("%s-%s", k, v) {
return true
}
}
}
return strings.HasPrefix(key, SYSTEM_ADMIN_PREFIX)
}
func IsMetadataKeySysTag(key string) bool {
return strings.HasPrefix(key, SYS_TAG_PREFIX)
}
@@ -701,7 +712,7 @@ func (manager *SMetadataManager) GetSysadminKey(key string) string {
}
func IsMetadataKeyVisiable(key string) bool {
return !(IsMetadataKeySysTag(key) || IsMetadataKeySystemAdmin(key))
return !(IsMetadataKeySysTag(key) || IsMetadataKeySystemAdmin(key) || IsMetadataKeyPrivateKey(key))
}
func GetVisiableMetadata(ctx context.Context, model IStandaloneModel, userCred mcclient.TokenCredential) (map[string]string, error) {

View File

@@ -0,0 +1,41 @@
// 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 db
import (
"context"
"yunion.io/x/onecloud/pkg/mcclient"
)
var (
updateNotifyHook updateNotifyHookFunc
)
type updateNotifyHookFunc func(ctx context.Context, userCred mcclient.TokenCredential, obj IModel)
func SetUpdateNotifyHook(f updateNotifyHookFunc) {
if updateNotifyHook != nil {
panic("updateNotifyHook already set")
}
updateNotifyHook = f
}
func CallUpdateNotifyHook(ctx context.Context, userCred mcclient.TokenCredential, obj IModel) {
if updateNotifyHook == nil {
return
}
updateNotifyHook(ctx, userCred, obj)
}

View File

@@ -608,6 +608,8 @@ func (model *SVirtualResourceBase) GetShortDesc(ctx context.Context) *jsonutils.
tc, _ := TenantCacheManager.FetchTenantById(ctx, model.ProjectId)
if tc != nil {
desc.Add(jsonutils.NewString(tc.GetName()), "owner_tenant")
metadata, _ := GetVisiableMetadata(ctx, tc, nil)
desc.Set("project_tags", jsonutils.Marshal(metadata))
}
return desc
}

View File

@@ -17,6 +17,7 @@ package notifyclient
import (
"context"
"fmt"
"sync"
"time"
"yunion.io/x/jsonutils"
@@ -36,10 +37,30 @@ var (
notifyAdminUsers []string
notifyAdminGroups []string
notifyDBHookResources sync.Map
)
func init() {
notifyClientWorkerMan = appsrv.NewWorkerManager("NotifyClientWorkerManager", 1, 50, false)
// set db notify hook
db.SetUpdateNotifyHook(func(ctx context.Context, userCred mcclient.TokenCredential, obj db.IModel) {
_, ok := notifyDBHookResources.Load(obj.KeywordPlural())
if !ok {
return
}
EventNotify(ctx, userCred, SEventNotifyParam{
Obj: obj,
Action: ActionUpdate,
})
})
}
func AddNotifyDBHookResources(keywordPlurals ...string) {
for _, kp := range keywordPlurals {
notifyDBHookResources.Store(kp, true)
}
}
func NotifyWithCtx(ctx context.Context, recipientId []string, isGroup bool, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) {

View File

@@ -53,9 +53,6 @@ func OnBaseOptionsChange(oOpts, nOpts interface{}) bool {
if oldOpts.ApiServer != newOpts.ApiServer {
log.Debugf("api_server changed from %s to %s", oldOpts.ApiServer, newOpts.ApiServer)
}
if oldOpts.EnableTlsMigration != newOpts.EnableTlsMigration {
log.Debugf("enable_tls_migration changed from %v to %v", oldOpts.EnableTlsMigration, newOpts.EnableTlsMigration)
}
return changed
}

View File

@@ -21,7 +21,9 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/util/reflectutils"
identity_api "yunion.io/x/onecloud/pkg/apis/identity"
"yunion.io/x/onecloud/pkg/appsrv"
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
"yunion.io/x/onecloud/pkg/cloudcommon/syncman/watcher"
@@ -78,7 +80,13 @@ func StartOptionManagerWithSessionDriver(options interface{}, refreshSeconds int
OptionManager.FirstSync()
if session.IsRemote() {
OptionManager.StartWatching(&identity.ServicesV3)
var opts *CommonOptions
err := reflectutils.FindAnonymouStructPointer(options, &opts)
if err != nil {
log.Errorf("cannot find CommonOptions in options")
} else if opts.SessionEndpointType == identity_api.EndpointInterfaceInternal {
OptionManager.StartWatching(&identity.ServicesV3)
}
}
}

View File

@@ -110,8 +110,6 @@ type BaseOptions struct {
PlatformName string `help:"identity name of this platform" default:"Cloudpods"`
PlatformNames map[string]string `help:"identity name of this platform by language"`
EnableTlsMigration bool `help:"Enable TLS migration" default:"false"`
}
const (

View File

@@ -828,6 +828,10 @@ func NewIPv4AddrValidator(key string) *ValidatorIPv4Addr {
}
var ValidateModel = func(userCred mcclient.TokenCredential, manager db.IStandaloneModelManager, id *string) (db.IModel, error) {
if len(*id) == 0 {
return nil, httperrors.NewMissingParameterError(manager.Keyword())
}
model, err := manager.FetchByIdOrName(userCred, *id)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {

View File

@@ -1874,18 +1874,29 @@ func (self *SCloudaccount) SyncCloudroles(ctx context.Context, userCred mcclient
return result
}
func (self *SCloudaccount) GetUserCloudgroups(userId string) ([]string, error) {
func (self *SCloudaccount) GetUserCloudgroups(userCred mcclient.TokenCredential) ([]string, error) {
ret := []string{}
q := CloudgroupManager.Query()
samlusers := SamluserManager.Query("cloudgroup_id").Equals("owner_id", userId).Equals("cloudaccount_id", self.Id).SubQuery()
q = q.In("id", samlusers)
q := SamluserManager.Query().Equals("owner_id", userCred.GetUserId()).Equals("cloudaccount_id", self.Id)
users := []SSamluser{}
err := db.FetchModelObjects(SamluserManager, q, &users)
if err != nil {
return nil, errors.Wrapf(err, "db.FetchModelObjects")
}
if len(users) == 0 {
return nil, fmt.Errorf("no available saml user for %s %s", userCred.GetUserName(), userCred.GetUserId())
}
groupIds := []string{}
for i := range users {
groupIds = append(groupIds, users[i].CloudgroupId)
}
q = CloudgroupManager.Query().In("id", groupIds)
groups := []SCloudgroup{}
err := db.FetchModelObjects(CloudgroupManager, q, &groups)
err = db.FetchModelObjects(CloudgroupManager, q, &groups)
if err != nil {
return nil, errors.Wrapf(err, "db.FetchModelObjects")
}
if len(groups) == 0 {
return ret, nil
return ret, fmt.Errorf("no available cloudgroup for %s %s", userCred.GetUserName(), userCred.GetUserId())
}
for i := range groups {
cache, err := CloudgroupcacheManager.Register(&groups[i], self)

View File

@@ -1512,3 +1512,48 @@ func (self *SClouduser) SyncCustomCloudpoliciesForCloud(ctx context.Context, use
return account.SyncCustomCloudpoliciesForCloud(ctx, userCred, self)
}
func (self *SClouduser) PerformCreateAccessKey(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ClouduserCreateAccessKeyInput) (jsonutils.JSONObject, error) {
user, err := self.GetIClouduser()
if err != nil {
return nil, errors.Wrapf(err, "GetIClouduser error")
}
ak, err := user.CreateAccessKey(input.Name)
if err != nil {
return nil, errors.Wrapf(err, "GetDetailsAccessKeys error")
}
return jsonutils.Marshal(ak), nil
}
func (self *SClouduser) GetDetailsAccessKeys(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
user, err := self.GetIClouduser()
if err != nil {
return nil, errors.Wrapf(err, "GetIClouduser")
}
aks, err := user.GetAccessKeys()
if err != nil {
return nil, errors.Wrapf(err, "GetAccessKeys")
}
ret := struct {
Data []cloudprovider.SAccessKey
Total int
Limit int
}{
Data: aks,
Total: len(aks),
Limit: 20,
}
return jsonutils.Marshal(ret), nil
}
func (self *SClouduser) PerformDeleteAccessKey(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ClouduserDeleteAccessKeyInput) (jsonutils.JSONObject, error) {
user, err := self.GetIClouduser()
if err != nil {
return nil, errors.Wrapf(err, "GetIClouduser")
}
err = user.DeleteAccessKey(input.AccessKey)
if err != nil {
return nil, errors.Wrapf(err, "DeleteAccessKey")
}
return nil, nil
}

View File

@@ -68,13 +68,10 @@ func (d *SHuaweiSAMLDriver) GetIdpInitiatedLoginData(ctx context.Context, userCr
if len(idpId) == 0 {
return data, httperrors.NewInputParameterError("saml auth url %s missing idp", uri)
}
groups, err := account.GetUserCloudgroups(userCred.GetUserId())
groups, err := account.GetUserCloudgroups(userCred)
if err != nil {
return data, httperrors.NewGeneralError(errors.Wrapf(err, "GetUserCloudgroups"))
}
if len(groups) == 0 {
return data, httperrors.NewResourceNotFoundError("no available group found")
}
data.NameId = userCred.GetUserName()
data.NameIdFormat = samlutils.NAME_ID_FORMAT_TRANSIENT
@@ -129,13 +126,10 @@ func (d *SHuaweiSAMLDriver) GetSpInitiatedLoginData(ctx context.Context, userCre
return data, httperrors.NewResourceNotReadyError("SAMLProvider for account %s not ready", account.Id)
}
groups, err := account.GetUserCloudgroups(userCred.GetUserId())
groups, err := account.GetUserCloudgroups(userCred)
if err != nil {
return data, httperrors.NewGeneralError(errors.Wrapf(err, "GetUserCloudgroups"))
}
if len(groups) == 0 {
return data, httperrors.NewResourceNotFoundError("no available group found")
}
data.NameId = userCred.GetUserName()
data.NameIdFormat = samlutils.NAME_ID_FORMAT_TRANSIENT

View File

@@ -128,6 +128,10 @@ func (self *SBaseCollectDriver) CollectK8sMetrics(ctx context.Context, manager a
return cloudprovider.ErrNotImplemented
}
func (self *SBaseCollectDriver) CollectModelartsPoolMetrics(ctx context.Context, manager api.CloudproviderDetails, provider cloudprovider.ICloudProvider, res map[string]api.ModelartsPoolDetails, start, end time.Time) error {
return cloudprovider.ErrNotImplemented
}
type SCollectByResourceIdDriver struct {
SBaseCollectDriver
}
@@ -217,6 +221,7 @@ func (self *SCollectByResourceIdDriver) CollectServerMetrics(ctx context.Context
RegionExtId: vm.RegionExtId,
StartTime: start,
EndTime: end,
OsType: vm.OsType,
}
opts.ResourceId = vm.ExternalId

View File

@@ -39,6 +39,7 @@ type ICollectDriver interface {
CollectLoadbalancerMetrics(ctx context.Context, manager api.CloudproviderDetails, provider cloudprovider.ICloudProvider, res map[string]api.LoadbalancerDetails, start, end time.Time) error
CollectBucketMetrics(ctx context.Context, manager api.CloudproviderDetails, provider cloudprovider.ICloudProvider, res map[string]api.BucketDetails, start, end time.Time) error
CollectK8sMetrics(ctx context.Context, manager api.CloudproviderDetails, provider cloudprovider.ICloudProvider, res map[string]api.KubeClusterDetails, start, end time.Time) error
CollectModelartsPoolMetrics(ctx context.Context, manager api.CloudproviderDetails, provider cloudprovider.ICloudProvider, res map[string]api.ModelartsPoolDetails, start, end time.Time) error
}
func GetDriver(name string) (ICollectDriver, error) {

View File

@@ -15,7 +15,20 @@
package providerdriver
import (
"context"
"strconv"
"sync"
"time"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/onecloud/pkg/apis"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudmon/options"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/util/influxdb"
)
type HuaweiCollect struct {
@@ -33,3 +46,72 @@ func (self *HuaweiCollect) IsSupportMetrics() bool {
func init() {
Register(&HuaweiCollect{})
}
func (self *HuaweiCollect) CollectModelartsPoolMetrics(ctx context.Context, manager api.CloudproviderDetails, provider cloudprovider.ICloudProvider, res map[string]api.ModelartsPoolDetails, start, end time.Time) error {
metrics := []influxdb.SMetricData{}
var wg sync.WaitGroup
var mu sync.Mutex
for i := range res {
wg.Add(1)
go func(pool api.ModelartsPoolDetails) {
defer func() {
wg.Done()
}()
opts := &cloudprovider.MetricListOptions{
ResourceType: cloudprovider.METRIC_RESOURCE_TYPE_MODELARTS_POOL,
StartTime: start,
EndTime: end,
}
opts.ResourceId = pool.ExternalId
tags := []influxdb.SKeyValue{}
for k, v := range pool.GetMetricTags() {
tags = append(tags, influxdb.SKeyValue{
Key: k,
Value: v,
})
}
data, err := provider.GetMetrics(opts)
if err != nil {
if errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
log.Errorf("get modelarts_pool %s(%s) error: %v", pool.Name, pool.Id, err)
return
}
return
}
for _, values := range data {
for _, value := range values.Values {
metric := influxdb.SMetricData{
Name: values.MetricType.Name(),
Timestamp: value.Timestamp,
Tags: tags,
Metrics: []influxdb.SKeyValue{
{
Key: values.MetricType.Key(),
Value: strconv.FormatFloat(value.Value, 'E', -1, 64),
},
},
}
for k, v := range value.Tags {
metric.Tags = append(metric.Tags, influxdb.SKeyValue{
Key: k,
Value: v,
})
}
mu.Lock()
metrics = append(metrics, metric)
mu.Unlock()
}
}
}(res[i])
}
wg.Wait()
s := auth.GetAdminSession(ctx, options.Options.Region)
urls, err := s.GetServiceURLs(apis.SERVICE_TYPE_INFLUXDB, options.Options.SessionEndpointType, "")
if err != nil {
return errors.Wrap(err, "GetServiceURLs")
}
log.Infof("send %d modelarts_pool with %d metrics for %s(%s)", len(res), len(metrics), manager.Name, manager.Id)
return influxdb.BatchSendMetrics(urls, options.Options.InfluxDatabase, metrics, false)
}

View File

@@ -15,7 +15,20 @@
package providerdriver
import (
"context"
"strconv"
"sync"
"time"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/onecloud/pkg/apis"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudmon/options"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/util/influxdb"
)
type HuaweiStackCollect struct {
@@ -29,3 +42,76 @@ func (self *HuaweiStackCollect) GetProvider() string {
func init() {
Register(&HuaweiStackCollect{})
}
func (self *HuaweiStackCollect) IsSupportMetrics() bool {
return true
}
func (self *HuaweiStackCollect) CollectModelartsPoolMetrics(ctx context.Context, manager api.CloudproviderDetails, provider cloudprovider.ICloudProvider, res map[string]api.ModelartsPoolDetails, start, end time.Time) error {
metrics := []influxdb.SMetricData{}
var wg sync.WaitGroup
var mu sync.Mutex
for i := range res {
wg.Add(1)
go func(pool api.ModelartsPoolDetails) {
defer func() {
wg.Done()
}()
opts := &cloudprovider.MetricListOptions{
ResourceType: cloudprovider.METRIC_RESOURCE_TYPE_MODELARTS_POOL,
StartTime: start,
EndTime: end,
}
opts.ResourceId = pool.ExternalId
tags := []influxdb.SKeyValue{}
for k, v := range pool.GetMetricTags() {
tags = append(tags, influxdb.SKeyValue{
Key: k,
Value: v,
})
}
data, err := provider.GetMetrics(opts)
if err != nil {
if errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
log.Errorf("get modelarts_pool %s(%s) error: %v", pool.Name, pool.Id, err)
return
}
return
}
for _, values := range data {
for _, value := range values.Values {
metric := influxdb.SMetricData{
Name: values.MetricType.Name(),
Timestamp: value.Timestamp,
Tags: tags,
Metrics: []influxdb.SKeyValue{
{
Key: values.MetricType.Key(),
Value: strconv.FormatFloat(value.Value, 'E', -1, 64),
},
},
}
for k, v := range value.Tags {
metric.Tags = append(metric.Tags, influxdb.SKeyValue{
Key: k,
Value: v,
})
}
mu.Lock()
metrics = append(metrics, metric)
mu.Unlock()
}
}
}(res[i])
}
wg.Wait()
s := auth.GetAdminSession(ctx, options.Options.Region)
urls, err := s.GetServiceURLs(apis.SERVICE_TYPE_INFLUXDB, options.Options.SessionEndpointType, "")
if err != nil {
return errors.Wrap(err, "GetServiceURLs")
}
log.Infof("send %d modelarts_pool with %d metrics for %s(%s)", len(res), len(metrics), manager.Name, manager.Id)
return influxdb.BatchSendMetrics(urls, options.Options.InfluxDatabase, metrics, false)
}

View File

@@ -106,7 +106,8 @@ func (self *SBaseResources) init() error {
ImportedAt time.Time
}{}
resp.Data[i].Unmarshal(&baseInfo)
if len(baseInfo.ExternalId) == 0 && self.manager.GetKeyword() != compute.Cloudproviders.GetKeyword() {
if len(baseInfo.ExternalId) == 0 && (self.manager.GetKeyword() != compute.Cloudproviders.GetKeyword() &&
self.manager.GetKeyword() != compute.Cloudaccounts.GetKeyword()) {
continue
}
key := baseInfo.ExternalId
@@ -175,7 +176,8 @@ func (self *SBaseResources) increment() error {
for i := range ret {
baseInfo := sBaseInfo{}
ret[i].Unmarshal(&baseInfo)
if len(baseInfo.ExternalId) == 0 && self.manager.GetKeyword() != compute.Cloudproviders.GetKeyword() {
if len(baseInfo.ExternalId) == 0 && (self.manager.GetKeyword() != compute.Cloudproviders.GetKeyword() &&
self.manager.GetKeyword() != compute.Cloudaccounts.GetKeyword()) {
continue
}
key := baseInfo.ExternalId
@@ -342,6 +344,7 @@ type SResources struct {
Buckets TResource
KubeClusters TResource
Storages TResource
ModelartsPool TResource
}
func NewResources() *SResources {
@@ -356,6 +359,7 @@ func NewResources() *SResources {
Loadbalancers: NewBaseResources(&compute.Loadbalancers),
Buckets: NewBaseResources(&compute.Buckets),
KubeClusters: NewBaseResources(&compute.KubeClusters),
ModelartsPool: NewBaseResources(&compute.ModelartsPools),
}
}
@@ -403,6 +407,10 @@ func (self *SResources) Init(ctx context.Context, userCred mcclient.TokenCredent
if err != nil {
errs = append(errs, errors.Wrapf(err, "KubeClusters.init"))
}
err = self.ModelartsPool.init()
if err != nil {
errs = append(errs, errors.Wrapf(err, "ModelartsPool.init"))
}
return errors.NewAggregate(errs)
}()
if err != nil {
@@ -455,7 +463,11 @@ func (self *SResources) IncrementSync(ctx context.Context, userCred mcclient.Tok
}
err = self.KubeClusters.increment()
if err != nil {
errs = append(errs, errors.Wrapf(err, "Buckets.increment"))
errs = append(errs, errors.Wrapf(err, "KubeClusters.increment"))
}
err = self.ModelartsPool.increment()
if err != nil {
errs = append(errs, errors.Wrapf(err, "ModelartsPool.increment"))
}
return errors.NewAggregate(errs)
}()
@@ -510,6 +522,10 @@ func (self *SResources) DecrementSync(ctx context.Context, userCred mcclient.Tok
if err != nil {
errs = append(errs, errors.Wrapf(err, "KubeClusters.decrement"))
}
err = self.ModelartsPool.decrement()
if err != nil {
errs = append(errs, errors.Wrapf(err, "ModelartsPool.decrement"))
}
return errors.NewAggregate(errs)
}()
if err != nil {
@@ -551,6 +567,10 @@ func (self *SResources) UpdateSync(ctx context.Context, userCred mcclient.TokenC
if err != nil {
errs = append(errs, errors.Wrapf(err, "Loadbalancers.update"))
}
err = self.ModelartsPool.update()
if err != nil {
errs = append(errs, errors.Wrapf(err, "ModelartsPool.update"))
}
return errors.NewAggregate(errs)
}()
if err != nil {
@@ -604,7 +624,10 @@ func (self *SResources) CollectMetrics(ctx context.Context, userCred mcclient.To
resources = self.DBInstances.getResources(manager.Id)
dbinstances := map[string]api.DBInstanceDetails{}
jsonutils.Update(&dbinstances, resources)
err = jsonutils.Update(&dbinstances, resources)
if err != nil {
log.Errorf("unmarsha rds resources error: %v", err)
}
err = driver.CollectDBInstanceMetrics(ctx, manager, provider, dbinstances, startTime, endTime)
if err != nil && errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
log.Errorf("CollectDBInstanceMetrics for %s(%s) error: %v", manager.Name, manager.Provider, err)
@@ -612,7 +635,10 @@ func (self *SResources) CollectMetrics(ctx context.Context, userCred mcclient.To
resources = self.Servers.getResources(manager.Id)
servers := map[string]api.ServerDetails{}
jsonutils.Update(&servers, resources)
err = jsonutils.Update(&servers, resources)
if err != nil {
log.Errorf("unmarsha server resources error: %v", err)
}
err = driver.CollectServerMetrics(ctx, manager, provider, servers, startTime, endTime)
if err != nil && errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
log.Errorf("CollectServerMetrics for %s(%s) error: %v", manager.Name, manager.Provider, err)
@@ -620,7 +646,11 @@ func (self *SResources) CollectMetrics(ctx context.Context, userCred mcclient.To
resources = self.Hosts.getResources(manager.Id)
hosts := map[string]api.HostDetails{}
jsonutils.Update(&hosts, resources)
err = jsonutils.Update(&hosts, resources)
if err != nil {
log.Errorf("unmarsha host resources error: %v", err)
}
err = driver.CollectHostMetrics(ctx, manager, provider, hosts, startTime, endTime)
if err != nil && errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
log.Errorf("CollectHostMetrics for %s(%s) error: %v", manager.Name, manager.Provider, err)
@@ -628,7 +658,10 @@ func (self *SResources) CollectMetrics(ctx context.Context, userCred mcclient.To
resources = self.Storages.getResources(manager.Id)
storages := map[string]api.StorageDetails{}
jsonutils.Update(&storages, resources)
err = jsonutils.Update(&storages, resources)
if err != nil {
log.Errorf("unmarsha storage resources error: %v", err)
}
err = driver.CollectStorageMetrics(ctx, manager, provider, storages, startTime, endTime)
if err != nil && errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
log.Errorf("CollectStorageMetrics for %s(%s) error: %v", manager.Name, manager.Provider, err)
@@ -636,7 +669,11 @@ func (self *SResources) CollectMetrics(ctx context.Context, userCred mcclient.To
resources = self.Redis.getResources(manager.Id)
caches := map[string]api.ElasticcacheDetails{}
jsonutils.Update(&caches, resources)
err = jsonutils.Update(&caches, resources)
if err != nil {
log.Errorf("unmarsha redis resources error: %v", err)
}
err = driver.CollectRedisMetrics(ctx, manager, provider, caches, startTime, endTime)
if err != nil && errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
log.Errorf("CollectRedisMetrics for %s(%s) error: %v", manager.Name, manager.Provider, err)
@@ -644,7 +681,11 @@ func (self *SResources) CollectMetrics(ctx context.Context, userCred mcclient.To
resources = self.Loadbalancers.getResources(manager.Id)
lbs := map[string]api.LoadbalancerDetails{}
jsonutils.Update(&lbs, resources)
err = jsonutils.Update(&lbs, resources)
if err != nil {
log.Errorf("unmarsha lb resources error: %v", err)
}
err = driver.CollectLoadbalancerMetrics(ctx, manager, provider, lbs, startTime, endTime)
if err != nil && errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
log.Errorf("CollectLoadbalancerMetrics for %s(%s) error: %v", manager.Name, manager.Provider, err)
@@ -652,7 +693,11 @@ func (self *SResources) CollectMetrics(ctx context.Context, userCred mcclient.To
resources = self.Buckets.getResources(manager.Id)
buckets := map[string]api.BucketDetails{}
jsonutils.Update(&buckets, resources)
err = jsonutils.Update(&buckets, resources)
if err != nil {
log.Errorf("unmarsha bucket resources error: %v", err)
}
err = driver.CollectBucketMetrics(ctx, manager, provider, buckets, startTime, endTime)
if err != nil && errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
log.Errorf("CollectBucketMetrics for %s(%s) error: %v", manager.Name, manager.Provider, err)
@@ -660,11 +705,27 @@ func (self *SResources) CollectMetrics(ctx context.Context, userCred mcclient.To
resources = self.KubeClusters.getResources(manager.Id)
clusters := map[string]api.KubeClusterDetails{}
jsonutils.Update(&clusters, resources)
err = jsonutils.Update(&clusters, resources)
if err != nil {
log.Errorf("unmarsha k8s resources error: %v", err)
}
err = driver.CollectK8sMetrics(ctx, manager, provider, clusters, startTime, endTime)
if err != nil && errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
log.Errorf("CollectK8sMetrics for %s(%s) error: %v", manager.Name, manager.Provider, err)
}
resources = self.ModelartsPool.getResources(manager.Id)
pools := map[string]api.ModelartsPoolDetails{}
err = jsonutils.Update(&pools, resources)
if err != nil {
log.Errorf("unmarsha modelarts resources error: %v", err)
}
err = driver.CollectModelartsPoolMetrics(ctx, manager, provider, pools, startTime, endTime)
if err != nil && errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
log.Errorf("CollectModelartsPoolMetrics for %s(%s) error: %v", manager.Name, manager.Provider, err)
}
}(cloudproviders[i])
}
wg.Wait()

View File

@@ -398,6 +398,10 @@ func IsSupportTablestore(prod ICloudProvider) bool {
return IsSupportCapability(prod, CLOUD_CAPABILITY_TABLESTORE)
}
func IsSupportModelartsPool(prod ICloudProvider) bool {
return IsSupportCapability(prod, CLOUD_CAPABILITY_MODELARTES)
}
var providerTable map[string]ICloudProviderFactory
func init() {
@@ -620,6 +624,22 @@ func (self *SBaseProvider) GetMetrics(opts *MetricListOptions) ([]MetricValues,
return nil, errors.Wrapf(ErrNotImplemented, "GetMetric")
}
func (self *SBaseProvider) GetIModelartsPools() ([]ICloudModelartsPool, error) {
return nil, errors.Wrapf(ErrNotImplemented, "GetIModelartsPools")
}
func (self *SBaseProvider) GetIModelartsPoolById(id string) (ICloudModelartsPool, error) {
return nil, errors.Wrapf(ErrNotImplemented, "GetIModelartsPoolDetail")
}
func (self *SBaseProvider) CreateIModelartsPool(pool *ModelartsPoolCreateOption) (ICloudModelartsPool, error) {
return nil, errors.Wrapf(ErrNotImplemented, "CreateIModelartsPool")
}
func (self *SBaseProvider) GetIModelartsPoolSku() ([]ICloudModelartsPoolSku, error) {
return nil, errors.Wrapf(ErrNotImplemented, "GetIModelartsPoolSku")
}
func NewBaseProvider(factory ICloudProviderFactory) SBaseProvider {
return SBaseProvider{factory: factory}
}
@@ -910,3 +930,29 @@ func (factory *SPrivateCloudBaseProviderFactory) IsSupportPrepaidResources() boo
func (factory *SPrivateCloudBaseProviderFactory) NeedSyncSkuFromCloud() bool {
return true
}
type ICloudModelartsPool interface {
ICloudResource
IBillingResource
Delete() error
GetProjectId() string
GetInstanceType() string
GetWorkType() string
GetNodeCount() int
ChangeConfig(opts *ModelartsPoolChangeConfigOptions) error
}
type ICloudModelartsPoolSku interface {
ICloudResource
GetCpuCoreCount() int
GetCpuArch() string
GetStatus() string
GetMemorySizeMB() int
GetPoolType() string
GetGpuSize() int
GetGpuType() string
GetNpuSize() int
GetNpuType() string
}

View File

@@ -14,7 +14,11 @@
package cloudprovider
import "yunion.io/x/jsonutils"
import (
"time"
"yunion.io/x/jsonutils"
)
type SClouduserCreateConfig struct {
Name string
@@ -38,3 +42,11 @@ type SCloudpolicyCreateOptions struct {
Desc string
Document *jsonutils.JSONDict
}
type SAccessKey struct {
Name string
AccessKey string
Secret string
Status string
CreatedAt time.Time
}

View File

@@ -70,6 +70,7 @@ const (
CLOUD_CAPABILITY_CONTAINER = "container" // 容器
CLOUD_CAPABILITY_IPV6_GATEWAY = "ipv6_gateway" // IPv6网关
CLOUD_CAPABILITY_TABLESTORE = "tablestore" // 表格存储
CLOUD_CAPABILITY_MODELARTES = "modelarts"
)
const (

View File

@@ -81,6 +81,8 @@ type SHCSOEndpoints struct {
Eps string `default:"$HUAWEI_EPS_ENDPOINT"`
// 文件系统
SfsTurbo string `default:"$HUAWEI_SFS_TURBO_ENDPOINT"`
// Modelarts
Modelarts string `default:"$HUAWEI_MODELARTS_ENDPOINT"`
}
func (self *SHCSOEndpoints) GetEndpoint(defaultRegion, serviceName string, region string) string {

View File

@@ -15,6 +15,7 @@
package cloudprovider
import (
"fmt"
"time"
)
@@ -74,6 +75,10 @@ type SaveImageOptions struct {
}
func CloudImage2Image(image ICloudImage) SImage {
uefiSupport := false
if image.GetBios() == BIOS {
uefiSupport = true
}
return SImage{
CreatedAt: image.GetCreatedAt(),
Deleted: false,
@@ -84,10 +89,13 @@ func CloudImage2Image(image ICloudImage) SImage {
MinRamMB: image.GetMinRamSizeMb(),
Name: image.GetName(),
Properties: map[string]string{
"os_full_name": image.GetFullOsName(),
"os_type": string(image.GetOsType()),
"os_distribution": image.GetOsDist(),
"os_version": image.GetOsVersion(),
"os_arch": image.GetOsArch(),
"os_language": image.GetOsLang(),
"uefi_support": fmt.Sprintf("%v", uefiSupport),
},
Protected: true,
SizeBytes: image.GetSizeByte(),

View File

@@ -35,6 +35,22 @@ var (
OsTypeWindows = TOsType(osprofile.OS_TYPE_WINDOWS)
)
type TBiosType string
var (
BIOS = TBiosType("BIOS")
UEFI = TBiosType("UEFI")
)
func ToBiosType(bios string) TBiosType {
switch strings.ToLower(bios) {
case "uefi", "efi":
return UEFI
default:
return BIOS
}
}
type SDistDefaultAccount struct {
// 操作系统发行版
OsDistribution string

View File

@@ -44,15 +44,16 @@ func (key TMetricType) Key() string {
}
const (
METRIC_RESOURCE_TYPE_RDS TResourceType = "rds"
METRIC_RESOURCE_TYPE_SERVER TResourceType = "server"
METRIC_RESOURCE_TYPE_HOST TResourceType = "host"
METRIC_RESOURCE_TYPE_REDIS TResourceType = "redis"
METRIC_RESOURCE_TYPE_LB TResourceType = "lb"
METRIC_RESOURCE_TYPE_BUCKET TResourceType = "bucket"
METRIC_RESOURCE_TYPE_K8S TResourceType = "k8s"
METRIC_RESOURCE_TYPE_STORAGE TResourceType = "storage"
METRIC_RESOURCE_TYPE_CLOUD_ACCOUNT TResourceType = "cloudaccount_balance"
METRIC_RESOURCE_TYPE_RDS TResourceType = "rds"
METRIC_RESOURCE_TYPE_SERVER TResourceType = "server"
METRIC_RESOURCE_TYPE_HOST TResourceType = "host"
METRIC_RESOURCE_TYPE_REDIS TResourceType = "redis"
METRIC_RESOURCE_TYPE_LB TResourceType = "lb"
METRIC_RESOURCE_TYPE_BUCKET TResourceType = "bucket"
METRIC_RESOURCE_TYPE_K8S TResourceType = "k8s"
METRIC_RESOURCE_TYPE_STORAGE TResourceType = "storage"
METRIC_RESOURCE_TYPE_CLOUD_ACCOUNT TResourceType = "cloudaccount_balance"
METRIC_RESOURCE_TYPE_MODELARTS_POOL TResourceType = "modelarts"
)
const (
@@ -252,6 +253,19 @@ const (
K8S_NODE_METRIC_TYPE_DISK_USAGE TMetricType = "k8s_node_disk.used_percent"
K8S_NODE_METRIC_TYPE_NET_BPS_RX TMetricType = "k8s_node_netio.bps_recv"
K8S_NODE_METRIC_TYPE_NET_BPS_TX TMetricType = "k8s_node_netio.bps_sent"
// modelarts专属资源池监控数据
MODELARTS_POOL_METRIC_TYPE_CPU_USAGE TMetricType = "modelarts_pool_cpu.usage_percent"
MODELARTS_POOL_METRIC_TYPE_MEM_USAGE TMetricType = "modelarts_pool_mem.usage_percent"
MODELARTS_POOL_METRIC_TYPE_GPU_MEM_USAGE TMetricType = "modelarts_pool_gpu_mem.usage_percent"
MODELARTS_POOL_METRIC_TYPE_GPU_UTIL TMetricType = "modelarts_pool_gpu_util.percent"
MODELARTS_POOL_METRIC_TYPE_NPU_UTIL TMetricType = "modelarts_pool_npu_util.percent"
MODELARTS_POOL_METRIC_TYPE_NPU_MEM_USAGE TMetricType = "modelarts_pool_npu_mem.usage_percent"
//磁盘可用容量
MODELARTS_POOL_METRIC_TYPE_DISK_AVAILABLE_CAPACITY TMetricType = "modelarts_pool_disk.available_capacity"
MODELARTS_POOL_METRIC_TYPE_DISK_CAPACITY TMetricType = "modelarts_pool_disk.capacity"
MODELARTS_POOL_METRIC_TYPE_DISK_USAGE TMetricType = "modelarts_pool_disk.usage_percent"
)
var (
@@ -344,6 +358,7 @@ type MetricListOptions struct {
StartTime time.Time
EndTime time.Time
OsType string
Interval int
// rds
Engine string

View File

@@ -0,0 +1,37 @@
// 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 cloudprovider
type ModelartsPoolCreateOption struct {
Name string
PoolDesc string
BillingMode uint
PeriodType uint
PeriodNum uint
AutoRenew uint
InstanceType string
NodeCount int
NetworkId string
WorkType string
}
type Azs struct {
Az string `json:"az"`
Count int `json:"count"`
}
type ModelartsPoolChangeConfigOptions struct {
NodeCount int
}

View File

@@ -12,4 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package tasks // import "yunion.io/x/onecloud/pkg/monitor/tasks"
package cloudprovider
type IOSInfo interface {
GetFullOsName() string
GetOsType() TOsType
GetOsDist() string
GetOsVersion() string
GetOsArch() string
GetOsLang() string
GetBios() TBiosType
}
func IsUEFI(ios IOSInfo) bool {
return ios.GetBios() == UEFI
}

View File

@@ -194,6 +194,11 @@ type ICloudRegion interface {
GetICloudKubeClusterById(id string) (ICloudKubeCluster, error)
GetICloudTablestores() ([]ICloudTablestore, error)
GetIModelartsPools() ([]ICloudModelartsPool, error)
GetIModelartsPoolById(id string) (ICloudModelartsPool, error)
CreateIModelartsPool(pool *ModelartsPoolCreateOption) (ICloudModelartsPool, error)
GetIModelartsPoolSku() ([]ICloudModelartsPoolSku, error)
}
type ICloudZone interface {
@@ -212,20 +217,19 @@ type ICloudZone interface {
type ICloudImage interface {
IVirtualResource
IOSInfo
Delete(ctx context.Context) error
GetIStoragecache() ICloudStoragecache
GetSizeByte() int64
GetImageType() TImageType
GetImageStatus() string
GetOsType() TOsType
GetOsDist() string
GetOsVersion() string
GetOsArch() string
GetMinOsDiskSizeGb() int
GetMinRamSizeMb() int
GetImageFormat() string
UEFI() bool
GetPublicScope() rbacutils.TRbacScope
GetSubImages() []SSubImage
}
@@ -296,6 +300,8 @@ type ICloudHost interface {
GetCpuDesc() string
GetCpuMhz() int
GetCpuCmtbound() float32
GetCpuArchitecture() string
GetMemSizeMB() int
GetMemCmtbound() float32
GetReservedMemoryMb() int
@@ -318,6 +324,8 @@ type ICloudVM interface {
IBillingResource
IVirtualResource
IOSInfo
ConvertPublicIpToEip() error
GetHostname() string
@@ -341,10 +349,12 @@ type ICloudVM interface {
GetBootOrder() string
GetVga() string
GetVdi() string
GetOSArch() string
GetOsType() TOsType
GetOSName() string
GetBios() string
// GetOSArch() string
// GetOsType() TOsType
// GetOSName() string
// GetBios() string
GetMachine() string
GetInstanceType() string
@@ -1188,6 +1198,10 @@ type IClouduser interface {
ResetPassword(password string) error
IsConsoleLogin() bool
CreateAccessKey(name string) (*SAccessKey, error)
DeleteAccessKey(accessKey string) error
GetAccessKeys() ([]SAccessKey, error)
}
// 公有云子账号权限

View File

@@ -500,6 +500,18 @@ func (self *SBaremetalGuestDriver) OnGuestDeployTaskDataReceived(ctx context.Con
return nil
}
func (self *SBaremetalGuestDriver) IsDisableImageCache(gst *models.SGuest) (bool, error) {
host, err := gst.GetHost()
if err != nil {
return false, errors.Wrapf(err, "Get guest %s(%s) host", gst.GetName(), gst.GetId())
}
agent := host.GetAgent(api.AgentTypeBaremetal)
if agent == nil {
return false, errors.Wrapf(errors.ErrNotFound, "get host %s(%s) agent", host.GetName(), host.GetId())
}
return agent.DisableImageCache, nil
}
func (self *SBaremetalGuestDriver) RequestDeployGuestOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error {
config, err := guest.GetDeployConfigOnHost(ctx, task.GetUserCred(), host, task.GetParams())
if err != nil {
@@ -515,6 +527,13 @@ func (self *SBaremetalGuestDriver) RequestDeployGuestOnHost(ctx context.Context,
} else if val == "deploy" && jsonutils.QueryBoolean(task.GetParams(), "restart", false) {
config.Set("on_finish", jsonutils.NewString("shutdown"))
}
disableCache, err := self.IsDisableImageCache(guest)
if err != nil {
return errors.Wrap(err, "check IsDisableImageCache")
}
config.Set("disable_image_cache", jsonutils.NewBool(disableCache))
url := fmt.Sprintf("/baremetals/%s/servers/%s/%s", host.Id, guest.Id, val)
headers := task.GetTaskRequestHeader()
_, err = host.BaremetalSyncRequest(ctx, "POST", url, headers, config)

View File

@@ -418,7 +418,7 @@ func (self *SESXiGuestDriver) RequestDeployGuestOnHost(ctx context.Context, gues
return errors.Wrapf(err, "GetExternalProjectsByProjectIdOrName(%s,%s)", project.Id, project.Name)
}
extProj := account.GetAvailableExternalProject(project, projects)
extProj := models.GetAvailableExternalProject(project, projects)
if extProj != nil {
config.Add(jsonutils.NewString(extProj.Name), "desc", "resource_pool")
} else {

View File

@@ -425,7 +425,10 @@ func (self *SKVMGuestDriver) RequestChangeVmConfig(ctx context.Context, guest *m
}
func (self *SKVMGuestDriver) RequestSoftReset(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
_, err := guest.SendMonitorCommand(ctx, task.GetUserCred(), "system_reset")
_, err := guest.SendMonitorCommand(
ctx, task.GetUserCred(),
&api.ServerMonitorInput{COMMAND: "system_reset"},
)
return err
}
@@ -773,6 +776,9 @@ func (self *SKVMGuestDriver) CheckLiveMigrate(ctx context.Context, guest *models
return httperrors.NewBadRequestError("Guest have backup, can't migrate")
}
if utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_SUSPEND}) {
if input.MaxBandwidthMb != nil && *input.MaxBandwidthMb < 50 {
return httperrors.NewBadRequestError("max bandwidth must gratethan 100M")
}
cdrom := guest.GetCdrom()
if cdrom != nil && len(cdrom.ImageId) > 0 {
return httperrors.NewBadRequestError("Cannot live migrate with cdrom")

View File

@@ -1071,6 +1071,12 @@ func (self *SManagedVirtualizedGuestDriver) OnGuestDeployTaskDataReceived(ctx co
}
guest.SaveDeployInfo(ctx, task.GetUserCred(), data)
iVM, err := guest.GetIVM(ctx)
if err != nil {
return errors.Wrap(err, "guest.GetIVM")
}
guest.SyncOsInfo(ctx, task.GetUserCred(), iVM)
return nil
}
@@ -1318,6 +1324,7 @@ func (self *SManagedVirtualizedGuestDriver) RequestRemoteUpdate(ctx context.Cont
logclient.AddSimpleActionLog(guest, logclient.ACT_UPDATE_TAGS, tagsUpdateInfo, userCred, true)
// sync back cloud metadata
iVM.Refresh()
guest.SyncOsInfo(ctx, userCred, iVM)
err = models.SyncVirtualResourceMetadata(ctx, userCred, guest, iVM)
if err != nil {
return errors.Wrap(err, "syncVirtualResourceMetadata")

View File

@@ -19,6 +19,7 @@ import (
"fmt"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
@@ -43,12 +44,31 @@ func (self *SBaremetalHostDriver) GetHypervisor() string {
return api.HYPERVISOR_BAREMETAL
}
func (self *SBaremetalHostDriver) IsDisableImageCache(host *models.SHost) (bool, error) {
agent := host.GetAgent(api.AgentTypeBaremetal)
if agent == nil {
return false, errors.Wrapf(errors.ErrNotFound, "get host %s(%s) agent", host.GetName(), host.GetId())
}
return agent.DisableImageCache, nil
}
func (self *SBaremetalHostDriver) CheckAndSetCacheImage(ctx context.Context, host *models.SHost, storageCache *models.SStoragecache, task taskman.ITask) error {
input := api.CacheImageInput{}
task.GetParams().Unmarshal(&input)
_, err := models.CachedimageManager.FetchById(input.ImageId)
if err != nil {
return err
return errors.Wrapf(err, "fetch cachedimage by image_id %s", input.ImageId)
}
disableCache, err := self.IsDisableImageCache(host)
if err != nil {
return errors.Wrapf(err, "check disable image cache by host %s(%s)", host.GetName(), host.GetId())
}
// iso must be cached to use
if disableCache && input.Format != "iso" {
task.ScheduleRun(nil)
return nil
}
url := "/disks/image_cache"

View File

@@ -97,6 +97,14 @@ func (self *SKVMHostDriver) ValidateAttachStorage(ctx context.Context, userCred
if !jsonutils.QueryBoolean(res, "is_mount_point", false) {
return input, httperrors.NewBadRequestError("%s is not mount point %s", input.MountPoint, res)
}
urlStr = fmt.Sprintf("%s/storages/is-local-mount-point?%s", host.ManagerUri, params.QueryString())
_, res, err = httputils.JSONRequest(httputils.GetDefaultClient(), ctx, "GET", urlStr, header, nil, false)
if err != nil {
return input, err
}
if jsonutils.QueryBoolean(res, "is_local_mount_point", false) {
return input, httperrors.NewBadRequestError("%s is local storage mount point", input.MountPoint)
}
}
}
return input, nil

View File

@@ -50,7 +50,8 @@ type SBaremetalagent struct {
Version string `width:"64" charset:"ascii" list:"admin" update:"admin" create:"admin_optional"` // Column(VARCHAR(64, charset='ascii'))
StoragecacheId string `width:"36" charset:"ascii" nullable:"true" list:"admin" get:"admin" update:"admin" create:"admin_optional"`
StoragecacheId string `width:"36" charset:"ascii" nullable:"true" list:"admin" get:"admin" update:"admin" create:"admin_optional"`
DisableImageCache bool `default:"false" list:"admin" create:"admin_optional" update:"admin"`
}
var BaremetalagentManager *SBaremetalagentManager
@@ -154,6 +155,26 @@ func (self *SBaremetalagent) PerformDisable(ctx context.Context, userCred mcclie
return nil, nil
}
func (self *SBaremetalagent) PerformEnableImageCache(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
if self.DisableImageCache {
db.Update(self, func() error {
self.DisableImageCache = false
return nil
})
}
return nil, nil
}
func (self *SBaremetalagent) PerformDisableImageCache(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
if !self.DisableImageCache {
db.Update(self, func() error {
self.DisableImageCache = true
return nil
})
}
return nil, nil
}
func (self *SBaremetalagent) PerformOnline(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
if self.Status == api.BAREMETAL_AGENT_OFFLINE {
db.Update(self, func() error {

View File

@@ -561,7 +561,7 @@ func (self *SCachedimage) syncWithCloudImage(ctx context.Context, userCred mccli
if image.GetPublicScope() == rbacutils.ScopeSystem {
self.IsPublic = true
}
self.UEFI = tristate.NewFromBool(image.UEFI())
self.UEFI = tristate.NewFromBool(cloudprovider.IsUEFI(image))
sImage := cloudprovider.CloudImage2Image(image)
self.Info = jsonutils.Marshal(&sImage)
self.LastSync = time.Now().UTC()
@@ -578,7 +578,7 @@ func (manager *SCachedimageManager) newFromCloudImage(ctx context.Context, userC
cachedImage.SetModelManager(manager, &cachedImage)
cachedImage.Size = image.GetSizeByte()
cachedImage.UEFI = tristate.NewFromBool(image.UEFI())
cachedImage.UEFI = tristate.NewFromBool(cloudprovider.IsUEFI(image))
sImage := cloudprovider.CloudImage2Image(image)
cachedImage.Info = jsonutils.Marshal(&sImage)
cachedImage.LastSync = time.Now().UTC()

View File

@@ -416,27 +416,16 @@ func (manager *SCloudaccountManager) validateCreateData(
input.Zone = obj.GetId()
}
var endpointOptions jsonutils.JSONObject
if input.SCloudaccountCredential.SHCSOEndpoints != nil {
endpointOptions = jsonutils.Marshal(input.SCloudaccountCredential.SHCSOEndpoints)
}
if input.SCloudaccountCredential.SCtyunExtraOptions != nil {
endpointOptions = jsonutils.Marshal(input.SCloudaccountCredential.SCtyunExtraOptions)
}
if input.Options == nil {
input.Options = jsonutils.NewDict()
}
input.Options.Update(jsonutils.Marshal(input.SCloudaccountCredential.SHCSOEndpoints))
input.Options.Update(jsonutils.Marshal(input.SCloudaccountCredential.SCtyunExtraOptions))
if len(input.DefaultRegion) > 0 {
input.Options.Add(jsonutils.NewString(input.DefaultRegion), "default_region")
}
if endpointOptions != nil {
input.Options.Update(endpointOptions)
}
input.SCloudaccount, err = providerDriver.ValidateCreateCloudaccountData(ctx, userCred, input.SCloudaccountCredential)
if err != nil {
return input, err
@@ -456,20 +445,22 @@ func (manager *SCloudaccountManager) validateCreateData(
input.IsPublicCloud = providerDriver.IsPublicCloud()
input.IsOnPremise = providerDriver.IsOnPremise()
q := manager.Query().Equals("provider", input.Provider)
if len(input.Account) > 0 {
q = q.Equals("account", input.Account)
}
if len(input.AccessUrl) > 0 {
q = q.Equals("access_url", input.AccessUrl)
}
if !input.SkipDuplicateAccountCheck {
q := manager.Query().Equals("provider", input.Provider)
if len(input.Account) > 0 {
q = q.Equals("account", input.Account)
}
if len(input.AccessUrl) > 0 {
q = q.Equals("access_url", input.AccessUrl)
}
cnt, err := q.CountWithError()
if err != nil {
return input, httperrors.NewInternalServerError("check uniqness fail %s", err)
}
if cnt > 0 {
return input, httperrors.NewConflictError("The account has been registered")
cnt, err := q.CountWithError()
if err != nil {
return input, httperrors.NewInternalServerError("check uniqness fail %s", err)
}
if cnt > 0 {
return input, httperrors.NewConflictError("The account has been registered")
}
}
var proxyFunc httputils.TransportProxyFunc
@@ -522,7 +513,7 @@ func (manager *SCloudaccountManager) validateCreateData(
}
// check accountId uniqueness
if len(accountId) > 0 {
if len(accountId) > 0 && !input.SkipDuplicateAccountCheck {
cnt, err := manager.Query().Equals("account_id", accountId).CountWithError()
if err != nil {
return input, httperrors.NewInternalServerError("check account_id duplication error %s", err)
@@ -2585,7 +2576,7 @@ func (account *SCloudaccount) GetUsages() []db.IUsage {
}
}
func (self *SCloudaccount) GetAvailableExternalProject(local *db.STenant, projects []SExternalProject) *SExternalProject {
func GetAvailableExternalProject(local *db.STenant, projects []SExternalProject) *SExternalProject {
var ret *SExternalProject = nil
for i := 0; i < len(projects); i++ {
if projects[i].Status == api.EXTERNAL_PROJECT_STATUS_AVAILABLE {
@@ -2626,7 +2617,7 @@ func (self *SCloudaccount) SyncProject(ctx context.Context, userCred mcclient.To
return "", errors.Wrapf(err, "GetExternalProjectsByProjectIdOrName(%s,%s)", projectId, project.Name)
}
extProj := self.GetAvailableExternalProject(project, projects)
extProj := GetAvailableExternalProject(project, projects)
if extProj != nil {
return extProj.ExternalId, nil
}

View File

@@ -1438,6 +1438,8 @@ func (self *SCloudprovider) RealDelete(ctx context.Context, userCred mcclient.To
CloudproviderRegionManager,
CloudregionManager,
CloudproviderQuotaManager,
ModelartsPoolManager,
ModelartsPoolSkuManager,
} {
err = manager.purgeAll(ctx, userCred, self.Id)
if err != nil {
@@ -1733,6 +1735,9 @@ func (provider *SCloudprovider) GetChangeOwnerCandidateDomainIds() []string {
}
func (self *SCloudprovider) SyncProject(ctx context.Context, userCred mcclient.TokenCredential, id string) (string, error) {
if self.Provider == api.CLOUD_PROVIDER_AZURE {
return self.SyncAzureProject(ctx, userCred, id)
}
account, err := self.GetCloudaccount()
if err != nil {
return "", errors.Wrapf(err, "GetCloudaccount")
@@ -1740,6 +1745,95 @@ func (self *SCloudprovider) SyncProject(ctx context.Context, userCred mcclient.T
return account.SyncProject(ctx, userCred, id)
}
func (self *SCloudprovider) GetExternalProjectsByProjectIdOrName(projectId, name string) ([]SExternalProject, error) {
projects := []SExternalProject{}
q := ExternalProjectManager.Query().Equals("manager_id", self.Id)
q = q.Filter(
sqlchemy.OR(
sqlchemy.Equals(q.Field("name"), name),
sqlchemy.Equals(q.Field("tenant_id"), projectId),
),
)
err := db.FetchModelObjects(ExternalProjectManager, q, &projects)
if err != nil {
return nil, errors.Wrap(err, "db.FetchModelObjects")
}
return projects, nil
}
func (self *SCloudprovider) SyncAzureProject(ctx context.Context, userCred mcclient.TokenCredential, id string) (string, error) {
lockman.LockRawObject(ctx, "projects", self.Id)
defer lockman.ReleaseRawObject(ctx, "projects", self.Id)
account, err := self.GetCloudaccount()
if err != nil {
return "", errors.Wrapf(err, "GetCloudaccount")
}
provider, err := self.GetProvider(ctx)
if err != nil {
return "", errors.Wrap(err, "GetProvider")
}
project, err := db.TenantCacheManager.FetchTenantById(ctx, id)
if err != nil {
return "", errors.Wrapf(err, "FetchTenantById(%s)", id)
}
projects, err := self.GetExternalProjectsByProjectIdOrName(id, project.Name)
if err != nil {
return "", errors.Wrapf(err, "GetExternalProjectsByProjectIdOrName(%s,%s)", id, project.Name)
}
extProj := GetAvailableExternalProject(project, projects)
if extProj != nil {
idx := strings.Index(extProj.ExternalId, "/")
if idx > -1 {
return extProj.ExternalId[idx+1:], nil
}
return extProj.ExternalId, nil
}
retry := 1
if len(projects) > 0 {
retry = 10
}
var iProject cloudprovider.ICloudProject = nil
projectName := project.Name
for i := 0; i < retry; i++ {
iProject, err = provider.CreateIProject(projectName)
if err == nil {
break
}
projectName = fmt.Sprintf("%s-%d", project.Name, i)
}
if err != nil {
if errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
logclient.AddSimpleActionLog(self, logclient.ACT_CREATE, err, userCred, false)
}
return "", errors.Wrapf(err, "CreateIProject(%s)", projectName)
}
extProj, err = ExternalProjectManager.newFromCloudProject(ctx, userCred, account, project, iProject)
if err != nil {
return "", errors.Wrap(err, "newFromCloudProject")
}
db.Update(extProj, func() error {
extProj.ManagerId = self.Id
return nil
})
idx := strings.Index(extProj.ExternalId, "/")
if idx > -1 {
return extProj.ExternalId[idx+1:], nil
}
return extProj.ExternalId, nil
}
func (self *SCloudprovider) GetSchedtags() []SSchedtag {
return GetSchedtags(CloudproviderschedtagManager, self.Id)
}

View File

@@ -1882,6 +1882,11 @@ func syncPublicCloudProviderInfo(
}
}
if cloudprovider.IsSupportModelartsPool(driver) && syncRange.NeedSyncResource(cloudprovider.CLOUD_CAPABILITY_MODELARTES) {
syncModelartsPoolSkus(ctx, userCred, syncResults, provider, localRegion, remoteRegion)
syncModelartsPools(ctx, userCred, syncResults, provider, localRegion, remoteRegion)
}
return nil
}
@@ -2341,3 +2346,27 @@ func syncTablestore(ctx context.Context, userCred mcclient.TokenCredential, sync
}
return nil
}
func syncModelartsPools(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, localRegion *SCloudregion, remoteRegion cloudprovider.ICloudRegion) error {
ipools, err := remoteRegion.GetIModelartsPools()
if err != nil {
msg := fmt.Sprintf("GetIModelartsPools for provider %s failed %s", err, ipools)
log.Errorf(msg)
return err
}
result := localRegion.SyncModelartsPools(ctx, userCred, provider, ipools)
log.Infof("SyncModelartsPools for region %s result: %s", provider.GetName(), result.Result())
return nil
}
func syncModelartsPoolSkus(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, localRegion *SCloudregion, remoteRegion cloudprovider.ICloudRegion) error {
ipools, err := remoteRegion.GetIModelartsPoolSku()
if err != nil {
msg := fmt.Sprintf("GetIModelartsPoolSku for provider %s failed %s", err, ipools)
log.Errorf(msg)
return err
}
result := localRegion.SyncModelartsPoolSkus(ctx, userCred, provider, ipools)
log.Infof("SyncModelartsPoolSkus for region %s result: %s", provider.GetName(), result.Result())
return nil
}

View File

@@ -74,6 +74,7 @@ func init() {
),
}
DBInstanceManager.SetVirtualObject(DBInstanceManager)
notifyclient.AddNotifyDBHookResources(DBInstanceManager.KeywordPlural())
}
type SDBInstance struct {
@@ -934,7 +935,7 @@ func (self *SDBInstance) PerformReboot(ctx context.Context, userCred mcclient.To
return nil, self.StartDBInstanceRebootTask(ctx, userCred, jsonutils.NewDict(), "")
}
//同步RDS实例状态
// 同步RDS实例状态
func (self *SDBInstance) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
return self.PerformSync(ctx, userCred, query, data)
}
@@ -2114,8 +2115,4 @@ func (self *SDBInstance) GetExpiredAt() time.Time {
func (db *SDBInstance) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {
db.SVirtualResourceBase.PostUpdate(ctx, userCred, query, data)
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
Obj: db,
Action: notifyclient.ActionUpdate,
})
}

View File

@@ -2614,8 +2614,8 @@ func (manager *SDiskManager) CleanPendingDeleteDisks(ctx context.Context, userCr
}
func (manager *SDiskManager) getAutoSnapshotDisksId(isExternal bool) ([]SSnapshotPolicyDisk, error) {
t := time.Now()
tz, _ := time.LoadLocation(options.Options.TimeZone)
t := time.Now().In(tz)
week := t.Weekday()
if week == 0 { // sunday is zero
week += 7

View File

@@ -293,8 +293,8 @@ func (manager *SDnsZoneManager) FetchCustomizeColumns(
objs[i] = &caches[i]
}
cacheDetails := DnsZoneCacheManager.FetchCustomizeColumns(ctx, userCred, jsonutils.NewDict(), objs, stringutils2.SSortedStrings{}, true)
for i := range cacheDetails {
jsonDict := jsonutils.Marshal(cacheDetails[i]).(*jsonutils.JSONDict)
for j := range cacheDetails {
jsonDict := jsonutils.Marshal(cacheDetails[j]).(*jsonutils.JSONDict)
jsonDict.Update(jsonutils.Marshal(objs[i]).(*jsonutils.JSONDict))
rows[i].CloudCaches = append(rows[i].CloudCaches, jsonDict)
}

View File

@@ -61,6 +61,7 @@ func init() {
),
}
ElasticSearchManager.SetVirtualObject(ElasticSearchManager)
notifyclient.AddNotifyDBHookResources(ElasticSearchManager.KeywordPlural())
}
type SElasticSearch struct {
@@ -631,7 +632,7 @@ func (manager *SElasticSearchManager) ListItemExportKeys(ctx context.Context,
return q, nil
}
//同步ElasticSearch实例状态
// 同步ElasticSearch实例状态
func (self *SElasticSearch) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
var openTask = true
count, err := taskman.TaskManager.QueryTasksOfObject(self, time.Now().Add(-3*time.Minute), &openTask).CountWithError()
@@ -655,8 +656,4 @@ func (self *SElasticSearch) GetDetailsAccessInfo(ctx context.Context, userCred m
func (es *SElasticSearch) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {
es.SVirtualResourceBase.PostUpdate(ctx, userCred, query, data)
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
Obj: es,
Action: notifyclient.ActionUpdate,
})
}

View File

@@ -116,14 +116,13 @@ func (self *SGuest) PerformMonitor(
ctx context.Context,
userCred mcclient.TokenCredential,
query jsonutils.JSONObject,
data jsonutils.JSONObject,
input *api.ServerMonitorInput,
) (jsonutils.JSONObject, error) {
if utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_BLOCK_STREAM, api.VM_MIGRATING}) {
cmd, err := data.GetString("command")
if err != nil {
if input.COMMAND == "" {
return nil, httperrors.NewMissingParameterError("command")
}
return self.SendMonitorCommand(ctx, userCred, cmd)
return self.SendMonitorCommand(ctx, userCred, input)
}
return nil, httperrors.NewInvalidStatusError("Cannot send command in status %s", self.Status)
}
@@ -436,7 +435,8 @@ func (self *SGuest) PerformMigrateForecast(ctx context.Context, userCred mcclien
input.PreferHostId = lmInput.PreferHost
} else {
mInput = &api.GuestMigrateInput{
PreferHost: input.PreferHostId,
PreferHost: input.PreferHostId,
IsRescueMode: input.IsRescueMode,
}
if err := self.validateMigrate(ctx, userCred, mInput, nil); err != nil {
return nil, err
@@ -527,10 +527,18 @@ func (self *SGuest) PerformLiveMigrate(ctx context.Context, userCred mcclient.To
if input.EnableTLS == nil {
input.EnableTLS = &options.Options.EnableTlsMigration
}
return nil, self.StartGuestLiveMigrateTask(ctx, userCred, self.Status, input.PreferHost, input.SkipCpuCheck, input.SkipKernelCheck, input.EnableTLS, "")
return nil, self.StartGuestLiveMigrateTask(ctx, userCred,
self.Status, input.PreferHost, input.SkipCpuCheck,
input.SkipKernelCheck, input.EnableTLS, input.QuicklyFinish, input.MaxBandwidthMb, input.KeepDestGuestOnFailed, "",
)
}
func (self *SGuest) StartGuestLiveMigrateTask(ctx context.Context, userCred mcclient.TokenCredential, guestStatus, preferHostId string, skipCpuCheck *bool, skipKernelCheck *bool, enableTLS *bool, parentTaskId string) error {
func (self *SGuest) StartGuestLiveMigrateTask(
ctx context.Context, userCred mcclient.TokenCredential,
guestStatus, preferHostId string,
skipCpuCheck, skipKernelCheck, enableTLS, quicklyFinish *bool,
maxBandwidthMb *int64, keepDestGuestOnFailed *bool, parentTaskId string,
) error {
self.SetStatus(userCred, api.VM_START_MIGRATE, "")
data := jsonutils.NewDict()
if len(preferHostId) > 0 {
@@ -545,6 +553,16 @@ func (self *SGuest) StartGuestLiveMigrateTask(ctx context.Context, userCred mccl
if enableTLS != nil {
data.Set("enable_tls", jsonutils.NewBool(*enableTLS))
}
if quicklyFinish != nil {
data.Set("quickly_finish", jsonutils.NewBool(*quicklyFinish))
}
if maxBandwidthMb != nil {
data.Set("max_bandwidth_mb", jsonutils.NewInt(*maxBandwidthMb))
}
if keepDestGuestOnFailed != nil {
data.Set("keep_dest_guest_on_failed", jsonutils.NewBool(*keepDestGuestOnFailed))
}
data.Set("guest_status", jsonutils.NewString(guestStatus))
dedicateMigrateTask := "GuestLiveMigrateTask"
if self.GetHypervisor() != api.HYPERVISOR_KVM {
@@ -559,6 +577,48 @@ func (self *SGuest) StartGuestLiveMigrateTask(ctx context.Context, userCred mccl
return nil
}
func (self *SGuest) PerformSetLiveMigrateParams(
ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ServerSetLiveMigrateParamsInput,
) (jsonutils.JSONObject, error) {
if self.Status != api.VM_LIVE_MIGRATING {
return nil, httperrors.NewServerStatusError("cannot set migrate params in status %s", self.Status)
}
if input.MaxBandwidthMB == nil && input.DowntimeLimitMS == nil {
return nil, httperrors.NewInputParameterError("empty input")
}
arguments := map[string]interface{}{}
if input.MaxBandwidthMB != nil {
arguments["max-bandwidth"] = *input.MaxBandwidthMB * 1024 * 1024
}
if input.DowntimeLimitMS != nil {
arguments["downtime-limit"] = *input.DowntimeLimitMS
}
cmd := map[string]interface{}{
"execute": "migrate-set-parameters",
"arguments": arguments,
}
log.Infof("set live migrate params input: %s", jsonutils.Marshal(cmd).String())
monitorInput := &api.ServerMonitorInput{
COMMAND: jsonutils.Marshal(cmd).String(),
QMP: true,
}
return self.SendMonitorCommand(ctx, userCred, monitorInput)
}
func (self *SGuest) PerformCancelLiveMigrate(
ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject,
) (jsonutils.JSONObject, error) {
if self.Status != api.VM_LIVE_MIGRATING {
return nil, httperrors.NewServerStatusError("cannot set migrate params in status %s", self.Status)
}
monitorInput := &api.ServerMonitorInput{
COMMAND: "migrate_cancel",
QMP: false,
}
return self.SendMonitorCommand(ctx, userCred, monitorInput)
}
func (self *SGuest) PerformClone(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
if self.IsEncrypted() {
return nil, httperrors.NewForbiddenError("cannot clone encrypted server")
@@ -631,14 +691,8 @@ func (self *SGuest) PerformClone(ctx context.Context, userCred mcclient.TokenCre
return nil, nil
}
func (self *SGuest) GetDetailsCreateParams(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
input := self.ToCreateInput(ctx, userCred)
return input.JSON(input), nil
}
func (self *SGuest) PerformSetPassword(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ServerSetPasswordInput) (jsonutils.JSONObject, error) {
switch self.Status {
case api.VM_RUNNING:
if self.Hypervisor == api.HYPERVISOR_KVM && self.Status == api.VM_RUNNING {
inputQga := &api.ServerQgaSetPasswordInput{
Username: input.Username,
Password: input.Password,
@@ -654,18 +708,21 @@ func (self *SGuest) PerformSetPassword(ctx context.Context, userCred mcclient.To
inputQga.Password = seclib2.RandomPassword2(12)
}
return self.PerformQgaSetPassword(ctx, userCred, query, inputQga)
case api.VM_READY:
} else {
inputDeploy := api.ServerDeployInput{
Password: input.Password,
ResetPassword: input.ResetPassword,
AutoStart: input.AutoStart,
}
return self.PerformDeploy(ctx, userCred, query, inputDeploy)
default:
return nil, httperrors.NewServerStatusError("Cannot deploy in status %s", self.Status)
}
}
func (self *SGuest) GetDetailsCreateParams(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
input := self.ToCreateInput(ctx, userCred)
return input.JSON(input), nil
}
func (self *SGuest) saveOldPassword(ctx context.Context, userCred mcclient.TokenCredential) {
loginKey := self.GetMetadata(ctx, api.VM_METADATA_LOGIN_KEY, userCred)
if len(loginKey) > 0 {
@@ -2958,7 +3015,7 @@ func (self *SGuest) PerformSendkeys(ctx context.Context, userCred mcclient.Token
if err == nil {
cmd = fmt.Sprintf("%s %d", cmd, duration)
}
_, err = self.SendMonitorCommand(ctx, userCred, cmd)
_, err = self.SendMonitorCommand(ctx, userCred, &api.ServerMonitorInput{COMMAND: cmd})
return nil, err
}
@@ -2993,13 +3050,14 @@ func (self *SGuest) IsLegalKey(key string) bool {
return true
}
func (self *SGuest) SendMonitorCommand(ctx context.Context, userCred mcclient.TokenCredential, cmd string) (jsonutils.JSONObject, error) {
func (self *SGuest) SendMonitorCommand(ctx context.Context, userCred mcclient.TokenCredential, cmd *api.ServerMonitorInput) (jsonutils.JSONObject, error) {
host, _ := self.GetHost()
url := fmt.Sprintf("%s/servers/%s/monitor", host.ManagerUri, self.Id)
header := http.Header{}
header.Add("X-Auth-Token", userCred.GetTokenString())
body := jsonutils.NewDict()
body.Add(jsonutils.NewString(cmd), "cmd")
body.Add(jsonutils.NewString(cmd.COMMAND), "cmd")
body.Add(jsonutils.NewBool(cmd.QMP), "qmp")
_, res, err := httputils.JSONRequest(httputils.GetDefaultClient(), ctx, "POST", url, header, body, false)
if err != nil {
return nil, err
@@ -4644,6 +4702,8 @@ func (manager *SGuestManager) PerformBatchMigrate(ctx context.Context, userCred
SkipCpuCheck: params.SkipCpuCheck,
SkipKernelCheck: params.SkipKernelCheck,
EnableTLS: params.EnableTLS,
MaxBandwidthMb: params.MaxBandwidthMb,
QuciklyFinish: params.QuciklyFinish,
}
guests[i].SetStatus(userCred, api.VM_START_MIGRATE, "batch migrate")
if _, ok := hostGuests[guests[i].HostId]; ok {

View File

@@ -101,6 +101,7 @@ func init() {
GuestManager.SetVirtualObject(GuestManager)
GuestManager.SetAlias("guest", "guests")
GuestManager.NameRequireAscii = false
notifyclient.AddNotifyDBHookResources(GuestManager.KeywordPlural(), GuestManager.AliasPlural())
}
type SGuest struct {
@@ -1886,10 +1887,6 @@ func (self *SGuest) PostUpdate(ctx context.Context, userCred mcclient.TokenCrede
log.Errorf("unable to set sshport for guest %s", self.GetId())
}
}
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
Obj: self,
Action: notifyclient.ActionUpdate,
})
}
func (manager *SGuestManager) checkCreateQuota(
@@ -2542,7 +2539,7 @@ func (self *SGuest) getAdminSecgroupName() string {
return ""
}
//获取多个安全组规则,优先级降序排序
// 获取多个安全组规则,优先级降序排序
func (self *SGuest) getSecurityGroupsRules() string {
secgroups, _ := self.GetSecgroups()
secgroupids := []string{}
@@ -2644,7 +2641,7 @@ func (self *SGuest) syncRemoveCloudVM(ctx context.Context, userCred mcclient.Tok
}
}
} else if errors.Cause(err) != cloudprovider.ErrNotFound {
return err
return errors.Wrap(err, "GetIVMById")
}
if options.SyncPurgeRemovedResources.Contains(self.Keyword()) {
@@ -2697,6 +2694,32 @@ func (guest *SGuest) SyncAllWithCloudVM(ctx context.Context, userCred mcclient.T
return nil
}
func (g *SGuest) SyncOsInfo(ctx context.Context, userCred mcclient.TokenCredential, extVM cloudprovider.IOSInfo) error {
// save os info
osinfo := map[string]interface{}{}
for k, v := range map[string]string{
"os_full_name": extVM.GetFullOsName(),
"os_name": string(extVM.GetOsType()),
"os_arch": extVM.GetOsArch(),
"os_type": string(extVM.GetOsType()),
"os_distribution": extVM.GetOsDist(),
"os_version": extVM.GetOsVersion(),
"os_language": extVM.GetOsLang(),
} {
if len(v) == 0 {
continue
}
osinfo[k] = v
}
if len(osinfo) > 0 {
err := g.SetAllMetadata(ctx, osinfo, userCred)
if err != nil {
return errors.Wrap(err, "SetAllMetadata")
}
}
return nil
}
func (self *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.TokenCredential, provider cloudprovider.ICloudProvider, host *SHost, extVM cloudprovider.ICloudVM, syncOwnerId mcclient.IIdentityProvider, syncStatus bool) error {
recycle := false
@@ -2722,9 +2745,15 @@ func (self *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.Token
self.BootOrder = extVM.GetBootOrder()
self.Vga = extVM.GetVga()
self.Vdi = extVM.GetVdi()
self.OsArch = extVM.GetOSArch()
self.OsType = string(extVM.GetOsType())
self.Bios = extVM.GetBios()
if len(self.OsArch) == 0 {
self.OsArch = extVM.GetOsArch()
}
if len(self.OsType) == 0 {
self.OsType = string(extVM.GetOsType())
}
if len(self.Bios) == 0 {
self.Bios = string(extVM.GetBios())
}
self.Machine = extVM.GetMachine()
if !recycle {
self.HostId = host.Id
@@ -2786,6 +2815,8 @@ func (self *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.Token
})
}
self.SyncOsInfo(ctx, userCred, extVM)
syncVirtualResourceMetadata(ctx, userCred, self, extVM)
SyncCloudProject(userCred, self, syncOwnerId, extVM, host.ManagerId)
@@ -2811,9 +2842,9 @@ func (manager *SGuestManager) newCloudVM(ctx context.Context, userCred mcclient.
guest.BootOrder = extVM.GetBootOrder()
guest.Vga = extVM.GetVga()
guest.Vdi = extVM.GetVdi()
guest.OsArch = extVM.GetOSArch()
guest.OsArch = extVM.GetOsArch()
guest.OsType = string(extVM.GetOsType())
guest.Bios = extVM.GetBios()
guest.Bios = string(extVM.GetBios())
guest.Machine = extVM.GetMachine()
guest.Hypervisor = extVM.GetHypervisor()
guest.Hostname = extVM.GetHostname()
@@ -2887,6 +2918,8 @@ func (manager *SGuestManager) newCloudVM(ctx context.Context, userCred mcclient.
return nil, errors.Wrapf(err, "Insert")
}
guest.SyncOsInfo(ctx, userCred, extVM)
syncVirtualResourceMetadata(ctx, userCred, &guest, extVM)
SyncCloudProject(userCred, &guest, syncOwnerId, extVM, host.ManagerId)
@@ -2986,7 +3019,7 @@ func (self *SGuest) GetOSProfile() osprofile.SOSProfile {
// Summary of network address allocation strategy
//
// IpAddr when specified must be part of the network
// # IpAddr when specified must be part of the network
//
// Use IpAddr without checking if it's already allocated when UseDesignatedIP
// is true. See b31bc7fa ("feature: 1. baremetal server reuse host ip...")
@@ -4476,7 +4509,7 @@ func (self *SGuest) GetJsonDescAtHypervisor(ctx context.Context, host *SHost) *a
// add scaling group
sggs, err := ScalingGroupGuestManager.Fetch("", self.Id)
if err == nil && len(sggs) > 0 {
desc.ScallingGroupId = sggs[0].ScalingGroupId
desc.ScalingGroupId = sggs[0].ScalingGroupId
}
return desc

View File

@@ -17,6 +17,7 @@ package models
import (
"context"
"fmt"
"sync"
"time"
"yunion.io/x/log"
@@ -37,7 +38,7 @@ type SHostHealthChecker struct {
// time of wait host reconnect
timeout time.Duration
// hosts chan
hc map[string]chan struct{}
hc *sync.Map
}
func hostKey(hostname string) string {
@@ -51,7 +52,7 @@ func InitHostHealthChecker(cli *etcd.SEtcdClient, timeout int) *SHostHealthCheck
hostHealthChecker = &SHostHealthChecker{
cli: cli,
timeout: time.Duration(timeout) * time.Second,
hc: make(map[string]chan struct{}),
hc: new(sync.Map),
}
return hostHealthChecker
}
@@ -61,6 +62,11 @@ func (h *SHostHealthChecker) StartHostsHealthCheck(ctx context.Context) error {
return h.startHealthCheck(ctx)
}
func (h *SHostHealthChecker) load(hostname string) chan struct{} {
v, _ := h.hc.Load(hostname)
return v.(chan struct{})
}
func (h *SHostHealthChecker) startHealthCheck(ctx context.Context) error {
q := HostManager.Query().IsTrue("enabled").IsTrue("enable_health_check").Equals("host_type", api.HOST_TYPE_HYPERVISOR)
rows, err := q.Rows()
@@ -88,8 +94,8 @@ func (h *SHostHealthChecker) startWatcher(ctx context.Context, hostname string)
log.Infof("Start watch host %s", hostname)
var key = hostKey(hostname)
if _, ok := h.hc[hostname]; !ok {
h.hc[hostname] = make(chan struct{})
if _, ok := h.hc.Load(hostname); !ok {
h.hc.Store(hostname, make(chan struct{}))
}
if err := h.cli.Watch(
ctx, key,
@@ -108,7 +114,7 @@ func (h *SHostHealthChecker) startWatcher(ctx context.Context, hostname string)
select {
case <-time.NewTimer(h.timeout).C:
h.onHostUnhealthy(ctx, hostname)
case <-h.hc[hostname]:
case <-h.load(hostname):
if _err := h.startWatcher(ctx, hostname); _err != nil {
log.Errorf("failed start watcher %s", _err)
}
@@ -136,8 +142,9 @@ func (h *SHostHealthChecker) onHostUnhealthy(ctx context.Context, hostname strin
func (h *SHostHealthChecker) onHostOnline(ctx context.Context, hostname string) etcd.TEtcdCreateEventFunc {
return func(ctx context.Context, key, value []byte) {
log.Infof("Got host online %s", hostname)
if h.hc[hostname] != nil {
h.hc[hostname] <- struct{}{}
if v, ok := h.hc.Load(hostname); ok {
c := v.(chan struct{})
c <- struct{}{}
}
}
}
@@ -148,7 +155,7 @@ func (h *SHostHealthChecker) processHostOffline(ctx context.Context, hostname st
select {
case <-time.NewTimer(h.timeout).C:
h.onHostUnhealthy(ctx, hostname)
case <-h.hc[hostname]:
case <-h.load(hostname):
if err := h.startWatcher(ctx, hostname); err != nil {
log.Errorf("failed start watcher %s", err)
}
@@ -178,5 +185,5 @@ func (h *SHostHealthChecker) WatchHost(ctx context.Context, hostname string) err
func (h *SHostHealthChecker) UnwatchHost(ctx context.Context, hostname string) {
log.Infof("Unwatch host %s", hostname)
h.cli.Unwatch(hostKey(hostname))
delete(h.hc, hostname)
h.hc.Delete(hostname)
}

View File

@@ -1867,6 +1867,10 @@ func (self *SHost) syncWithCloudHost(ctx context.Context, userCred mcclient.Toke
self.MemCmtbound = memCmt
}
if arch := extHost.GetCpuArchitecture(); len(arch) > 0 {
self.CpuArchitecture = arch
}
if reservedMem := extHost.GetReservedMemoryMb(); reservedMem > 0 {
self.MemReserved = reservedMem
}
@@ -2107,6 +2111,9 @@ func (manager *SHostManager) NewFromCloudHost(ctx context.Context, userCred mccl
if memCmt := extHost.GetMemCmtbound(); memCmt > 0 {
host.MemCmtbound = memCmt
}
if arch := extHost.GetCpuArchitecture(); len(arch) > 0 {
host.CpuArchitecture = arch
}
if reservedMem := extHost.GetReservedMemoryMb(); reservedMem > 0 {
host.MemReserved = reservedMem
@@ -2449,7 +2456,7 @@ func (self *SHost) SyncHostVMs(ctx context.Context, userCred mcclient.TokenCrede
}
skipFunc := func(ext cloudprovider.ICloudVM) (bool, string) {
if len(options.Options.SkipServerBySysTagKeys) == 0 {
if len(options.Options.SkipServerBySysTagKeys) == 0 && len(options.Options.SkipServerBySysTagKeys) == 0 {
return false, ""
}
keys := strings.Split(options.Options.SkipServerBySysTagKeys, ",")
@@ -2458,6 +2465,13 @@ func (self *SHost) SyncHostVMs(ctx context.Context, userCred mcclient.TokenCrede
return true, key
}
}
userKeys := strings.Split(options.Options.SkipServerByUserTagKeys, ",")
tags, _ := ext.GetTags()
for key := range tags {
if utils.IsInStringArray(key, userKeys) {
return true, key
}
}
return false, ""
}
@@ -2473,8 +2487,8 @@ func (self *SHost) SyncHostVMs(ctx context.Context, userCred mcclient.TokenCrede
for i := 0; i < len(commondb); i += 1 {
skip, key := skipFunc(commonext[i])
if skip {
log.Infof("skip server %s(%s) sync for delete with system tag key: %s", commonext[i].GetName(), commonext[i].GetGlobalId(), key)
err := commondb[i].syncRemoveCloudVM(ctx, userCred)
log.Infof("delete server %s(%s) with system tag key: %s", commonext[i].GetName(), commonext[i].GetGlobalId(), key)
err := commondb[i].purge(ctx, userCred)
if err != nil {
syncResult.DeleteError(err)
continue
@@ -5392,8 +5406,12 @@ func (self *SHost) EsxiRequest(ctx context.Context, method httputils.THttpMethod
return self.doAgentRequest(api.AgentTypeEsxi, ctx, method, url, headers, body)
}
func (self *SHost) GetAgent(at api.TAgentType) *SBaremetalagent {
return BaremetalagentManager.GetAgent(at, self.ZoneId)
}
func (self *SHost) isAgentReady(agentType api.TAgentType) bool {
agent := BaremetalagentManager.GetAgent(agentType, self.ZoneId)
agent := self.GetAgent(agentType)
if agent == nil {
log.Errorf("%s ready: false", agentType)
return false
@@ -5612,7 +5630,7 @@ func (host *SHost) OnHostDown(ctx context.Context, userCred mcclient.TokenCreden
hostHealthChecker.UnwatchHost(ctx, host.GetHostnameByName())
if host.HostStatus == api.HOST_OFFLINE && !host.EnableHealthCheck &&
host.autoMigrateOnHostShutdown(ctx) {
!host.autoMigrateOnHostShutdown(ctx) {
// hostagent requested offline, and not enable auto migrate on host shutdown
log.Infof("host not need auto migrate on host shutdown")
return

View File

@@ -731,17 +731,19 @@ func (lbr *SLoadbalancerListenerRule) constructFieldsFromCloudListenerRule(userC
lbr.BackendGroupId = ""
}
log.Errorf("Fetch huawei loadbalancer backendgroup by external id %s failed: %s", groupId, err)
} else {
lbr.BackendGroupId = group.(*SHuaweiCachedLbbg).BackendGroupId
}
lbr.BackendGroupId = group.(*SHuaweiCachedLbbg).BackendGroupId
} else if lbr.GetProviderName() == api.CLOUD_PROVIDER_AWS {
if len(groupId) > 0 {
group, err := db.FetchByExternalId(AwsCachedLbbgManager, groupId)
if err != nil {
log.Errorf("Fetch aws loadbalancer backendgroup by external id %s failed: %s", groupId, err)
} else {
lbr.BackendGroupId = group.(*SAwsCachedLbbg).BackendGroupId
}
lbr.BackendGroupId = group.(*SAwsCachedLbbg).BackendGroupId
}
} else if lbr.GetProviderName() == api.CLOUD_PROVIDER_QCLOUD {
group, err := db.FetchByExternalId(QcloudCachedLbbgManager, groupId)
@@ -750,9 +752,10 @@ func (lbr *SLoadbalancerListenerRule) constructFieldsFromCloudListenerRule(userC
lbr.BackendGroupId = ""
}
log.Errorf("Fetch qcloud loadbalancer backendgroup by external id %s failed: %s", groupId, err)
} else {
lbr.BackendGroupId = group.(*SQcloudCachedLbbg).BackendGroupId
}
lbr.BackendGroupId = group.(*SQcloudCachedLbbg).BackendGroupId
} else if backendgroup, err := db.FetchByExternalId(LoadbalancerBackendGroupManager, groupId); err == nil {
lbr.BackendGroupId = backendgroup.GetId()
}

View File

@@ -0,0 +1,297 @@
// 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 models
import (
"context"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/compare"
"yunion.io/x/sqlchemy"
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/cloudprovider"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/util/stringutils2"
)
type SModelartsPoolSkuManager struct {
db.SExternalizedResourceBaseManager
db.SEnabledStatusStandaloneResourceBaseManager
SCloudregionResourceBaseManager
SManagedResourceBaseManager
}
var ModelartsPoolSkuManager *SModelartsPoolSkuManager
func init() {
ModelartsPoolSkuManager = &SModelartsPoolSkuManager{
SEnabledStatusStandaloneResourceBaseManager: db.NewEnabledStatusStandaloneResourceBaseManager(
SModelartsPoolSku{},
"modelarts_pool_skus_tbl",
"modelarts_pool_sku",
"modelarts_pool_skus",
),
}
ModelartsPoolSkuManager.NameRequireAscii = false
ModelartsPoolSkuManager.SetVirtualObject(ModelartsPoolSkuManager)
}
type SModelartsPoolSku struct {
SManagedResourceBase
db.SEnabledStatusStandaloneResourceBase
db.SExternalizedResourceBase
SCloudregionResourceBase
Type string `width:"128" charset:"ascii" nullable:"true" list:"user" create:"admin_optional" update:"admin"` // 资源规格类型
// CPU 架构 x86|xarm
CpuArch string `width:"16" charset:"ascii" nullable:"true" list:"user" create:"admin_optional" update:"admin"`
//CPU核心数量
CpuCount int `list:"user" create:"admin_optional" update:"admin"`
// GPU卡类型
GpuType string `width:"128" charset:"ascii" nullable:"true" list:"user" create:"admin_optional" update:"admin"`
// GPU卡数量
GpuSize int `nullable:"true" list:"user" create:"admin_optional" update:"admin"`
// NPU卡类型
NpuType string `width:"128" charset:"ascii" nullable:"true" list:"user" create:"admin_optional" update:"admin"`
// NPU卡数量
NpuSize int `nullable:"true" list:"user" create:"admin_optional" update:"admin"`
// 内存
Memory int `nullable:"true" list:"user" create:"admin_optional" update:"admin"`
}
func (manager *SModelartsPoolSkuManager) GetContextManagers() [][]db.IModelManager {
return [][]db.IModelManager{}
}
func (man *SModelartsPoolSkuManager) ListItemFilter(
ctx context.Context,
q *sqlchemy.SQuery,
userCred mcclient.TokenCredential,
query api.ModelartsPoolSkuListInput,
) (*sqlchemy.SQuery, error) {
var err error
q, err = man.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.EnabledStatusStandaloneResourceListInput)
if err != nil {
return nil, errors.Wrap(err, "SEnabledStatusStandaloneResourceBaseManager.ListItemFilter")
}
q, err = man.SExternalizedResourceBaseManager.ListItemFilter(ctx, q, userCred, query.ExternalizedResourceBaseListInput)
if err != nil {
return nil, errors.Wrap(err, "SExternalizedResourceBaseManager.ListItemFilter")
}
q, err = man.SManagedResourceBaseManager.ListItemFilter(ctx, q, userCred, query.ManagedResourceListInput)
if err != nil {
return nil, errors.Wrap(err, "SManagedResourceBaseManager.ListItemFilter")
}
q, err = man.SCloudregionResourceBaseManager.ListItemFilter(ctx, q, userCred, query.RegionalFilterListInput)
if err != nil {
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.ListItemFilter")
}
return q, nil
}
func (man *SModelartsPoolSkuManager) OrderByExtraFields(
ctx context.Context,
q *sqlchemy.SQuery,
userCred mcclient.TokenCredential,
query api.ModelartsPoolSkuListInput,
) (*sqlchemy.SQuery, error) {
q, err := man.SEnabledStatusStandaloneResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.EnabledStatusStandaloneResourceListInput)
if err != nil {
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.OrderByExtraFields")
}
q, err = man.SExternalizedResourceBaseManager.ListItemFilter(ctx, q, userCred, query.ExternalizedResourceBaseListInput)
if err != nil {
return nil, errors.Wrap(err, "SExternalizedResourceBaseManager.ListItemFilter")
}
q, err = man.SManagedResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.ManagedResourceListInput)
if err != nil {
return nil, errors.Wrap(err, "SManagedResourceBaseManager.OrderByExtraFields")
}
q, err = man.SCloudregionResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.RegionalFilterListInput)
if err != nil {
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.OrderByExtraFields")
}
return q, nil
}
func (man *SModelartsPoolSkuManager) QueryDistinctExtraField(q *sqlchemy.SQuery, field string) (*sqlchemy.SQuery, error) {
q, err := man.SEnabledStatusStandaloneResourceBaseManager.QueryDistinctExtraField(q, field)
if err == nil {
return q, nil
}
q, err = man.SManagedResourceBaseManager.QueryDistinctExtraField(q, field)
if err == nil {
return q, nil
}
return q, httperrors.ErrNotFound
}
func (manager *SModelartsPoolSkuManager) FetchCustomizeColumns(
ctx context.Context,
userCred mcclient.TokenCredential,
query jsonutils.JSONObject,
objs []interface{},
fields stringutils2.SSortedStrings,
isList bool,
) []api.ModelartsPoolSkuDetails {
rows := make([]api.ModelartsPoolSkuDetails, len(objs))
enabledRows := manager.SEnabledStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
manRows := manager.SManagedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
regRows := manager.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
for i := range rows {
rows[i] = api.ModelartsPoolSkuDetails{
EnabledStatusStandaloneResourceDetails: enabledRows[i],
ManagedResourceInfo: manRows[i],
CloudregionResourceInfo: regRows[i],
}
}
return rows
}
func (manager *SModelartsPoolSkuManager) ListItemExportKeys(ctx context.Context,
q *sqlchemy.SQuery,
userCred mcclient.TokenCredential,
keys stringutils2.SSortedStrings,
) (*sqlchemy.SQuery, error) {
var err error
q, err = manager.SEnabledStatusStandaloneResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
if err != nil {
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemExportKeys")
}
if keys.ContainsAny(manager.SManagedResourceBaseManager.GetExportKeys()...) {
q, err = manager.SManagedResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
if err != nil {
return nil, errors.Wrap(err, "SManagedResourceBaseManager.ListItemExportKeys")
}
}
return q, nil
}
func (self *SCloudregion) GetModelartsPoolSkus(managerId string) ([]SModelartsPoolSku, error) {
q := ModelartsPoolSkuManager.Query().Equals("cloudregion_id", self.Id)
if len(managerId) > 0 {
q = q.Equals("manager_id", managerId)
}
ret := []SModelartsPoolSku{}
err := db.FetchModelObjects(ModelartsPoolSkuManager, q, &ret)
if err != nil {
return nil, errors.Wrapf(err, "db.FetchModelObjects")
}
return ret, nil
}
func (self *SCloudregion) SyncModelartsPoolSkus(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, exts []cloudprovider.ICloudModelartsPoolSku) compare.SyncResult {
// 加锁防止重入
lockman.LockRawObject(ctx, self.Provider, "modelarts-pool-sku")
defer lockman.ReleaseRawObject(ctx, self.Provider, "modelarts-pool-sku")
result := compare.SyncResult{}
dbPoolSku, err := self.GetModelartsPoolSkus(provider.Id)
if err != nil {
result.Error(err)
return result
}
removed := make([]SModelartsPoolSku, 0)
commondb := make([]SModelartsPoolSku, 0)
commonext := make([]cloudprovider.ICloudModelartsPoolSku, 0)
added := make([]cloudprovider.ICloudModelartsPoolSku, 0)
// 本地和云上资源列表进行比对
err = compare.CompareSets(dbPoolSku, exts, &removed, &commondb, &commonext, &added)
if err != nil {
result.Error(err)
return result
}
// 删除云上没有的资源
for i := 0; i < len(removed); i++ {
err := removed[i].Delete(ctx, userCred)
if err != nil {
result.DeleteError(err)
continue
}
result.Delete()
}
// 和云上资源属性进行同步
for i := 0; i < len(commondb); i++ {
log.Errorln("this is commonext", commonext[i])
err := commondb[i].syncWithCloudSku(ctx, userCred, commonext[i])
if err != nil {
result.UpdateError(err)
continue
}
result.Update()
}
// 创建本地没有的云上资源
for i := 0; i < len(added); i++ {
err := self.newFromCloudModelartsPoolSku(ctx, userCred, provider, added[i])
if err != nil {
result.AddError(err)
continue
}
result.Add()
}
return result
}
func (self *SModelartsPoolSku) syncWithCloudSku(ctx context.Context, userCred mcclient.TokenCredential, isku cloudprovider.ICloudModelartsPoolSku) error {
_, err := db.Update(self, func() error {
self.Name = isku.GetName()
self.CpuCount = isku.GetCpuCoreCount()
self.CpuArch = isku.GetCpuArch()
self.Status = isku.GetStatus()
self.Type = isku.GetPoolType()
self.CreatedAt = isku.GetCreatedAt()
self.GpuType = isku.GetGpuType()
self.GpuSize = isku.GetGpuSize()
self.Memory = isku.GetMemorySizeMB()
self.NpuType = isku.GetNpuType()
self.NpuSize = isku.GetNpuSize()
self.ExternalId = isku.GetGlobalId()
return nil
})
return err
}
func (self *SCloudregion) newFromCloudModelartsPoolSku(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, isku cloudprovider.ICloudModelartsPoolSku) error {
sku := SModelartsPoolSku{}
sku.SetModelManager(ModelartsPoolSkuManager, &sku)
sku.CloudregionId = self.Id
sku.Name = isku.GetName()
sku.CpuCount = isku.GetCpuCoreCount()
sku.CpuArch = isku.GetCpuArch()
sku.Status = isku.GetStatus()
sku.Type = isku.GetPoolType()
sku.CreatedAt = isku.GetCreatedAt()
sku.GpuType = isku.GetGpuType()
sku.GpuSize = isku.GetGpuSize()
sku.Memory = isku.GetMemorySizeMB()
sku.NpuType = isku.GetNpuType()
sku.NpuSize = isku.GetNpuSize()
sku.ExternalId = isku.GetGlobalId()
sku.ManagerId = provider.Id
return ModelartsPoolSkuManager.TableSpec().Insert(ctx, &sku)
}

View File

@@ -0,0 +1,498 @@
// 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 models
import (
"context"
"fmt"
"time"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/compare"
"yunion.io/x/sqlchemy"
billing_api "yunion.io/x/onecloud/pkg/apis/billing"
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/validators"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/util/stringutils2"
)
type SModelartsPoolManager struct {
// 由于资源是用户资源因此定义为Virtual资源
db.SVirtualResourceBaseManager
db.SExternalizedResourceBaseManager
SDeletePreventableResourceBaseManager
SCloudregionResourceBaseManager
SManagedResourceBaseManager
}
var ModelartsPoolManager *SModelartsPoolManager
func init() {
ModelartsPoolManager = &SModelartsPoolManager{
SVirtualResourceBaseManager: db.NewVirtualResourceBaseManager(
SModelartsPool{},
"modelarts_pools_tbl",
"modelarts_pool",
"modelarts_pools",
),
}
ModelartsPoolManager.SetVirtualObject(ModelartsPoolManager)
}
type SModelartsPool struct {
db.SVirtualResourceBase
db.SExternalizedResourceBase
SManagedResourceBase
SBillingResourceBase
SCloudregionResourceBase
SDeletePreventableResourceBase
InstanceType string `width:"72" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"`
NodeCount int `nullable:"false" list:"user" create:"required"`
WorkType string `width:"72" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"`
// CPU 架构 x86|xarm
CpuArch string `width:"16" charset:"ascii" nullable:"true" list:"user" create:"admin_optional" update:"admin"`
}
func (manager *SModelartsPoolManager) GetContextManagers() [][]db.IModelManager {
return [][]db.IModelManager{{CloudregionManager}}
}
// Pool实例列表
func (man *SModelartsPoolManager) ListItemFilter(
ctx context.Context,
q *sqlchemy.SQuery,
userCred mcclient.TokenCredential,
query api.ModelartsPoolListInput,
) (*sqlchemy.SQuery, error) {
var err error
q, err = man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
if err != nil {
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
}
q, err = man.SExternalizedResourceBaseManager.ListItemFilter(ctx, q, userCred, query.ExternalizedResourceBaseListInput)
if err != nil {
return nil, errors.Wrap(err, "SExternalizedResourceBaseManager.ListItemFilter")
}
q, err = man.SDeletePreventableResourceBaseManager.ListItemFilter(ctx, q, userCred, query.DeletePreventableResourceBaseListInput)
if err != nil {
return nil, errors.Wrap(err, "SDeletePreventableResourceBaseManager.ListItemFilter")
}
q, err = man.SManagedResourceBaseManager.ListItemFilter(ctx, q, userCred, query.ManagedResourceListInput)
if err != nil {
return nil, errors.Wrap(err, "SManagedResourceBaseManager.ListItemFilter")
}
q, err = man.SCloudregionResourceBaseManager.ListItemFilter(ctx, q, userCred, query.RegionalFilterListInput)
if err != nil {
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.ListItemFilter")
}
return q, nil
}
func (man *SModelartsPoolManager) OrderByExtraFields(
ctx context.Context,
q *sqlchemy.SQuery,
userCred mcclient.TokenCredential,
query api.ModelartsPoolListInput,
) (*sqlchemy.SQuery, error) {
q, err := man.SVirtualResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.VirtualResourceListInput)
if err != nil {
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.OrderByExtraFields")
}
q, err = man.SCloudregionResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.RegionalFilterListInput)
if err != nil {
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.OrderByExtraFields")
}
q, err = man.SManagedResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.ManagedResourceListInput)
if err != nil {
return nil, errors.Wrap(err, "SManagedResourceBaseManager.OrderByExtraFields")
}
return q, nil
}
func (man *SModelartsPoolManager) QueryDistinctExtraField(q *sqlchemy.SQuery, field string) (*sqlchemy.SQuery, error) {
q, err := man.SVirtualResourceBaseManager.QueryDistinctExtraField(q, field)
if err == nil {
return q, nil
}
q, err = man.SCloudregionResourceBaseManager.QueryDistinctExtraField(q, field)
if err == nil {
return q, nil
}
q, err = man.SManagedResourceBaseManager.QueryDistinctExtraField(q, field)
if err == nil {
return q, nil
}
return q, httperrors.ErrNotFound
}
func (man *SModelartsPoolManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input api.ModelartsPoolCreateInput) (api.ModelartsPoolCreateInput, error) {
var err error
if input.NodeCount <= 0 {
input.NodeCount = 1
}
if input.NodeCount > 200 {
return input, errors.Wrap(errors.ErrNotSupported, "node count must between 1 and 200")
}
_, err = validators.ValidateModel(userCred, CloudproviderManager, &input.CloudproviderId)
if err != nil {
return input, err
}
input.ManagerId = input.CloudproviderId
_, err = validators.ValidateModel(userCred, CloudregionManager, &input.CloudregionId)
if err != nil {
return input, err
}
input.VirtualResourceCreateInput, err = man.SVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.VirtualResourceCreateInput)
if err != nil {
return input, err
}
return input, nil
}
func (manager *SModelartsPoolManager) FetchCustomizeColumns(
ctx context.Context,
userCred mcclient.TokenCredential,
query jsonutils.JSONObject,
objs []interface{},
fields stringutils2.SSortedStrings,
isList bool,
) []api.ModelartsPoolDetails {
rows := make([]api.ModelartsPoolDetails, len(objs))
virtRows := manager.SVirtualResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
manRows := manager.SManagedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
regRows := manager.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
for i := range rows {
rows[i] = api.ModelartsPoolDetails{
VirtualResourceDetails: virtRows[i],
ManagedResourceInfo: manRows[i],
CloudregionResourceInfo: regRows[i],
}
}
return rows
}
func (manager *SModelartsPoolManager) ListItemExportKeys(ctx context.Context,
q *sqlchemy.SQuery,
userCred mcclient.TokenCredential,
keys stringutils2.SSortedStrings,
) (*sqlchemy.SQuery, error) {
var err error
q, err = manager.SVirtualResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
if err != nil {
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemExportKeys")
}
if keys.ContainsAny(manager.SManagedResourceBaseManager.GetExportKeys()...) {
q, err = manager.SManagedResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
if err != nil {
return nil, errors.Wrap(err, "SManagedResourceBaseManager.ListItemExportKeys")
}
}
return q, nil
}
func (self *SCloudregion) GetPools(managerId string) ([]SModelartsPool, error) {
q := ModelartsPoolManager.Query().Equals("cloudregion_id", self.Id)
if len(managerId) > 0 {
q = q.Equals("manager_id", managerId)
}
ret := []SModelartsPool{}
err := db.FetchModelObjects(ModelartsPoolManager, q, &ret)
if err != nil {
return nil, errors.Wrapf(err, "db.FetchModelObjects")
}
return ret, nil
}
func (self *SCloudregion) SyncModelartsPools(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, exts []cloudprovider.ICloudModelartsPool) compare.SyncResult {
// 加锁防止重入
lockman.LockRawObject(ctx, ModelartsPoolManager.KeywordPlural(), fmt.Sprintf("%s-%s", provider.Id, self.Id))
defer lockman.ReleaseRawObject(ctx, ModelartsPoolManager.KeywordPlural(), fmt.Sprintf("%s-%s", provider.Id, self.Id))
result := compare.SyncResult{}
dbPools, err := self.GetPools(provider.Id)
if err != nil {
result.Error(err)
return result
}
removed := make([]SModelartsPool, 0)
commondb := make([]SModelartsPool, 0)
commonext := make([]cloudprovider.ICloudModelartsPool, 0)
added := make([]cloudprovider.ICloudModelartsPool, 0)
// 本地和云上资源列表进行比对
err = compare.CompareSets(dbPools, exts, &removed, &commondb, &commonext, &added)
if err != nil {
result.Error(err)
return result
}
// 删除云上没有的资源
for i := 0; i < len(removed); i++ {
err := removed[i].syncRemoveCloudModelartsPool(ctx, userCred)
if err != nil {
result.DeleteError(err)
continue
}
result.Delete()
}
// 和云上资源属性进行同步
for i := 0; i < len(commondb); i++ {
err := commondb[i].SyncWithCloudModelartsPool(ctx, userCred, commonext[i])
if err != nil {
result.UpdateError(err)
continue
}
result.Update()
}
// 创建本地没有的云上资源
for i := 0; i < len(added); i++ {
_, err := self.newFromCloudModelartsPool(ctx, userCred, provider, added[i])
if err != nil {
result.AddError(err)
continue
}
result.Add()
}
return result
}
// 判断资源是否可以删除
func (self *SModelartsPool) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
if self.DisableDelete.IsTrue() {
return httperrors.NewInvalidStatusError("ModelartsPool is locked, cannot delete")
}
return self.SStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
}
func (self *SModelartsPool) syncRemoveCloudModelartsPool(ctx context.Context, userCred mcclient.TokenCredential) error {
return self.RealDelete(ctx, userCred)
}
func (self *SModelartsPool) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
self.SVirtualResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
self.StartCreateTask(ctx, userCred, "")
}
func (self *SModelartsPool) StartCreateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
var err = func() error {
params := jsonutils.NewDict()
task, err := taskman.TaskManager.NewTask(ctx, "ModelartsPoolCreateTask", self, userCred, params, parentTaskId, "", nil)
if err != nil {
return errors.Wrapf(err, "NewTask")
}
return task.ScheduleRun(nil)
}()
if err != nil {
self.SetStatus(userCred, api.MODELARTS_POOL_STATUS_ERROR, err.Error())
return err
}
self.SetStatus(userCred, api.MODELARTS_POOL_STATUS_CREATING, "")
return nil
}
func (modelarts *SModelartsPool) PerformSyncstatus(
ctx context.Context,
userCred mcclient.TokenCredential,
query jsonutils.JSONObject,
input api.ModelartsPoolSyncstatusInput,
) (jsonutils.JSONObject, error) {
var openTask = true
count, err := taskman.TaskManager.QueryTasksOfObject(modelarts, time.Now().Add(-3*time.Minute), &openTask).CountWithError()
if err != nil {
return nil, err
}
if count > 0 {
return nil, httperrors.NewBadRequestError("ModelartsPool has %d task active, can't sync status", count)
}
return nil, StartResourceSyncStatusTask(ctx, userCred, modelarts, "ModelartsPoolSyncstatusTask", "")
}
func (self *SModelartsPool) StartSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
return StartResourceSyncStatusTask(ctx, userCred, self, "ModelartsPoolSyncstatusTask", parentTaskId)
}
func (self *SModelartsPool) GetCloudproviderId() string {
return self.ManagerId
}
func (self *SModelartsPool) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
return nil
}
func (self *SModelartsPool) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
return self.SVirtualResourceBase.Delete(ctx, userCred)
}
// 进入删除任务
func (self *SModelartsPool) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
return self.StartDeleteTask(ctx, userCred, "")
}
func (self *SModelartsPool) StartDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
task, err := taskman.TaskManager.NewTask(ctx, "ModelartsPoolDeleteTask", self, userCred, nil, parentTaskId, "", nil)
if err != nil {
return err
}
self.SetStatus(userCred, api.MODELARTS_POOL_STATUS_DELETING, "")
task.ScheduleRun(nil)
return nil
}
func (self *SModelartsPool) PerformChangeConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ModelartsPoolChangeConfigInput) (jsonutils.JSONObject, error) {
if input.NodeCount == self.NodeCount {
return nil, nil
}
return nil, self.StartChangeConfigTask(ctx, userCred, input)
}
func (self *SModelartsPool) StartChangeConfigTask(ctx context.Context, userCred mcclient.TokenCredential, input api.ModelartsPoolChangeConfigInput) error {
params := jsonutils.Marshal(input).(*jsonutils.JSONDict)
task, err := taskman.TaskManager.NewTask(ctx, "ModelartsPoolChangeConfigTask", self, userCred, params, "", "", nil)
if err != nil {
return err
}
self.SetStatus(userCred, api.MODELARTS_POOL_STATUS_CHANGE_CONFIG, "")
return task.ScheduleRun(nil)
}
func (self *SModelartsPool) GetIRegion() (cloudprovider.ICloudRegion, error) {
provider, err := self.GetDriver(context.Background())
if err != nil {
return nil, errors.Wrap(err, "self.GetDriver")
}
region, err := self.GetRegion()
if err != nil {
return nil, errors.Wrapf(err, "GetRegion")
}
iRegion, err := provider.GetIRegionById(region.ExternalId)
if err != nil {
return nil, errors.Wrapf(err, "provider.GetIRegionById")
}
return iRegion, nil
}
// 获取云上对应的资源
func (self *SModelartsPool) GetIModelartsPool() (cloudprovider.ICloudModelartsPool, error) {
if len(self.ExternalId) == 0 {
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "empty externalId")
}
iRegion, err := self.GetIRegion()
if err != nil {
return nil, errors.Wrap(err, "self.GetDriver")
}
return iRegion.GetIModelartsPoolById(self.ExternalId)
}
// 同步资源属性
func (self *SModelartsPool) SyncWithCloudModelartsPool(ctx context.Context, userCred mcclient.TokenCredential, ext cloudprovider.ICloudModelartsPool) error {
instanceName := ext.GetInstanceType()
sku := SModelartsPoolSku{}
err := ModelartsPoolSkuManager.Query().Equals("name", instanceName).First(&sku)
if err != nil {
return errors.Wrapf(err, "get modelartsPoolSku")
}
diff, err := db.UpdateWithLock(ctx, self, func() error {
self.Status = ext.GetStatus()
self.BillingType = ext.GetBillingType()
self.InstanceType = instanceName
self.WorkType = ext.GetWorkType()
self.CpuArch = sku.CpuArch
self.NodeCount = ext.GetNodeCount()
return nil
})
if err != nil {
return errors.Wrapf(err, "db.Update")
}
err = syncVirtualResourceMetadata(ctx, userCred, self, ext)
if err != nil {
return errors.Wrapf(err, "syncVirtualResourceMetadata")
}
if provider := self.GetCloudprovider(); provider != nil {
SyncCloudProject(userCred, self, provider.GetOwnerId(), ext, provider.Id)
}
db.OpsLog.LogSyncUpdate(self, diff, userCred)
return nil
}
func (self *SCloudregion) newFromCloudModelartsPool(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, ext cloudprovider.ICloudModelartsPool) (*SModelartsPool, error) {
pool := SModelartsPool{}
pool.SetModelManager(ModelartsPoolManager, &pool)
pool.ExternalId = ext.GetGlobalId()
pool.CloudregionId = self.Id
pool.ManagerId = provider.Id
pool.IsEmulated = ext.IsEmulated()
pool.Status = ext.GetStatus()
pool.WorkType = ext.GetWorkType()
pool.InstanceType = ext.GetInstanceType()
pool.NodeCount = ext.GetNodeCount()
if createdAt := ext.GetCreatedAt(); !createdAt.IsZero() {
pool.CreatedAt = createdAt
}
sku := SModelartsPoolSku{}
err := ModelartsPoolSkuManager.Query().Equals("Name", pool.InstanceType).First(&sku)
if err != nil {
return nil, errors.Wrapf(err, "ModelartsPoolSkuManager get cpuArch")
}
pool.CpuArch = sku.CpuArch
pool.BillingType = ext.GetBillingType()
if pool.BillingType == billing_api.BILLING_TYPE_PREPAID {
if expired := ext.GetExpiredAt(); !expired.IsZero() {
pool.ExpiredAt = expired
}
pool.AutoRenew = ext.IsAutoRenew()
}
err = func() error {
// 这里加锁是为了防止名称重复
lockman.LockRawObject(ctx, ModelartsPoolManager.Keyword(), "name")
defer lockman.ReleaseRawObject(ctx, ModelartsPoolManager.Keyword(), "name")
pool.Name, err = db.GenerateName(ctx, ModelartsPoolManager, provider.GetOwnerId(), ext.GetName())
if err != nil {
return errors.Wrapf(err, "db.GenerateName")
}
return ModelartsPoolManager.TableSpec().Insert(ctx, &pool)
}()
if err != nil {
return nil, errors.Wrapf(err, "newFromCloudModelartsPool.Insert")
}
// 同步标签
syncVirtualResourceMetadata(ctx, userCred, &pool, ext)
// 同步项目归属
SyncCloudProject(userCred, &pool, provider.GetOwnerId(), ext, provider.Id)
db.OpsLog.LogEvent(&pool, db.ACT_CREATE, pool.GetShortDesc(ctx), userCred)
return &pool, nil
}

View File

@@ -2149,3 +2149,39 @@ func (manager *STablestoreManager) purgeAll(ctx context.Context, userCred mcclie
}
return nil
}
func (manager *SModelartsPoolManager) purgeAll(ctx context.Context, userCred mcclient.TokenCredential, providerId string) error {
ess := []SModelartsPool{}
err := fetchByManagerId(manager, providerId, &ess)
if err != nil {
return errors.Wrapf(err, "fetchByManagerId")
}
for i := range ess {
lockman.LockObject(ctx, &ess[i])
defer lockman.ReleaseObject(ctx, &ess[i])
err := ess[i].RealDelete(ctx, userCred)
if err != nil {
return errors.Wrapf(err, "modelarts pool delete")
}
}
return nil
}
func (manager *SModelartsPoolSkuManager) purgeAll(ctx context.Context, userCred mcclient.TokenCredential, providerId string) error {
poolSku := []SModelartsPoolSku{}
err := fetchByManagerId(manager, providerId, &poolSku)
if err != nil {
return errors.Wrapf(err, "fetchByManagerId")
}
for i := range poolSku {
lockman.LockObject(ctx, &poolSku[i])
defer lockman.ReleaseObject(ctx, &poolSku[i])
err := poolSku[i].Delete(ctx, userCred)
if err != nil {
return errors.Wrapf(err, "modelarts pool delete")
}
}
return nil
}

View File

@@ -285,7 +285,9 @@ func (sa *SScalingAlarm) Register(ctx context.Context, userCred mcclient.TokenCr
if err != nil {
return errors.Wrap(err, "ScalingAlarm.generateAlertConfig")
}
alert, err := monitor.Alerts.DoCreate(session, config)
alert, err := monitor.CommonAlerts.DoCreate(session, config, &monapi.CommonAlertCreateBaseInput{
AlertType: monapi.CommonAlertServiceAlertType,
})
if err != nil {
return errors.Wrap(err, "create Alert failed")
}
@@ -359,7 +361,7 @@ func (sa *SScalingAlarm) generateAlertConfig(sp *SScalingPolicy) (*monitor.Alert
func (sa *SScalingAlarm) UnRegister(ctx context.Context, userCred mcclient.TokenCredential) error {
session := auth.GetSession(ctx, userCred, "")
_, err := monitor.Alerts.Delete(session, sa.AlarmId, jsonutils.NewDict())
if err != nil {
if err != nil && errors.Cause(err) != httperrors.ErrResourceNotFound {
return errors.Wrap(err, "Alerts.Delete")
}
err = sa.Delete(ctx, userCred)

View File

@@ -851,7 +851,7 @@ func (self *SSecurityGroupCache) SyncRules(ctx context.Context, skipSyncRule boo
}
iSecgroup, err := self.GetISecurityGroup(ctx)
if err != nil {
return errors.Wrapf(err, "GetOrCreateISecurityGroup")
return errors.Wrapf(err, "GetISecurityGroup")
}
if skipSyncRule {
return nil

View File

@@ -23,7 +23,6 @@ import (
"sort"
"strconv"
"strings"
"time"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
@@ -44,12 +43,9 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/mcclient/modules/scheduler"
"yunion.io/x/onecloud/pkg/util/hashcache"
"yunion.io/x/onecloud/pkg/util/stringutils2"
)
var Cache *hashcache.Cache
type SServerSkuManager struct {
db.SEnabledStatusStandaloneResourceBaseManager
SCloudregionResourceBaseManager
@@ -69,8 +65,6 @@ func init() {
}
ServerSkuManager.NameRequireAscii = false
ServerSkuManager.SetVirtualObject(ServerSkuManager)
Cache = hashcache.NewCache(2048, time.Second*300)
}
// SServerSku 实际对应的是instance type清单. 这里的Sku实际指的是instance type。
@@ -211,39 +205,10 @@ func genInstanceType(family string, cpu, memMb int64) (string, error) {
}
}
func skuRelatedGuestCount(self *SServerSku) (int, error) {
var q *sqlchemy.SQuery
if len(self.ZoneId) > 0 {
hostTable := HostManager.Query().SubQuery()
guestTable := GuestManager.Query().SubQuery()
q = guestTable.Query().Join(hostTable, sqlchemy.Equals(hostTable.Field("id"), guestTable.Field("host_id")))
q = q.Filter(sqlchemy.Equals(hostTable.Field("zone_id"), self.ZoneId))
} else {
q = GuestManager.Query()
}
q = q.Equals("instance_type", self.GetName())
return q.CountWithError()
}
func (self SServerSku) GetGlobalId() string {
return self.ExternalId
}
func (self *SServerSku) getTotalGuestCount() int {
// count
var count int
countKey := self.GetId() + ".total_guest_count"
v := Cache.Get(countKey)
if v == nil {
count, _ = skuRelatedGuestCount(self)
Cache.Set(countKey, count)
} else {
count = v.(int)
}
return count
}
func (manager *SServerSkuManager) FetchCustomizeColumns(
ctx context.Context,
userCred mcclient.TokenCredential,
@@ -257,16 +222,67 @@ func (manager *SServerSkuManager) FetchCustomizeColumns(
stdRows := manager.SEnabledStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
regRows := manager.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
zoneRows := manager.SZoneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
instanceTypes := []string{}
for i := range rows {
rows[i] = api.ServerSkuDetails{
EnabledStatusStandaloneResourceDetails: stdRows[i],
ZoneResourceInfoBase: zoneRows[i].ZoneResourceInfoBase,
CloudregionResourceInfo: regRows[i],
}
sku := objs[i].(*SServerSku)
if !utils.IsInStringArray(sku.Name, instanceTypes) {
instanceTypes = append(instanceTypes, sku.Name)
}
rows[i].CloudEnv = strings.Split(zoneRows[i].RegionExternalId, "/")[0]
rows[i].TotalGuestCount = objs[i].(*SServerSku).getTotalGuestCount()
}
ret := []struct {
InstanceType string
CloudregionId string
ZoneId string
}{}
guestsQ := GuestManager.Query().SubQuery()
hostsQ := HostManager.Query().SubQuery()
zonesQ := ZoneManager.Query().SubQuery()
q := guestsQ.Query(
guestsQ.Field("instance_type"),
hostsQ.Field("zone_id"),
zonesQ.Field("cloudregion_id"),
).
Join(hostsQ, sqlchemy.Equals(guestsQ.Field("host_id"), hostsQ.Field("id"))).
Join(zonesQ, sqlchemy.Equals(hostsQ.Field("zone_id"), zonesQ.Field("id"))).
Filter(sqlchemy.In(guestsQ.Field("instance_type"), instanceTypes))
err := q.All(&ret)
if err != nil {
log.Errorf("query instance cnt error: %v", err)
return rows
}
skuMap := map[string]map[string]int{}
for _, sku := range ret {
_, ok := skuMap[sku.InstanceType]
if !ok {
skuMap[sku.InstanceType] = map[string]int{}
}
_, ok = skuMap[sku.InstanceType][sku.ZoneId]
if !ok {
skuMap[sku.InstanceType][sku.ZoneId] = 0
}
skuMap[sku.InstanceType][sku.ZoneId] += 1
_, ok = skuMap[sku.InstanceType][sku.CloudregionId]
if !ok {
skuMap[sku.InstanceType][sku.CloudregionId] = 0
}
skuMap[sku.InstanceType][sku.CloudregionId] += 1
}
for i := range rows {
sku := objs[i].(*SServerSku)
if len(sku.ZoneId) > 0 {
rows[i].TotalGuestCount = skuMap[sku.Name][sku.ZoneId]
} else {
rows[i].TotalGuestCount = skuMap[sku.Name][sku.CloudregionId]
}
}
return rows
@@ -623,12 +639,8 @@ func (self *SServerSku) StartServerSkuDeleteTask(ctx context.Context, userCred m
return nil
}
func (self *SServerSku) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
serverCount, err := skuRelatedGuestCount(self)
if err != nil {
return httperrors.NewInternalServerError("check instance")
}
if serverCount > 0 {
func (self *SServerSku) ValidateDeleteCondition(ctx context.Context, info *api.ServerSkuDetails) error {
if info.TotalGuestCount > 0 {
return httperrors.NewNotEmptyError("now allow to delete inuse instance_type.please remove related servers first: %s", self.Name)
}

View File

@@ -1532,6 +1532,14 @@ func (manager *SStorageManager) ListItemFilter(
q = q.In("id", sq.SubQuery())
}
if query.IsBaremetal != nil {
qf := q.NotEquals
if *query.IsBaremetal {
qf = q.Equals
}
q = qf("storage_type", api.STORAGE_BAREMETAL)
}
return q, err
}

View File

@@ -15,6 +15,8 @@
package options
import (
"yunion.io/x/log"
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
"yunion.io/x/onecloud/pkg/cloudcommon/pending_delete"
"yunion.io/x/onecloud/pkg/multicloud/esxi"
@@ -185,10 +187,13 @@ type ComputeOptions struct {
DefaultIPAllocationDirection string `help:"default IP allocation direction" default:"stepdown"`
// 弹性伸缩中的ecs一般会有特殊的系统标签通过指定这些标签可以忽略这部分ecs的同步, 指定多个key需要以 ',' 分隔
SkipServerBySysTagKeys string `help:"skip server sync and create with system tags" default:"acs:autoscaling:scalingGroupId"`
SkipServerBySysTagKeys string `help:"skip server sync and create with system tags" default:"acs:autoscaling:scalingGroupId"`
SkipServerByUserTagKeys string `help:"skip server sync and create with user tags" default:""`
EnableAwsMonitorAgent bool `help:"enable aws monitor agent" default:"true"`
EnableTlsMigration bool `help:"Enable TLS migration" default:"false"`
esxi.EsxiOptions
}
@@ -228,6 +233,9 @@ func OnOptionsChange(oldO, newO interface{}) bool {
changed = true
}
}
if oldOpts.EnableTlsMigration != newOpts.EnableTlsMigration {
log.Debugf("enable_tls_migration changed from %v to %v", oldOpts.EnableTlsMigration, newOpts.EnableTlsMigration)
}
return changed
}

Some files were not shown because too many files have changed in this diff Show More