Exemplo n.º 1
0
def get_inner_objects(vim,
                      base_obj,
                      path,
                      inner_type,
                      properties_to_collect=None,
                      all=False):
    """Gets the list of inner objects of the type specified."""
    client_factory = vim.client.factory
    base_type = base_obj._type
    traversal_spec = vutil.build_traversal_spec(client_factory, 'inner',
                                                base_type, path, False, [])
    object_spec = vutil.build_object_spec(client_factory, base_obj,
                                          [traversal_spec])
    property_spec = vutil.build_property_spec(
        client_factory,
        type_=inner_type,
        properties_to_collect=properties_to_collect,
        all_properties=all)
    property_filter_spec = vutil.build_property_filter_spec(
        client_factory, [property_spec], [object_spec])
    options = client_factory.create('ns0:RetrieveOptions')
    options.maxObjects = CONF.vmware.maximum_objects
    return vim.RetrievePropertiesEx(vim.service_content.propertyCollector,
                                    specSet=[property_filter_spec],
                                    options=options)
Exemplo n.º 2
0
def get_property_filter_specs(vim, property_dict, objects=None):
    client_factory = vim.client.factory
    object_specs = []
    if not objects:
        objects = [vim.service_content.rootFolder]
    for obj in objects:
        if obj.value == get_root_folder_id(vim):
            traversal_spec = [
                build_recursive_traversal_spec_root(client_factory)]
        else:
            traversal_spec = build_recursive_traversal_spec(client_factory)
        object_spec = vim_util.build_object_spec(client_factory,
                                        obj,
                                        traversal_spec)
        object_specs.append(object_spec)

    property_specs = []
    for obj_type in property_dict:
        props = property_dict[obj_type]
        property_spec = vim_util.build_property_spec(client_factory,
                                            type_=obj_type,
                                            properties_to_collect=props)
        property_specs.append(property_spec)

    property_filter_spec = vim_util.build_property_filter_spec(client_factory,
                                                      property_specs,
                                                      object_specs)
    return property_filter_spec
Exemplo n.º 3
0
 def test_build_property_filter_spec(self):
     client_factory = mock.Mock()
     prop_specs = [mock.Mock()]
     obj_specs = [mock.Mock()]
     filter_spec = vim_util.build_property_filter_spec(client_factory, prop_specs, obj_specs)
     self.assertEqual(obj_specs, filter_spec.objectSet)
     self.assertEqual(prop_specs, filter_spec.propSet)
Exemplo n.º 4
0
 def test_build_property_filter_spec(self):
     client_factory = mock.Mock()
     prop_specs = [mock.Mock()]
     obj_specs = [mock.Mock()]
     filter_spec = vim_util.build_property_filter_spec(
         client_factory, prop_specs, obj_specs)
     self.assertEqual(obj_specs, filter_spec.objectSet)
     self.assertEqual(prop_specs, filter_spec.propSet)
Exemplo n.º 5
0
def get_inner_objects(vim, base_obj, path, inner_type,
                      properties_to_collect=None, all=False):
    """Gets the list of inner objects of the type specified."""
    client_factory = vim.client.factory
    base_type = base_obj._type
    traversal_spec = vutil.build_traversal_spec(client_factory, 'inner',
                                                base_type, path, False, [])
    object_spec = vutil.build_object_spec(client_factory,
                                          base_obj,
                                          [traversal_spec])
    property_spec = vutil.build_property_spec(client_factory, type_=inner_type,
                                properties_to_collect=properties_to_collect,
                                all_properties=all)
    property_filter_spec = vutil.build_property_filter_spec(client_factory,
                                [property_spec], [object_spec])
    options = client_factory.create('ns0:RetrieveOptions')
    options.maxObjects = CONF.vmware.maximum_objects
    return vim.RetrievePropertiesEx(
            vim.service_content.propertyCollector,
            specSet=[property_filter_spec], options=options)
