Completed
Pull Request — master (#513)
by
unknown
03:15
created

GetVMConsoleUrls.run()   B

Complexity

Conditions 3

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
c 0
b 0
f 0
dl 0
loc 27
rs 8.8571
1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
from vmwarelib.actions import BaseAction
17
18
19
class GetVMConsoleUrls(BaseAction):
20
21
    def run(self, vm_ids, vsphere=None):
22
23
        self.establish_connection(vsphere)
24
25
        meta_url_template =\
26
            'https://{host}:{port}/vsphere-client/vmrc/vmrc.jsp?'\
27
            'vm=urn:vmomi:VirtualMachine:{{vm}}:{si_uuid}'
28
29
        si_uuid = self.si_content.about.instanceUuid
30
        if vsphere:
31
            connection = self.config['vsphere'].get(vsphere)
32
        else:
33
            connection = self.config
34
35
        host = connection['host']
36
        port = connection['port']
37
38
        vm_url_template = meta_url_template.format(
39
            host=host, port=port, si_uuid=si_uuid)
40
41
        vm_moids = vm_ids
42
        vms_console_urls = [
43
            {moid: {'url': vm_url_template.format(vm=moid)}}
44
            for moid in vm_moids
45
        ]
46
47
        return vms_console_urls
48