~zulcss/nova/nova-precise-g3

« back to all changes in this revision

Viewing changes to nova/virt/vmwareapi/host.py

  • Committer: Chuck Short
  • Date: 2013-02-25 12:48:57 UTC
  • mfrom: (94.1.5 raring-proposed)
  • Revision ID: zulcss@ubuntu.com-20130225124857-iiz7w0zqhjo1sbs3
* New upstream release for the Ubuntu Cloud Archive. 
* New usptream release. 
* debian/patches/debian/patches/fix-ubuntu-tests.patch: Refreshed.
* debian/nova-baremetal.logrotate: Fix logfile path.
* debian/control, debian/nova-spiceproxy.{install, logrotate, upstart}:
  Add spice html5 proxy support.
* debian/nova-novncproxy.upstart: Start on runlevel [2345]
* debian/rules: Call testr directly since run_tests.sh -N gives weird return
  value when tests pass.
* debian/pyddist-overrides: Add websockify.
* debian/nova-common.postinst: Removed config file conversion, since
  the option is no longer available. (LP: #1110567)
* debian/control: Add python-pyasn1 as a dependency.
* debian/control: Add python-oslo-config as a dependency.
* debian/control: Suggest sysfsutils, sg3-utils, multipath-tools for fibre
  channel support.
* debian/control: Fix typo (websocikfy -> websockify).
* SECURITY UPDATE: fix lack of authentication on block device used for
  os-volume_boot
  - debian/patches/CVE-2013-0208.patch: adjust nova/compute/api.py to
    validate we can access the volumes
  - CVE-2013-0208

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright (c) 2012 VMware, Inc.
 
4
#
 
5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
6
#    not use this file except in compliance with the License. You may obtain
 
7
#    a copy of the License at
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
11
#    Unless required by applicable law or agreed to in writing, software
 
12
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
13
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
14
#    License for the specific language governing permissions and limitations
 
15
#    under the License.
 
16
 
 
17
"""
 
18
Management class for host-related functions (start, reboot, etc).
 
19
"""
 
20
 
 
21
from nova import exception
 
22
from nova.openstack.common import log as logging
 
23
from nova.virt.vmwareapi import vim_util
 
24
from nova.virt.vmwareapi import vm_util
 
25
 
 
26
LOG = logging.getLogger(__name__)
 
27
 
 
28
 
 
29
class Host(object):
 
30
    """
 
31
    Implements host related operations.
 
32
    """
 
33
    def __init__(self, session):
 
34
        self._session = session
 
35
 
 
36
    def host_power_action(self, host, action):
 
37
        """Reboots or shuts down the host."""
 
38
        host_mor = self._session._call_method(vim_util, "get_objects",
 
39
                                              "HostSystem")[0].obj
 
40
        LOG.debug(_("%(action)s %(host)s") % locals())
 
41
        if action == "reboot":
 
42
            host_task = self._session._call_method(
 
43
                                    self._session._get_vim(),
 
44
                                    "RebootHost_Task", host_mor,
 
45
                                    force=False)
 
46
        elif action == "shutdown":
 
47
            host_task = self._session._call_method(
 
48
                                    self._session._get_vim(),
 
49
                                    "ShutdownHost_Task", host_mor,
 
50
                                    force=False)
 
51
        elif action == "startup":
 
52
            host_task = self._session._call_method(
 
53
                                    self._session._get_vim(),
 
54
                                    "PowerUpHostFromStandBy_Task", host_mor,
 
55
                                    timeoutSec=60)
 
56
        self._session._wait_for_task(host, host_task)
 
57
 
 
58
    def host_maintenance_mode(self, host, mode):
 
59
        """Start/Stop host maintenance window. On start, it triggers
 
60
        guest VMs evacuation."""
 
61
        host_mor = self._session._call_method(vim_util, "get_objects",
 
62
                                              "HostSystem")[0].obj
 
63
        LOG.debug(_("Set maintenance mod on %(host)s to %(mode)s") % locals())
 
64
        if mode:
 
65
            host_task = self._session._call_method(
 
66
                                    self._session._get_vim(),
 
67
                                    "EnterMaintenanceMode_Task",
 
68
                                    host_mor, timeout=0,
 
69
                                    evacuatePoweredOffVms=True)
 
70
        else:
 
71
            host_task = self._session._call_method(
 
72
                                    self._session._get_vim(),
 
73
                                    "ExitMaintenanceMode_Task",
 
74
                                    host_mor, timeout=0)
 
75
        self._session._wait_for_task(host, host_task)
 
76
 
 
77
    def set_host_enabled(self, _host, enabled):
 
78
        """Sets the specified host's ability to accept new instances."""
 
79
        pass
 
80
 
 
81
 
 
82
class HostState(object):
 
83
    """Manages information about the ESX host this compute
 
84
    node is running on.
 
85
    """
 
86
    def __init__(self, session, host_name):
 
87
        super(HostState, self).__init__()
 
88
        self._session = session
 
89
        self._host_name = host_name
 
90
        self._stats = {}
 
91
        self.update_status()
 
92
 
 
93
    def get_host_stats(self, refresh=False):
 
94
        """Return the current state of the host. If 'refresh' is
 
95
        True, run the update first.
 
96
        """
 
97
        if refresh:
 
98
            self.update_status()
 
99
        return self._stats
 
100
 
 
101
    def update_status(self):
 
102
        """Update the current state of the host.
 
103
        """
 
104
        host_mor = self._session._call_method(vim_util, "get_objects",
 
105
                                              "HostSystem")[0].obj
 
106
        summary = self._session._call_method(vim_util,
 
107
                                             "get_dynamic_property",
 
108
                                             host_mor,
 
109
                                             "HostSystem",
 
110
                                             "summary")
 
111
 
 
112
        if summary is None:
 
113
            return
 
114
 
 
115
        try:
 
116
            ds = vm_util.get_datastore_ref_and_name(self._session)
 
117
        except exception.DatastoreNotFound:
 
118
            ds = (None, None, 0, 0)
 
119
 
 
120
        data = {}
 
121
        data["vcpus"] = summary.hardware.numCpuThreads
 
122
        data["cpu_info"] = \
 
123
                {"vendor": summary.hardware.vendor,
 
124
                 "model": summary.hardware.cpuModel,
 
125
                 "topology": {"cores": summary.hardware.numCpuCores,
 
126
                              "sockets": summary.hardware.numCpuPkgs,
 
127
                              "threads": summary.hardware.numCpuThreads}
 
128
                }
 
129
        data["disk_total"] = ds[2] / (1024 * 1024)
 
130
        data["disk_available"] = ds[3] / (1024 * 1024)
 
131
        data["disk_used"] = data["disk_total"] - data["disk_available"]
 
132
        data["host_memory_total"] = summary.hardware.memorySize / (1024 * 1024)
 
133
        data["host_memory_free"] = data["host_memory_total"] - \
 
134
                                   summary.quickStats.overallMemoryUsage
 
135
        data["hypervisor_type"] = summary.config.product.name
 
136
        data["hypervisor_version"] = summary.config.product.version
 
137
        data["hypervisor_hostname"] = self._host_name
 
138
 
 
139
        self._stats = data
 
140
        return data
 
141
 
 
142
 
 
143
class VCState(object):
 
144
    """Manages information about the VC host this compute
 
145
    node is running on.
 
146
    """
 
147
    def __init__(self, session, host_name, cluster):
 
148
        super(VCState, self).__init__()
 
149
        self._session = session
 
150
        self._host_name = host_name
 
151
        self._cluster = cluster
 
152
        self._stats = {}
 
153
        self.update_status()
 
154
 
 
155
    def get_host_stats(self, refresh=False):
 
156
        """Return the current state of the host. If 'refresh' is
 
157
        True, run the update first.
 
158
        """
 
159
        if refresh:
 
160
            self.update_status()
 
161
        return self._stats
 
162
 
 
163
    def update_status(self):
 
164
        """Update the current state of the host.
 
165
        """
 
166
        host_mor = vm_util.get_host_ref(self._session, self._cluster)
 
167
        if host_mor is None:
 
168
            return
 
169
 
 
170
        summary = self._session._call_method(vim_util,
 
171
                                             "get_dynamic_property",
 
172
                                             host_mor,
 
173
                                             "HostSystem",
 
174
                                             "summary")
 
175
 
 
176
        if summary is None:
 
177
            return
 
178
 
 
179
        try:
 
180
            ds = vm_util.get_datastore_ref_and_name(self._session,
 
181
                                                    self._cluster)
 
182
        except exception.DatastoreNotFound:
 
183
            ds = (None, None, 0, 0)
 
184
 
 
185
        data = {}
 
186
        data["vcpus"] = summary.hardware.numCpuThreads
 
187
        data["cpu_info"] =\
 
188
        {"vendor": summary.hardware.vendor,
 
189
         "model": summary.hardware.cpuModel,
 
190
         "topology": {"cores": summary.hardware.numCpuCores,
 
191
                      "sockets": summary.hardware.numCpuPkgs,
 
192
                      "threads": summary.hardware.numCpuThreads}
 
193
        }
 
194
        data["disk_total"] = ds[2] / (1024 * 1024)
 
195
        data["disk_available"] = ds[3] / (1024 * 1024)
 
196
        data["disk_used"] = data["disk_total"] - data["disk_available"]
 
197
        data["host_memory_total"] = summary.hardware.memorySize / (1024 * 1024)
 
198
        data["host_memory_free"] = data["host_memory_total"] -\
 
199
                                   summary.quickStats.overallMemoryUsage
 
200
        data["hypervisor_type"] = summary.config.product.name
 
201
        data["hypervisor_version"] = summary.config.product.version
 
202
        data["hypervisor_hostname"] = self._host_name
 
203
 
 
204
        self._stats = data
 
205
        return data