def _query_host_by_scope(self, scope): """Query host info :param scope : clusterUrn , dvswitchUrn or datasotroeUrn :return a list of host in scope """ host_uri = utils.build_uri_with_params(self.site.host_uri, {'scope': scope}) return self.get(host_uri)['hosts']
def _query_host_by_scope(self, scope): """Query host info :param scope : clusterUrn , dvswitchUrn or datasotroeUrn :return a list of host in scope """ host_uri = utils.build_uri_with_params(self.site.host_uri, {'scope':scope}) return self.get(host_uri)['hosts']
def _query_vm(self, **kwargs): """Query VMs. :param kwargs: name: VM name status: VM status scope: VM in certain scope :return: list of VMs """ return self.get(utils.build_uri_with_params(self.site.vm_uri, kwargs))
def _delete_vm_with_fc_vm(self, fc_vm, destroy_disks=True): """ delete vm with fc instance, inner function :param fc_vm: :param destroy_disks: :return: """ reserve_disks = {'isReserveDisks': 0 if destroy_disks else 1} LOG.info(_('Deleting VM on FC, instance: %s reserve_disks %s'), fc_vm.name, jsonutils.dumps(reserve_disks)) self.delete(utils.build_uri_with_params(fc_vm.uri, reserve_disks))
def get_cluster_stats_by_name(self, cluster_name): """Get the aggregate resource stats of a cluster.""" cpu_info = {'vcpus': 0, 'cores': 0, 'vendor': [], 'model': []} mem_info = {'total': 0, 'used': 0} mem_total = 0 mem_used = 0 cluster_urn = None cluster_query_info = {'name': cluster_name} cluster_query_uri = utils.build_uri_with_params( self.site.cluster_uri, cluster_query_info) clusters = self.get(cluster_query_uri)['clusters'] find_cluster = None if clusters: for cluster in clusters: if cluster['name'] == cluster_name: find_cluster = cluster if find_cluster: cluster_urn = find_cluster['urn'] hosts = self._query_host_by_scope(cluster_urn) for host in hosts: if host['status'] == 'normal' and (not host['isMaintaining']): cpu_info['vcpus'] += host['cpuQuantity'] mem_total += host['memResource']['totalSizeMB'] mem_used += host['memResource']['allocatedSizeMB'] if 'vendor' in host: cpu_info['vendor'].append(host['vendor']) if 'model' in host: cpu_info['model'].append(host['model']) mem_info['total'] = mem_total mem_info['used'] = mem_used computeresource = self._get_cluster_computeresource(find_cluster) cpuResource = computeresource["cpuResource"] cpu_info["totalSizeMHz"] = cpuResource.get("totalSizeMHz") cpu_info["allocatedSizeMHz"] = cpuResource.get("allocatedSizeMHz") cpu_info["allocatedVcpus"] = cpuResource.get("allocatedVcpus", 0) cpu_usage_monitor_period = \ constant.CONF.fusioncompute.cpu_usage_monitor_period if cpu_usage_monitor_period not in [300, 1800, 3600, 86400]: cpu_usage_monitor_period = 3600 cpu_info["usage"] = self.get_cpu_usage(cpu_usage_monitor_period, cluster_urn) data = {'cpu': cpu_info, 'mem': mem_info} return cluster_urn, data else: LOG.warn(_("get cluster status failed, use default.")) data = {'cpu': cpu_info, 'mem': mem_info} return cluster_urn, data
def get_cluster_stats_by_name(self, cluster_name): """Get the aggregate resource stats of a cluster.""" cpu_info = {'vcpus': 0, 'cores': 0, 'vendor': [], 'model': []} mem_info = {'total': 0, 'used': 0} mem_total = 0 mem_used = 0 cluster_urn = None cluster_query_info = {'name': cluster_name} cluster_query_uri = utils.build_uri_with_params(self.site.cluster_uri, cluster_query_info) clusters = self.get(cluster_query_uri)['clusters'] find_cluster = None if clusters: for cluster in clusters: if cluster['name'] == cluster_name: find_cluster = cluster if find_cluster: cluster_urn = find_cluster['urn'] hosts = self._query_host_by_scope(cluster_urn) for host in hosts: if host['status'] == 'normal' and (not host['isMaintaining']): cpu_info['vcpus'] += host['cpuQuantity'] mem_total += host['memResource']['totalSizeMB'] mem_used += host['memResource']['allocatedSizeMB'] if 'vendor' in host: cpu_info['vendor'].append(host['vendor']) if 'model' in host: cpu_info['model'].append(host['model']) mem_info['total'] = mem_total mem_info['used'] = mem_used computeresource = self._get_cluster_computeresource(find_cluster) cpuResource = computeresource["cpuResource"] cpu_info["totalSizeMHz"] = cpuResource.get("totalSizeMHz") cpu_info["allocatedSizeMHz"] = cpuResource.get("allocatedSizeMHz") cpu_info["allocatedVcpus"] = cpuResource.get("allocatedVcpus", 0) cpu_usage_monitor_period = \ constant.CONF.fusioncompute.cpu_usage_monitor_period if cpu_usage_monitor_period not in [300, 1800, 3600, 86400]: cpu_usage_monitor_period = 3600 cpu_info["usage"] = self.get_cpu_usage(cpu_usage_monitor_period, cluster_urn) data = {'cpu': cpu_info, 'mem': mem_info} return cluster_urn, data else: LOG.warn(_("get cluster status failed, use default.")) data = {'cpu': cpu_info, 'mem': mem_info} return cluster_urn, data
def query_datastore_by_cluster_urn(self, cluster_urn): """Query """ datastore_cond = {'status': 'NORMAL', 'scope': cluster_urn} datastore_uri = utils.build_uri_with_params(self.site.datastore_uri, datastore_cond) return self.get(datastore_uri)['datastores']
def query_datastore_by_cluster_urn(self, cluster_urn): """Query """ datastore_cond = {'status' : 'NORMAL', 'scope' : cluster_urn} datastore_uri = utils.build_uri_with_params(self.site.datastore_uri, datastore_cond) return self.get(datastore_uri)['datastores']