webconsole.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import i18n from '@/locales'
  2. import store from '@/store'
  3. export function solWebConsole (manager, host, onData, createDialog) {
  4. var hostId = host.host_id // if it is a baremetal server
  5. if (!hostId) {
  6. hostId = host.id
  7. }
  8. return {
  9. label: i18n.t('compute.text_342'),
  10. permission: 'hosts_get_ipmi',
  11. action: () => {
  12. const success = () => {
  13. manager.objectRpc({
  14. methodname: 'DoBaremetalConnect',
  15. objId: hostId,
  16. }).then(({ data }) => {
  17. onData(host, { ...data, extra_param_str: `&instance_name=SOL ${host.name}&ips=${host.ips}` })
  18. })
  19. }
  20. if (store.getters.userInfo.enable_mfa && store.state.auth.auth.system_totp_on && createDialog) {
  21. createDialog('SecretVertifyDialog', {
  22. success,
  23. })
  24. } else {
  25. success()
  26. }
  27. },
  28. meta: () => {
  29. const ret = {
  30. validate: host.status === 'running',
  31. }
  32. return ret
  33. },
  34. }
  35. }
  36. export function jnlpConsole (manager, host, createDialog) {
  37. return {
  38. label: i18n.t('compute.text_351'),
  39. action: () => {
  40. const success = () => {
  41. manager.getSpecific({
  42. id: host.id,
  43. spec: 'jnlp',
  44. }).then(res => {
  45. const blob = new Blob([res.data.jnlp], { type: 'application/x-java-jnlp-file' })
  46. const url = window.URL.createObjectURL(blob)
  47. const fileName = `${host.name}.jnlp`
  48. const linkDom = document.createElement('a')
  49. linkDom.href = url
  50. linkDom.setAttribute('download', fileName)
  51. document.body.appendChild(linkDom)
  52. linkDom.click()
  53. document.body.removeChild(linkDom)
  54. window.URL.revokeObjectURL(url)
  55. })
  56. }
  57. if (store.getters.userInfo.enable_mfa && store.state.auth.auth.system_totp_on && createDialog) {
  58. createDialog('SecretVertifyDialog', {
  59. success,
  60. })
  61. } else {
  62. success()
  63. }
  64. },
  65. }
  66. }