Exemplo n.º 6
0
    def _init_perf_counter_id_lookup_map(self):

        # Query details of all the performance counters from VC
        session = self._api_session
        client_factory = session.vim.client.factory
        perf_manager = session.vim.service_content.perfManager

        prop_spec = vim_util.build_property_spec(client_factory,
                                                 PERF_MANAGER_TYPE,
                                                 [PERF_COUNTER_PROPERTY])

        obj_spec = vim_util.build_object_spec(client_factory, perf_manager,
                                              None)

        filter_spec = vim_util.build_property_filter_spec(
            client_factory, [prop_spec], [obj_spec])

        options = client_factory.create('ns0:RetrieveOptions')
        options.maxObjects = 1

        prop_collector = session.vim.service_content.propertyCollector
        result = session.invoke_api(session.vim,
                                    "RetrievePropertiesEx",
                                    prop_collector,
                                    specSet=[filter_spec],
                                    options=options)

        perf_counter_infos = result.objects[0].propSet[0].val.PerfCounterInfo

        # Extract the counter Id for each counter and populate the map
        self._perf_counter_id_lookup_map = {}
        for perf_counter_info in perf_counter_infos:

            counter_group = perf_counter_info.groupInfo.key
            counter_name = perf_counter_info.nameInfo.key
            counter_rollup_type = perf_counter_info.rollupType
            counter_id = perf_counter_info.key

            counter_full_name = (counter_group + ":" + counter_name + ":" +
                                 counter_rollup_type)
            self._perf_counter_id_lookup_map[counter_full_name] = counter_id
Exemplo n.º 7
0
def get_objects(vim, type, properties_to_collect=None, all=False):
    """Gets the list of objects of the type specified."""
    if not properties_to_collect:
        properties_to_collect = ["name"]

    client_factory = vim.client.factory
    trav_spec = build_recursive_traversal_spec_root(client_factory)
    object_spec = vim_util.build_object_spec(client_factory,
                                    vim.service_content.rootFolder,
                                    [trav_spec])
    property_spec = \
        vim_util.build_property_spec(client_factory, type_=type,
                            properties_to_collect=properties_to_collect,
                            all_properties=all)
    property_filter_spec = vim_util.build_property_filter_spec(client_factory,
                                                      [property_spec],
                                                      [object_spec])
    property_collector = vim.service_content.propertyCollector
    return retrieve_properties_ex(vim,
                                  property_collector,
                                  [property_filter_spec])
Exemplo n.º 8
0
    def _init_perf_counter_id_lookup_map(self):

        # Query details of all the performance counters from VC
        session = self._api_session
        client_factory = session.vim.client.factory
        perf_manager = session.vim.service_content.perfManager

        prop_spec = vim_util.build_property_spec(
            client_factory, PERF_MANAGER_TYPE, [PERF_COUNTER_PROPERTY])

        obj_spec = vim_util.build_object_spec(
            client_factory, perf_manager, None)

        filter_spec = vim_util.build_property_filter_spec(
            client_factory, [prop_spec], [obj_spec])

        options = client_factory.create('ns0:RetrieveOptions')
        options.maxObjects = 1

        prop_collector = session.vim.service_content.propertyCollector
        result = session.invoke_api(session.vim, "RetrievePropertiesEx",
                                    prop_collector, specSet=[filter_spec],
                                    options=options)

        perf_counter_infos = result.objects[0].propSet[0].val.PerfCounterInfo

        # Extract the counter Id for each counter and populate the map
        self._perf_counter_id_lookup_map = {}
        for perf_counter_info in perf_counter_infos:

            counter_group = perf_counter_info.groupInfo.key
            counter_name = perf_counter_info.nameInfo.key
            counter_rollup_type = perf_counter_info.rollupType
            counter_id = perf_counter_info.key

            counter_full_name = (counter_group + ":" + counter_name + ":" +
                                 counter_rollup_type)
            self._perf_counter_id_lookup_map[counter_full_name] = counter_id