Esempio n. 1
0
    def update_dvportgroup(self, pg_ref, config_version, port_config=None, name=None, retries=3):
        if retries <= 0:
            LOG.error("Maximum number of update retries reached for portgroup {}.".format(pg_ref))
            return
        try:
            pg_spec = self.builder.pg_config(port_config)
            pg_spec.configVersion = config_version
            if name:
                pg_spec.name = name

            now = timeutils.utcnow()
            pg_update_task = self.connection.invoke_api(
                self.connection.vim,
                'ReconfigureDVPortgroup_Task',
                pg_ref, spec=pg_spec)

            self.connection.wait_for_task(pg_update_task)
            delta = timeutils.utcnow() - now
            stats.timing('networking_dvs.dvportgroup.updated', delta)
            LOG.debug("Updating portgroup {} took {} seconds.".format(pg_ref, delta.seconds))
        except vmware_exceptions.VimException as e:
            if dvs_const.CONCURRENT_MODIFICATION_TEXT in str(e):
                LOG.debug("Concurrent modification detected, will retry.")
                config_version = vim_util.get_object_property(
                    self.connection.vim, pg_ref, "config.configVersion")
                return self.update_dvportgroup(pg_ref, config_version, port_config, name, retries-1)
            if dvs_const.BULK_FAULT_TEXT in str(e):
                info = get_task_info(self.connection, pg_update_task)
                self.rectifyForFault(info.error.fault)
                return
            raise exceptions.wrap_wmvare_vim_exception(e)
Esempio n. 2
0
 def _get_ds_browser(self, ds_ref):
     ds_browser = self._ds_browser.get(ds_ref.value)
     if not ds_browser:
         ds_browser = vutil.get_object_property(self._session.vim, ds_ref,
                                                "browser")
         self._ds_browser[ds_ref.value] = ds_browser
     return ds_browser
Esempio n. 3
0
 def _get_ds_browser(self, ds_ref):
     ds_browser = self._ds_browser.get(ds_ref.value)
     if not ds_browser:
         ds_browser = vutil.get_object_property(self._session.vim,
                                                ds_ref,
                                                "browser")
         self._ds_browser[ds_ref.value] = ds_browser
     return ds_browser
Esempio n. 4
0
def _get_total_ds_capacity_for_host(vim, host):
    """
    Gets the total disk capacity for host. It is done by looking up all the
    datastores of the host and return a summation of their capacities
    """
    datastores = vim_util.get_object_properties(vim, None, host, "HostSystem",
                                                "datastore")
    # OpenStack uses the first datastore found
    for datastore_obj in datastores.objects:
        for prop in datastore_obj.propSet:
            ds_refs = prop.val[0]
            for ds_ref in ds_refs:
                total_capacity = oslo_vutil.get_object_property(
                    vim, ds_ref, "summary.capacity")
                total_free = oslo_vutil.get_object_property(
                    vim, ds_ref, "summary.freeSpace")
                return total_capacity, (total_capacity - total_free)
    return 0, 0
Esempio n. 5
0
 def test_get_object_property(self, get_object_properties):
     prop = mock.Mock()
     prop.val = "ubuntu-12.04"
     properties = mock.Mock()
     properties.propSet = [prop]
     properties_list = [properties]
     get_object_properties.return_value = properties_list
     vim = mock.Mock()
     moref = mock.Mock()
     property_name = 'name'
     val = vim_util.get_object_property(vim, moref, property_name)
     self.assertEqual(prop.val, val)
     get_object_properties.assert_called_once_with(
         vim, moref, [property_name], skip_op_id=False)
Esempio n. 6
0
 def test_get_object_property(self, get_object_properties):
     prop = mock.Mock()
     prop.val = "ubuntu-12.04"
     properties = mock.Mock()
     properties.propSet = [prop]
     properties_list = [properties]
     get_object_properties.return_value = properties_list
     vim = mock.Mock()
     moref = mock.Mock()
     property_name = 'name'
     val = vim_util.get_object_property(vim, moref, property_name)
     self.assertEqual(prop.val, val)
     get_object_properties.assert_called_once_with(vim, moref,
                                                   [property_name])
