Completed
Pull Request — master (#460)
by Manas
02:13
created

GetVMConsoleUrls   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %
Metric Value
wmc 2
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 18 2
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, vms):
22
        meta_url_template = 'https://{host}:{port}/vsphere-client/vmrc/vmrc.jsp?' \
23
                            'vm=urn:vmomi:VirtualMachine:{{vm}}:{si_uuid}'
24
25
        si_content = self.si.RetrieveContent()
26
        si_uuid = si_content.about.instanceUuid
27
28
        host = self.config['host']
29
        port = self.config['port']
30
31
        vm_url_template = meta_url_template.format(host=host, port=port, si_uuid=si_uuid)
32
33
        vm_moids = vms
34
        vms_console_urls = [
35
            {moid: {'url': vm_url_template.format(vm=moid)}} for moid in vm_moids
36
        ]
37
38
        return vms_console_urls
39