| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 |
- import { mapGetters } from 'vuex'
- // import { Base64 } from 'js-base64'
- import qs from 'qs'
- import expectStatus from '@/constants/expectStatus'
- import { getDomainChangeOwnerAction, getSetPublicAction, getEnabledSwitchActions } from '@/utils/common/tableActions'
- import i18n from '@/locales'
- import { SMART_SSH_FORM_DECORATORS } from '@Compute/constants'
- import { canIpmiProbe } from '../utils/status'
- import { solWebConsole, jnlpConsole } from '../../../utils/webconsole'
- export default {
- destroyed () {
- this.manager = null
- },
- computed: {
- ...mapGetters(['userInfo', 'auth', 'common']),
- enableMFA () {
- return this.userInfo.enable_mfa && this.auth.auth.system_totp_on
- },
- enableWaterMark () {
- const { globalConfig = {} } = this.common
- const { enable_watermark = true } = globalConfig
- return enable_watermark
- },
- },
- created () {
- this.webconsoleManager = new this.$Manager('webconsole', 'v1')
- this.singleActions = [
- {
- label: i18n.t('compute.text_567'),
- permission: 'hosts_perform_login_info',
- actions: obj => {
- const ret = []
- if (obj.host_type === 'baremetal') {
- ret.push(solWebConsole(this.webconsoleManager, obj, this.openWebConsole, this.createDialog))
- }
- let ips = (obj.server_ips || '').split(',').filter(item => !!item)
- if (obj.access_ip) {
- ips = [obj.access_ip, ...ips]
- }
- const openWebConsole = (params) => {
- this.webconsoleManager.performAction(params).then(({ data }) => {
- const connectParams = qs.parse(data.connect_params)
- // 验证账号密码
- if (connectParams.is_need_login === 'true') {
- this.createDialog('SshAuthDialog', {
- manager: this.webconsoleManager,
- params,
- errorMsg: connectParams.login_error_message,
- data: { name: obj.name, ip: params.action },
- success: (data) => {
- this.openWebConsole(obj, data, 'ws')
- },
- })
- return
- }
- // 无需验证账号密码
- this.openWebConsole(obj, data, 'ws')
- })
- }
- const actionGenerator = ip => {
- return (_) => {
- const success = () => {
- const params = {
- action: ip,
- data: {},
- id: 'ssh',
- }
- openWebConsole(params)
- }
- if (this.enableMFA) {
- this.createDialog('SecretVertifyDialog', {
- success,
- })
- } else {
- success()
- }
- }
- }
- Array.from(new Set(ips)).forEach(ip => {
- const meta = () => ({ validate: true })
- ret.push({
- label: `SSH ${ip}`,
- action: actionGenerator(ip),
- meta,
- render: (obj, params, h) => {
- let styleObj = {
- padding: '0 10px',
- fontSize: '12px',
- }
- const isRunning = obj.status === 'running'
- if (!isRunning) {
- styleObj = {
- ...styleObj,
- cursor: 'not-allowed',
- color: 'rgba(0, 0, 0, 0.25)',
- }
- }
- const sshConnectHandle = () => {
- const success = () => {
- openWebConsole({
- action: ip,
- data: {},
- id: 'ssh',
- })
- }
- if (this.enableMFA) {
- this.createDialog('SecretVertifyDialog', {
- success,
- })
- } else {
- success()
- }
- }
- const sshSettingInfoHandle = () => {
- this.createDialog('SmartFormDialog', {
- title: i18n.t('compute.custom_ssh_connect', ['SSH']),
- data: [obj],
- callback: async (data) => {
- const pms = {
- action: ip,
- data: { port: data.port, username: data.username, password: data.password },
- id: 'ssh',
- }
- openWebConsole(pms)
- },
- decorators: SMART_SSH_FORM_DECORATORS,
- })
- }
- return <a-tooltip placement="left" title={!isRunning ? i18n.t('compute.text_1282') : ''}>
- <span style={styleObj} class='d-flex justify-content-between align-items-center'>
- <span onClick={isRunning ? sshConnectHandle : () => { }}>{`SSH ${ip}`}</span>
- {
- isRunning ? <span>
- <a-tooltip title={i18n.t('compute.custom_ssh_connect', ['SSH'])}>
- <a-icon class="ml-2" type="edit" onClick={isRunning ? sshSettingInfoHandle : () => { }} />
- </a-tooltip>
- </span> : null
- }
- </span>
- </a-tooltip>
- },
- })
- })
- ret.push({ ...jnlpConsole(new this.$Manager('hosts', 'v2'), obj, this.createDialog), permission: 'server_get_jnlp' })
- return ret
- },
- },
- {
- label: i18n.t('compute.text_352'),
- actions: (obj) => {
- return [
- ...getEnabledSwitchActions(Object.assign({}, this, { resource: 'physicalmachine' }), obj, ['hosts_perform_enable', 'hosts_perform_disable'], { resourceName: this.$t('dictionary.physicalmachine') }),
- {
- label: i18n.t('compute.text_541'),
- permission: 'hosts_perform_set_schedtag',
- action: () => {
- this.createDialog('HostsAdjustLabelDialog', {
- data: [obj],
- columns: this.columns,
- name: this.$t('dictionary.physicalmachine'),
- })
- },
- },
- {
- label: i18n.t('compute.perform_sync_status'),
- permission: 'hosts_perform_syncstatus',
- action: () => {
- this.onManager('performAction', {
- id: obj.id,
- steadyStatus: Object.values(expectStatus.host).flat(),
- managerArgs: {
- action: 'syncstatus',
- },
- })
- },
- meta: () => {
- if (obj.status === 'ready') {
- return {
- validate: false,
- tooltip: i18n.t('compute.text_850'),
- }
- }
- return {
- validate: true,
- }
- },
- },
- getDomainChangeOwnerAction(this, {
- name: this.$t('dictionary.physicalmachine'),
- resource: 'hosts',
- }, {
- permission: 'hosts_perform_change_owner',
- }),
- getSetPublicAction(this, {
- name: this.$t('dictionary.physicalmachine'),
- scope: 'domain',
- resource: 'hosts',
- }, {
- permission: 'hosts_perform_public',
- }),
- {
- label: i18n.t('compute.text_298'),
- permission: 'server_create',
- action: () => {
- let wire_id = ''
- if (obj.nic_info) {
- const arr = obj.nic_info.filter(item => {
- return item.nic_type !== 'ipmi' && item.wire_id
- })
- arr.map(item => {
- wire_id += `${item.wire_id},`
- })
- wire_id = wire_id.substr(0, wire_id.length - 1)
- }
- this.$router.push({
- path: '/baremetal/create',
- query: {
- id: obj.id,
- type: 'baremetal',
- zone_id: obj.zone_id,
- host_id: obj.id,
- region_id: obj.cloudregion_id,
- domain_id: obj.domain_id,
- wire_id,
- cloud_env: obj.cloud_env || 'onpremise',
- },
- })
- },
- meta: () => {
- if (!obj.is_baremetal) {
- return {
- validate: false,
- }
- }
- if (obj.host_type !== 'baremetal') {
- return {
- validate: false,
- }
- }
- if (obj.server_id) {
- return {
- validate: false,
- }
- }
- if (!obj.enabled) {
- return {
- validate: false,
- tooltip: i18n.t('compute.text_851'),
- }
- }
- if (['running', 'ready'].indexOf(obj.status) < 0) {
- return {
- validate: false,
- tooltip: i18n.t('compute.text_852'),
- }
- }
- return {
- validate: true,
- }
- },
- },
- {
- label: i18n.t('compute.text_828'),
- permission: 'hosts_perform_convert_hypervisor',
- action: () => {
- this.createDialog('HostsConvertDialog', {
- data: [obj],
- columns: this.columns,
- onManager: this.onManager,
- refresh: this.refresh,
- })
- },
- meta: () => {
- if (!obj.is_baremetal) {
- return {
- validate: false,
- }
- }
- if (obj.host_type !== 'baremetal') {
- return {
- validate: false,
- }
- }
- if (obj.server_id) {
- return {
- validate: false,
- }
- }
- if (!obj.enabled) {
- return {
- validate: false,
- tooltip: i18n.t('compute.text_851'),
- }
- }
- if (['running', 'ready'].indexOf(obj.status) < 0) {
- return {
- validate: false,
- tooltip: i18n.t('compute.text_852'),
- }
- }
- if (obj.spec && !obj.spec.disk) {
- return {
- validate: false,
- tooltip: i18n.t('compute.host_convert'),
- }
- }
- return {
- validate: true,
- }
- },
- },
- {
- label: i18n.t('compute.host_ipmi_probe'),
- permission: 'hosts_perform_ipmi_probe',
- action: () => {
- this.onManager('performAction', {
- id: obj.id,
- steadyStatus: Object.values(expectStatus.host).flat(),
- managerArgs: {
- action: 'ipmi-probe',
- },
- })
- },
- meta: () => ({ validate: canIpmiProbe(obj) }),
- },
- {
- label: i18n.t('compute.host_prepare'),
- permission: 'hosts_perform_prepare',
- action: () => {
- this.onManager('performAction', {
- id: obj.id,
- steadyStatus: Object.values(expectStatus.host).flat(),
- managerArgs: {
- action: 'prepare',
- },
- })
- },
- meta: () => ({ validate: obj.can_prepare }),
- },
- {
- label: i18n.t('compute.text_272'),
- permission: 'hosts_perform_start',
- action: () => {
- this.onManager('performAction', {
- id: obj.id,
- steadyStatus: Object.values(expectStatus.host).flat(),
- managerArgs: {
- action: 'start',
- },
- })
- },
- meta: () => {
- if (obj.server_id && obj.host_type === 'baremetal') {
- return {
- validate: false,
- }
- }
- return {
- validate: obj.status === 'ready',
- }
- },
- },
- {
- label: i18n.t('compute.text_273'),
- permission: 'hosts_perform_stop',
- action: () => {
- this.onManager('performAction', {
- id: obj.id,
- steadyStatus: Object.values(expectStatus.host).flat(),
- managerArgs: {
- action: 'stop',
- },
- })
- },
- meta: () => {
- if (!obj.is_baremetal) {
- return {
- validate: false,
- }
- }
- if (obj.server_id && obj.host_type === 'baremetal') {
- return {
- validate: false,
- }
- }
- if (obj.status !== 'running') {
- return {
- validate: false,
- }
- }
- return {
- validate: true,
- }
- },
- },
- {
- label: i18n.t('compute.text_550'),
- permission: 'hosts_perform_maintenance',
- action: () => {
- this.onManager('performAction', {
- id: obj.id,
- steadyStatus: Object.values(expectStatus.host).flat(),
- managerArgs: {
- action: 'maintenance',
- },
- })
- },
- meta: () => {
- if (obj.server) {
- return {
- validate: false,
- }
- }
- if (!obj.is_baremetal) {
- return {
- validate: false,
- }
- }
- if (!obj.server_id) {
- return {
- validate: false,
- }
- }
- if (obj.is_maintenance) {
- return {
- validate: false,
- }
- }
- if (['running', 'ready'].indexOf(obj.status) < 0) {
- return {
- validate: false,
- tooltip: i18n.t('compute.text_853'),
- }
- }
- return {
- validate: true,
- }
- },
- },
- {
- label: i18n.t('compute.text_559'),
- permission: 'hosts_perform_unmaintenance',
- action: () => {
- this.onManager('performAction', {
- id: obj.id,
- steadyStatus: Object.values(expectStatus.host).flat(),
- managerArgs: {
- action: 'unmaintenance',
- },
- })
- },
- meta: () => {
- if (obj.server) {
- return {
- validate: false,
- }
- }
- if (!obj.is_baremetal) {
- return {
- validate: false,
- }
- }
- if (!obj.server_id) {
- return {
- validate: false,
- }
- }
- if (!obj.is_maintenance) {
- return {
- validate: false,
- }
- }
- if (['running', 'ready'].indexOf(obj.status) < 0) {
- return {
- validate: false,
- tooltip: i18n.t('compute.text_853'),
- }
- }
- return {
- validate: true,
- }
- },
- },
- {
- label: i18n.t('compute.perform_delete'),
- permission: 'hosts_delete',
- action: () => {
- this.createDialog('DeleteResDialog', {
- name: this.$t('dictionary.physicalmachine'),
- vm: this,
- data: [obj],
- columns: this.columns,
- onManager: this.onManager,
- title: i18n.t('compute.perform_delete'),
- })
- },
- meta: () => {
- return {
- validate: this.$getDeleteResult(obj).validate,
- tooltip: this.$getDeleteResult(obj).validate ? '' : i18n.t('compute.text_854'),
- }
- },
- },
- ]
- },
- },
- ]
- },
- methods: {
- openWebConsole (obj, data, protocol) {
- this.$openWebConsole(data)
- },
- },
- }
|