~rlane/nova/lp773690

« back to all changes in this revision

Viewing changes to nova/console/vmrc.py

  • Committer: rlane at wikimedia
  • Date: 2011-04-29 22:30:40 UTC
  • mfrom: (382.1.655 nova)
  • Revision ID: rlane@wikimedia.org-20110429223040-i0x3ds9eqwrabyru
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#    License for the specific language governing permissions and limitations
16
16
#    under the License.
17
17
 
18
 
"""
19
 
VMRC console drivers.
20
 
"""
 
18
"""VMRC console drivers."""
21
19
 
22
20
import base64
23
21
import json
27
25
from nova import log as logging
28
26
from nova.virt.vmwareapi import vim_util
29
27
 
 
28
 
 
29
FLAGS = flags.FLAGS
30
30
flags.DEFINE_integer('console_vmrc_port',
31
31
                     443,
32
32
                     "port for VMware VMRC connections")
34
34
                     10,
35
35
                     "number of retries for retrieving VMRC information")
36
36
 
37
 
FLAGS = flags.FLAGS
38
 
 
39
37
 
40
38
class VMRCConsole(object):
41
39
    """VMRC console driver with ESX credentials."""
69
67
        return password
70
68
 
71
69
    def generate_password(self, vim_session, pool, instance_name):
72
 
        """
73
 
        Returns VMRC Connection credentials.
 
70
        """Returns VMRC Connection credentials.
74
71
 
75
72
        Return string is of the form '<VM PATH>:<ESX Username>@<ESX Password>'.
 
73
 
76
74
        """
77
75
        username, password = pool['username'], pool['password']
78
 
        vms = vim_session._call_method(vim_util, "get_objects",
79
 
                    "VirtualMachine", ["name", "config.files.vmPathName"])
 
76
        vms = vim_session._call_method(vim_util, 'get_objects',
 
77
                    'VirtualMachine', ['name', 'config.files.vmPathName'])
80
78
        vm_ds_path_name = None
81
79
        vm_ref = None
82
80
        for vm in vms:
83
81
            vm_name = None
84
82
            ds_path_name = None
85
83
            for prop in vm.propSet:
86
 
                if prop.name == "name":
 
84
                if prop.name == 'name':
87
85
                    vm_name = prop.val
88
 
                elif prop.name == "config.files.vmPathName":
 
86
                elif prop.name == 'config.files.vmPathName':
89
87
                    ds_path_name = prop.val
90
88
            if vm_name == instance_name:
91
89
                vm_ref = vm.obj
92
90
                vm_ds_path_name = ds_path_name
93
91
                break
94
92
        if vm_ref is None:
95
 
            raise exception.NotFound(_("instance - %s not present") %
96
 
                                     instance_name)
97
 
        json_data = json.dumps({"vm_id": vm_ds_path_name,
98
 
                    "username": username,
99
 
                    "password": password})
 
93
            raise exception.InstanceNotFound(instance_id=instance_name)
 
94
        json_data = json.dumps({'vm_id': vm_ds_path_name,
 
95
                    'username': username,
 
96
                    'password': password})
100
97
        return base64.b64encode(json_data)
101
98
 
102
99
    def is_otp(self):
115
112
        return 'vmrc+session'
116
113
 
117
114
    def generate_password(self, vim_session, pool, instance_name):
118
 
        """
119
 
        Returns a VMRC Session.
 
115
        """Returns a VMRC Session.
120
116
 
121
117
        Return string is of the form '<VM MOID>:<VMRC Ticket>'.
 
118
 
122
119
        """
123
 
        vms = vim_session._call_method(vim_util, "get_objects",
124
 
                    "VirtualMachine", ["name"])
125
 
        vm_ref = None
 
120
        vms = vim_session._call_method(vim_util, 'get_objects',
 
121
                    'VirtualMachine', ['name'])
 
122
        vm_ref = NoneV
126
123
        for vm in vms:
127
124
            if vm.propSet[0].val == instance_name:
128
125
                vm_ref = vm.obj
129
126
        if vm_ref is None:
130
 
            raise exception.NotFound(_("instance - %s not present") %
131
 
                                     instance_name)
 
127
            raise exception.InstanceNotFound(instance_id=instance_name)
132
128
        virtual_machine_ticket = \
133
129
                        vim_session._call_method(
134
130
            vim_session._get_vim(),
135
 
            "AcquireCloneTicket",
 
131
            'AcquireCloneTicket',
136
132
            vim_session._get_vim().get_service_content().sessionManager)
137
 
        json_data = json.dumps({"vm_id": str(vm_ref.value),
138
 
                     "username": virtual_machine_ticket,
139
 
                     "password": virtual_machine_ticket})
 
133
        json_data = json.dumps({'vm_id': str(vm_ref.value),
 
134
                     'username': virtual_machine_ticket,
 
135
                     'password': virtual_machine_ticket})
140
136
        return base64.b64encode(json_data)
141
137
 
142
138
    def is_otp(self):