~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/virt/hyperv/hostops.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2012 Cloudbase Solutions Srl
 
4
# All Rights Reserved.
 
5
#
 
6
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
7
#    not use this file except in compliance with the License. You may obtain
 
8
#    a copy of the License at
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
12
#    Unless required by applicable law or agreed to in writing, software
 
13
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
14
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
15
#    License for the specific language governing permissions and limitations
 
16
#    under the License.
 
17
 
 
18
"""
 
19
Management class for host operations.
 
20
"""
 
21
import multiprocessing
 
22
import os
 
23
import platform
 
24
 
 
25
from nova.openstack.common import cfg
 
26
from nova.openstack.common import log as logging
 
27
from nova.virt.hyperv import baseops
 
28
 
 
29
CONF = cfg.CONF
 
30
LOG = logging.getLogger(__name__)
 
31
 
 
32
 
 
33
class HostOps(baseops.BaseOps):
 
34
    def __init__(self):
 
35
        super(HostOps, self).__init__()
 
36
        self._stats = None
 
37
 
 
38
    def _get_vcpu_total(self):
 
39
        """Get vcpu number of physical computer.
 
40
        :returns: the number of cpu core.
 
41
        """
 
42
        # On certain platforms, this will raise a NotImplementedError.
 
43
        try:
 
44
            return multiprocessing.cpu_count()
 
45
        except NotImplementedError:
 
46
            LOG.warn(_("Cannot get the number of cpu, because this "
 
47
                       "function is not implemented for this platform. "
 
48
                       "This error can be safely ignored for now."))
 
49
            return 0
 
50
 
 
51
    def _get_memory_mb_total(self):
 
52
        """Get the total memory size(MB) of physical computer.
 
53
        :returns: the total amount of memory(MB).
 
54
        """
 
55
        total_kb = self._conn_cimv2.query(
 
56
            "SELECT TotalVisibleMemorySize FROM win32_operatingsystem")[0]\
 
57
            .TotalVisibleMemorySize
 
58
        total_mb = long(total_kb) / 1024
 
59
        return total_mb
 
60
 
 
61
    def _get_local_hdd_info_gb(self):
 
62
        """Get the total and used size of the volume containing
 
63
           CONF.instances_path expressed in GB.
 
64
        :returns:
 
65
            A tuple with the total and used space in GB.
 
66
        """
 
67
        normalized_path = os.path.normpath(CONF.instances_path)
 
68
        drive, path = os.path.splitdrive(normalized_path)
 
69
        hdd_info = self._conn_cimv2.query(
 
70
            ("SELECT FreeSpace,Size FROM win32_logicaldisk WHERE DeviceID='%s'"
 
71
            ) % drive)[0]
 
72
        total_gb = long(hdd_info.Size) / (1024 ** 3)
 
73
        free_gb = long(hdd_info.FreeSpace) / (1024 ** 3)
 
74
        used_gb = total_gb - free_gb
 
75
        return total_gb, used_gb
 
76
 
 
77
    def _get_vcpu_used(self):
 
78
        """ Get vcpu usage number of physical computer.
 
79
        :returns: The total number of vcpu that currently used.
 
80
        """
 
81
        #TODO(jordanrinke) figure out a way to count assigned VCPUs
 
82
        total_vcpu = 0
 
83
        return total_vcpu
 
84
 
 
85
    def _get_memory_mb_used(self):
 
86
        """Get the free memory size(MB) of physical computer.
 
87
        :returns: the total usage of memory(MB).
 
88
        """
 
89
        total_kb = self._conn_cimv2.query(
 
90
            "SELECT FreePhysicalMemory FROM win32_operatingsystem")[0]\
 
91
                .FreePhysicalMemory
 
92
        total_mb = long(total_kb) / 1024
 
93
 
 
94
        return total_mb
 
95
 
 
96
    def _get_hypervisor_version(self):
 
97
        """Get hypervisor version.
 
98
        :returns: hypervisor version (ex. 12003)
 
99
        """
 
100
        version = self._conn_cimv2.Win32_OperatingSystem()[0]\
 
101
            .Version.replace('.', '')
 
102
        LOG.info(_('Windows version: %s ') % version)
 
103
        return version
 
104
 
 
105
    def get_available_resource(self):
 
106
        """Retrieve resource info.
 
107
 
 
108
        This method is called when nova-compute launches, and
 
109
        as part of a periodic task.
 
110
 
 
111
        :returns: dictionary describing resources
 
112
 
 
113
        """
 
114
        LOG.info(_('get_available_resource called'))
 
115
 
 
116
        local_gb, used_gb = self._get_local_hdd_info_gb()
 
117
        # TODO(alexpilotti) implemented cpu_info
 
118
        dic = {'vcpus': self._get_vcpu_total(),
 
119
               'memory_mb': self._get_memory_mb_total(),
 
120
               'local_gb': local_gb,
 
121
               'vcpus_used': self._get_vcpu_used(),
 
122
               'memory_mb_used': self._get_memory_mb_used(),
 
123
               'local_gb_used': used_gb,
 
124
               'hypervisor_type': "hyperv",
 
125
               'hypervisor_version': self._get_hypervisor_version(),
 
126
               'hypervisor_hostname': platform.node(),
 
127
               'cpu_info': 'unknown'}
 
128
 
 
129
        return dic
 
130
 
 
131
    def _update_stats(self):
 
132
        LOG.debug(_("Updating host stats"))
 
133
 
 
134
        data = {}
 
135
        data["disk_total"], data["disk_used"] = self._get_local_hdd_info_gb()
 
136
        data["disk_available"] = data["disk_total"] - data["disk_used"]
 
137
        data["host_memory_total"] = self._get_memory_mb_total()
 
138
        data["host_memory_overhead"] = self._get_memory_mb_used()
 
139
        data["host_memory_free"] = \
 
140
            data["host_memory_total"] - data["host_memory_overhead"]
 
141
        data["host_memory_free_computed"] = data["host_memory_free"]
 
142
        data["supported_instances"] = \
 
143
            [('i686', 'hyperv', 'hvm'),
 
144
             ('x86_64', 'hyperv', 'hvm')]
 
145
        data["hypervisor_hostname"] = platform.node()
 
146
 
 
147
        self._stats = data
 
148
 
 
149
    def get_host_stats(self, refresh=False):
 
150
        """Return the current state of the host. If 'refresh' is
 
151
           True, run the update first."""
 
152
        LOG.info(_("get_host_stats called"))
 
153
 
 
154
        if refresh or not self._stats:
 
155
            self._update_stats()
 
156
        return self._stats
 
157
 
 
158
    def host_power_action(self, host, action):
 
159
        """Reboots, shuts down or powers up the host."""
 
160
        pass