1# Licensed under the Apache License, Version 2.0 (the "License"); you may 2# not use this file except in compliance with the License. You may obtain 3# a copy of the License at 4# 5# http://www.apache.org/licenses/LICENSE-2.0 6# 7# Unless required by applicable law or agreed to in writing, software 8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10# License for the specific language governing permissions and limitations 11# under the License. 12 13import warnings 14 15from openstack import exceptions 16from openstack import resource 17from openstack import utils 18 19 20class Hypervisor(resource.Resource): 21 resource_key = 'hypervisor' 22 resources_key = 'hypervisors' 23 base_path = '/os-hypervisors' 24 25 # capabilities 26 allow_fetch = True 27 allow_list = True 28 29 _query_mapping = resource.QueryParameters( 30 'hypervisor_hostname_pattern', 'with_servers' 31 ) 32 33 # Lot of attributes are dropped in 2.88 34 _max_microversion = '2.88' 35 36 # Properties 37 #: Information about the hypervisor's CPU. Up to 2.28 it was string. 38 cpu_info = resource.Body('cpu_info') 39 #: IP address of the host 40 host_ip = resource.Body('host_ip') 41 #: The type of hypervisor 42 hypervisor_type = resource.Body('hypervisor_type') 43 #: Version of the hypervisor 44 hypervisor_version = resource.Body('hypervisor_version') 45 #: Name of hypervisor 46 name = resource.Body('hypervisor_hostname') 47 #: Service details 48 service_details = resource.Body('service', type=dict) 49 #: List of Servers 50 servers = resource.Body('servers', type=list, list_type=dict) 51 #: State of hypervisor 52 state = resource.Body('state') 53 #: Status of hypervisor 54 status = resource.Body('status') 55 #: The total uptime of the hypervisor and information about average load. 56 #: This attribute is set only when querying uptime explicitly. 57 uptime = resource.Body('uptime') 58 59 # Attributes deprecated with 2.88 60 #: Measurement of the hypervisor's current workload 61 current_workload = resource.Body('current_workload', deprecated=True) 62 #: Disk space available to the scheduler 63 disk_available = resource.Body("disk_available_least", deprecated=True) 64 #: The amount, in gigabytes, of local storage used 65 local_disk_used = resource.Body('local_gb_used', deprecated=True) 66 #: The amount, in gigabytes, of the local storage device 67 local_disk_size = resource.Body('local_gb', deprecated=True) 68 #: The amount, in gigabytes, of free space on the local storage device 69 local_disk_free = resource.Body('free_disk_gb', deprecated=True) 70 #: The amount, in megabytes, of memory 71 memory_used = resource.Body('memory_mb_used', deprecated=True) 72 #: The amount, in megabytes, of total memory 73 memory_size = resource.Body('memory_mb', deprecated=True) 74 #: The amount, in megabytes, of available memory 75 memory_free = resource.Body('free_ram_mb', deprecated=True) 76 #: Count of the running virtual machines 77 running_vms = resource.Body('running_vms', deprecated=True) 78 #: Count of the VCPUs in use 79 vcpus_used = resource.Body('vcpus_used', deprecated=True) 80 #: Count of all VCPUs 81 vcpus = resource.Body('vcpus', deprecated=True) 82 83 def get_uptime(self, session): 84 """Get uptime information for the hypervisor 85 86 Updates uptime attribute of the hypervisor object 87 """ 88 warnings.warn( 89 "This call is deprecated and is only available until Nova 2.88") 90 if utils.supports_microversion(session, '2.88'): 91 raise exceptions.SDKException( 92 'Hypervisor.get_uptime is not supported anymore') 93 url = utils.urljoin(self.base_path, self.id, 'uptime') 94 microversion = self._get_microversion_for(session, 'fetch') 95 response = session.get( 96 url, microversion=microversion) 97 self._translate_response(response) 98 return self 99 100 101HypervisorDetail = Hypervisor 102