index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <base-side-page
  3. @cancel="cancelSidePage"
  4. :title="$t('compute.vminstance-container')"
  5. icon="res-vminstance"
  6. :res-name="detailData.name"
  7. :current-tab="params.windowData.currentTab"
  8. :tabs="filterDetailTabs"
  9. :loaded="loaded"
  10. @tab-change="handleTabChange">
  11. <template v-slot:actions>
  12. <actions
  13. :options="singleActions"
  14. :row="detailData"
  15. :before-show-menu="beforeShowMenu"
  16. button-type="link"
  17. button-size="small" />
  18. </template>
  19. <component
  20. v-bind="listActives"
  21. :is="params.windowData.currentTab"
  22. :data="componentData"
  23. :serverColumns="columns"
  24. :res-id="data.id"
  25. :monitor-res-id="data.id"
  26. :id="listId"
  27. :getParams="componentParams"
  28. :on-manager="onManager"
  29. :show-create-action="false"
  30. :isPageDestroyed="isPageDestroyed"
  31. taskResource="compute-tasks"
  32. @refresh="refresh"
  33. @single-refresh="singleRefresh"
  34. @tab-change="handleTabChange" />
  35. </base-side-page>
  36. </template>
  37. <script>
  38. import * as R from 'ramda'
  39. import SidePageMixin from '@/mixins/sidePage'
  40. import WindowsMixin from '@/mixins/windows'
  41. import Actions from '@/components/PageList/Actions'
  42. import GpuList from '@Compute/views/gpu/components/List'
  43. import ContainerList from '@Compute/views/pod-container/components/List'
  44. import Detail from './Detail'
  45. import SecgroupList from './Secgroup'
  46. // import Terminal from './Terminal'
  47. import NetworkList from './Network'
  48. import DiskList from './DiskList'
  49. import Monitor from './Monitor'
  50. // import Alert from './Alert'
  51. import SingleActionsMixin from '../mixins/singleActions'
  52. import ColumnsMixin from '../mixins/columns'
  53. export default {
  54. name: 'VmContainerInstanceSidePage',
  55. components: {
  56. Actions,
  57. Detail,
  58. ContainerList,
  59. NetworkList,
  60. DiskList,
  61. SecgroupList,
  62. Monitor,
  63. GpuList,
  64. // Alert,
  65. // Terminal,
  66. },
  67. mixins: [SidePageMixin, WindowsMixin, ColumnsMixin, SingleActionsMixin],
  68. data () {
  69. let detailTabs = [
  70. { label: this.$t('compute.text_238'), key: 'detail' },
  71. { label: this.$t('compute.container', []), key: 'container-list' },
  72. { label: this.$t('compute.text_105'), key: 'secgroup-list' },
  73. { label: this.$t('compute.text_104'), key: 'network-list' },
  74. { label: this.$t('compute.text_376'), key: 'disk-list' },
  75. { label: this.$t('compute.text_113'), key: 'gpu-list' },
  76. { label: this.$t('compute.text_608'), key: 'monitor' },
  77. // { label: this.$t('compute.text_1301'), key: 'alert' },
  78. { label: this.$t('table.title.task'), key: 'task-drawer' },
  79. // { label: this.$t('compute.repo.terminal'), key: 'terminal' },
  80. { label: this.$t('compute.text_240'), key: 'event-drawer' },
  81. ]
  82. if (this.$store.getters.isProjectMode) {
  83. detailTabs = R.remove(R.findIndex(R.propEq('key', 'gpu-list'))(detailTabs), 1, detailTabs)
  84. }
  85. return {
  86. detailTabs,
  87. agent_status: '',
  88. agent_fail_reason: '',
  89. agent_fail_code: '',
  90. isPageDestroyed: false,
  91. }
  92. },
  93. computed: {
  94. componentParams () {
  95. const tabs = ['secgroup-list', 'disk-list']
  96. if (this.params.windowData.currentTab === 'task-drawer') {
  97. return {
  98. is_root: true,
  99. }
  100. }
  101. if (tabs.includes(this.params.windowData.currentTab)) {
  102. return {
  103. detail: true,
  104. server: this.detailData.id,
  105. }
  106. }
  107. if (this.params.windowData.currentTab === 'host-list') {
  108. return {
  109. detail: true,
  110. id: this.detailData.host_id,
  111. }
  112. }
  113. if (this.params.windowData.currentTab === 'network-list') {
  114. return {
  115. associate_id: this.detailData.id,
  116. detail: true,
  117. }
  118. }
  119. if (this.params.windowData.currentTab === 'gpu-list') {
  120. return {
  121. guest_id: this.data.id,
  122. }
  123. }
  124. return null
  125. },
  126. secgroupListActives () {
  127. // const me = this
  128. const _ = {
  129. frontGroupActions: function () {
  130. return [
  131. // {
  132. // index: 1,
  133. // label: this.$t('compute.text_1116'),
  134. // permission: 'server_perform_add_secgroup',
  135. // action: () => {
  136. // this.createDialog('VmSetSecgroupDialog', {
  137. // vm: me,
  138. // data: [me.detailData],
  139. // columns: me.columns,
  140. // onManager: me.onManager,
  141. // refresh: () => {
  142. // this.refresh()
  143. // },
  144. // })
  145. // },
  146. // meta: () => {
  147. // const ret = {
  148. // validate: cloudEnabled('assignSecgroup', me.detailData),
  149. // tooltip: cloudUnabledTip('assignSecgroup', me.detailData),
  150. // }
  151. // return ret
  152. // },
  153. // hidden: this.$isScopedPolicyMenuHidden('vminstance_hidden_menus.server_perform_add_secgroup'),
  154. // },
  155. ]
  156. },
  157. }
  158. return _
  159. },
  160. listActives () {
  161. const _ = {
  162. 'secgroup-list': this.secgroupListActives,
  163. }
  164. return _[this.params.windowData.currentTab] || {}
  165. },
  166. listId () {
  167. switch (this.params.windowData.currentTab) {
  168. case 'network-list':
  169. return 'NetworkListForVmContainerInstanceSidePage'
  170. case 'disk-list':
  171. return 'DiskLiskForVmContainerInstanceSidePage'
  172. case 'secgroup-list':
  173. return 'SecgroupLiskForVmContainerInstanceSidePage'
  174. case 'event-drawer':
  175. return 'EventListForVmContainerInstanceSidePage'
  176. case 'gpu-list':
  177. return 'GpuListForVmContainerInstanceSidePage'
  178. case 'container-list':
  179. return 'ContainerListForVmContainerInstanceSidePage'
  180. default:
  181. return ''
  182. }
  183. },
  184. componentData () {
  185. return Object.assign({}, this.detailData, { agent_status: this.agent_status, agent_fail_reason: this.agent_fail_reason, agent_fail_code: this.agent_fail_code })
  186. },
  187. hiddenColumns () {
  188. if (this.params.windowData.currentTab === 'scheduledtasks-list') {
  189. return ['resource_type', 'labels']
  190. }
  191. return []
  192. },
  193. hiddenSingleActions () {
  194. return this.params.windowData.currentTab === 'scheduledtasks-list'
  195. },
  196. filterDetailTabs () {
  197. return this.detailTabs.map(item => {
  198. if (!this.detailData.id) {
  199. return {
  200. ...item,
  201. disabled: true,
  202. }
  203. }
  204. if (item.key === 'terminal' && this.detailData.status !== 'running') {
  205. return {
  206. ...item,
  207. disabled: true,
  208. }
  209. }
  210. return item
  211. })
  212. },
  213. },
  214. created () {
  215. this.initChangeTab()
  216. this.$bus.$on('agentStatusQuery', (val) => {
  217. if (this.agent_status === 'failed') {
  218. this.agent_status = 'applying'
  219. }
  220. this.handleInstallTask({
  221. script_apply_id: val,
  222. })
  223. })
  224. },
  225. beforeDestroy () {
  226. this.isPageDestroyed = true
  227. },
  228. methods: {
  229. initHiddenTab () {
  230. if (this.listRowData.brand !== 'OneCloud') {
  231. this.detailTabs = R.remove(R.findIndex(R.propEq('key', 'gpu-list'))(this.detailTabs), 1, this.detailTabs)
  232. }
  233. },
  234. initChangeTab () {
  235. if (this.params.tab) {
  236. this.handleTabChange(this.params.tab)
  237. }
  238. },
  239. async fetchDataCallback () {
  240. try {
  241. if (!this.data.data) return
  242. const { data: { data = [] } } = await new this.$Manager('scriptapplyrecords').list({ params: { server_id: this.data.data.id, details: false, limit: 1 } })
  243. if (data[0]) {
  244. this.agent_status = data[0].status
  245. if (data[0].status === 'applying') {
  246. if (!this.componentData.id) return
  247. this.handleInstallTask({
  248. server_id: this.componentData.id,
  249. details: false,
  250. limit: 1,
  251. })
  252. } else if (data[0].status === 'failed') {
  253. this.agent_fail_reason = data[0].reason
  254. this.agent_fail_code = data[0].fail_code || ''
  255. }
  256. }
  257. } catch (e) { }
  258. },
  259. beforeShowMenu () {
  260. return this.$store.dispatch('scopedPolicy/get', {
  261. category: ['vminstance_hidden_menus', 'vminstance_configured_callback_address', 'disk_hidden_menus'],
  262. })
  263. },
  264. async handleInstallTask (params) {
  265. try {
  266. let maxTry = 60
  267. while (maxTry > 0) {
  268. if (this.isPageDestroyed) {
  269. break
  270. }
  271. const { data: { data = [] } } = await new this.$Manager('scriptapplyrecords').list({ params: params })
  272. if (data[0]) {
  273. if (data[0].status === 'succeed' || data[0].status === 'failed') {
  274. this.agent_status = data[0].status
  275. this.agent_fail_reason = data[0].reason
  276. this.agent_fail_code = data[0].fail_code || ''
  277. break
  278. }
  279. }
  280. maxTry -= 1
  281. await new Promise(resolve => setTimeout(resolve, 6000))
  282. }
  283. } catch (e) { }
  284. },
  285. handleOpenSidepage (row, tab) {
  286. this.handleTabChange(tab)
  287. },
  288. },
  289. }
  290. </script>