Esempio n. 7
0
def get_vc_properties_pf9(vim,
                          respools,
                          datastores,
                          hosts,
                          host_res_types,
                          perf_manager=None):
    """
    Gets statistics for vCenter.
    1. CPU and memory usage is collected from resource pools.
    2. Disk usage and capacity is collected from datastore.
    3. Network statistics are aggregated from host systems
    """
    global _vc_query_interval
    global _vc_query_time

    # TBD: Removing this for now, since this method is called in quick succession for each node
    # This optimization needs to keep track of time per node / datastore

    # current_time = datetime.now()
    # if _vc_query_time and \
    #        current_time - _vc_query_time <= _vc_query_interval:
    #    return {}
    # _vc_query_time = current_time

    #Get cpu and mem usage from respool. Get net and disk stats from hosts
    vc_stats = dict()
    if respools is None:
        return None

    if perf_manager is None:
        perf_manager = vim.service_content.perfManager

    cpu_overall_usage = 0
    cpu_max_usage = 0
    mem_overall_usage = 0
    mem_max_usage = 0

    # Get statistics from all resource pools, and sum to provide a view for the entire cluster
    for respool in respools:
        #Performance manager does not provide cpu and memory stats for resource
        #pools. Hence get those stats from runtime.cpu and runtime.mem
        cpu_props = oslo_vutil.get_object_property(vim, respool,
                                                   "ResourcePool",
                                                   "runtime.cpu")
        mem_props = oslo_vutil.get_object_property(vim, respool,
                                                   "ResourcePool",
                                                   "runtime.memory")

        if cpu_props:
            cpu_overall_usage += cpu_props['overallUsage']
            cpu_max_usage += cpu_props['maxUsage']

        if mem_props:
            mem_overall_usage += mem_props['overallUsage']
            mem_max_usage += mem_props['maxUsage']

    cpu_percentage = 1.0 * cpu_overall_usage / max(cpu_max_usage, 1) * 100
    mem_percentage = 1.0 * mem_overall_usage / max(mem_max_usage, 1) * 100

    disk_overall_capacity = 0
    disk_overall_used = 0
    for datastore in datastores:
        disk_capacity = oslo_vutil.get_object_property(vim, datastore,
                                                       "summary.capacity")
        disk_used = disk_capacity - oslo_vutil.get_object_property(
            vim, datastore, "summary.freeSpace")
        disk_overall_capacity += disk_capacity
        disk_overall_used += disk_used

    total_packet_transmitted = 0
    total_packet_received = 0
    total_transmitted_kbps = 0
    total_received_kbps = 0
    for host in hosts:
        host_net_stats = get_esx_properties_pf9(vim, host, host_res_types,
                                                perf_manager)
        total_received_kbps += mean(
            host_net_stats.get('net.received.average', [0]))
        total_transmitted_kbps += \
            mean(host_net_stats.get('net.transmitted.average', [0]))
        total_packet_received += \
            mean(host_net_stats.get('net.packetsRx.summation', [0]))
        total_packet_transmitted += \
            mean(host_net_stats.get('net.packetsTx.summation', [0]))

    vc_stats['cpu.usage.average'] = cpu_percentage
    vc_stats['mem.usage.average'] = mem_percentage
    vc_stats['disk.capacity'] = disk_overall_capacity
    vc_stats['disk.usage'] = disk_overall_used
    vc_stats['net.transmitted.average'] = total_transmitted_kbps
    vc_stats['net.received.average'] = total_received_kbps
    vc_stats['net.packetsRx.summation'] = total_packet_received
    vc_stats['net.packetsTx.summation'] = total_packet_transmitted

    return vc_stats