Skip to content

Commit 24bd0be

Browse files
Added redirect url for MaaS instance page
1 parent 79e2bb7 commit 24bd0be

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

extensions/MaaS/maas.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,15 @@ def prepare(self):
139139
if json_data.get("cloudstack.vm.details", {}).get("nics"):
140140
json_data["cloudstack.vm.details"]["nics"][0]["mac"] = mac
141141

142+
console_url = f"http://{self.data['endpoint'].replace('http://','').replace('https://','')}:5240/MAAS/r/machine/{system_id}/summary"
143+
142144
result = {
143145
"nics": json_data["cloudstack.vm.details"]["nics"],
144146
"details": {
145147
"External:mac_address": mac,
146148
"External:maas_system_id": system_id,
147149
"External:hostname": hostname,
150+
"External:console_url": console_url,
148151
},
149152
}
150153
succeed(result)

ui/src/components/view/ActionButton.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<template>
1919
<span class="row-action-button">
20-
<a-tooltip arrowPointAtCenter placement="bottomRight" v-if="resource && resource.id && dataView && resource.hypervisor !== 'External'">
20+
<a-tooltip arrowPointAtCenter placement="bottomRight" v-if="resource && resource.id && dataView">
2121
<template #title>
2222
{{ $t('label.view.console') }}
2323
</template>
@@ -29,7 +29,7 @@
2929
icon="code"
3030
/>
3131
</a-tooltip>
32-
<a-tooltip arrowPointAtCenter placement="bottomRight" v-if="resource && resource.id && dataView && resource.hypervisor !== 'External'">
32+
<a-tooltip arrowPointAtCenter placement="bottomRight" v-if="resource && resource.id && dataView">
3333
<template #title>
3434
{{ $t('label.copy.consoleurl') }}
3535
</template>

ui/src/components/widgets/Console.vue

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@
1717

1818
<template>
1919
<a
20-
v-if="['vm', 'systemvm', 'router', 'ilbvm', 'vnfapp'].includes($route.meta.name) && 'listVirtualMachines' in $store.getters.apis && 'createConsoleEndpoint' in $store.getters.apis"
20+
v-if="['vm', 'systemvm', 'router', 'ilbvm', 'vnfapp'].includes($route.meta.name) &&
21+
'listVirtualMachines' in $store.getters.apis &&
22+
'createConsoleEndpoint' in $store.getters.apis"
2123
@click="consoleUrl">
22-
<a-button style="margin-left: 5px" shape="circle" type="dashed" :size="size" :disabled="['Stopped', 'Restoring', 'Error', 'Destroyed'].includes(resource.state) || resource.hostcontrolstate === 'Offline'" >
24+
<a-button
25+
style="margin-left: 5px"
26+
shape="circle"
27+
type="dashed"
28+
:size="size"
29+
:disabled="['Stopped', 'Restoring', 'Error', 'Destroyed'].includes(resource.state) ||
30+
resource.hostcontrolstate === 'Offline'">
2331
<code-outlined v-if="!copyUrlToClipboard"/>
2432
<copy-outlined v-else />
2533
</a-button>
@@ -49,11 +57,29 @@ export default {
4957
}
5058
},
5159
methods: {
52-
consoleUrl () {
53-
const params = {}
54-
params.virtualmachineid = this.resource.id
55-
postAPI('createConsoleEndpoint', params).then(json => {
56-
this.url = (json && json.createconsoleendpointresponse) ? json.createconsoleendpointresponse.consoleendpoint.url : '#/exception/404'
60+
async consoleUrl () {
61+
try {
62+
const externalUrl = this.resource?.details?.['External:console_url']
63+
if (externalUrl) {
64+
this.url = externalUrl
65+
if (this.copyUrlToClipboard) {
66+
this.$copyText(this.url)
67+
this.$message.success({
68+
content: this.$t('label.copied.clipboard')
69+
})
70+
} else {
71+
window.open(this.url, '_blank')
72+
}
73+
return
74+
}
75+
76+
const params = { virtualmachineid: this.resource.id }
77+
const json = await postAPI('createConsoleEndpoint', params)
78+
79+
this.url = (json && json.createconsoleendpointresponse)
80+
? json.createconsoleendpointresponse.consoleendpoint.url
81+
: '#/exception/404'
82+
5783
if (json.createconsoleendpointresponse.consoleendpoint.success) {
5884
if (this.copyUrlToClipboard) {
5985
this.$copyText(this.url)
@@ -69,9 +95,9 @@ export default {
6995
description: json.createconsoleendpointresponse.consoleendpoint.details
7096
})
7197
}
72-
}).catch(error => {
98+
} catch (error) {
7399
this.$notifyError(error)
74-
})
100+
}
75101
}
76102
},
77103
computed: {

0 commit comments

Comments
 (0)