# Path: oslo_vmware/dvs_util.py
# LOG = logging.getLogger(__name__)
# def get_dvs_moref(value):
# def get_vlan_spec(session, vlan_id):
# def get_trunk_vlan_spec(session, start=0, end=4094):
# def get_port_group_spec(session, name, vlan_id, trunk_mode=False):
# def add_port_group(session, dvs_moref, name, vlan_id=None,
#                    trunk_mode=False):
# def get_portgroups(session, dvs_moref):
# def delete_port_group(session, portgroup_moref):
# 
# Path: oslo_vmware/vim_util.py
# LOG = logging.getLogger(__name__)
# def get_moref(value, type_):
# def get_moref_value(moref):
# def get_moref_type(moref):
# def build_selection_spec(client_factory, name):
# def build_traversal_spec(client_factory, name, type_, path, skip, select_set):
# def build_recursive_traversal_spec(client_factory):
# def build_property_spec(client_factory, type_='VirtualMachine',
#                         properties_to_collect=None, all_properties=False):
# def build_object_spec(client_factory, root_folder, traversal_specs):
# def build_property_filter_spec(client_factory, property_specs, object_specs):
# def get_objects(vim, type_, max_objects, properties_to_collect=None,
#                 all_properties=False):
# def get_object_properties(vim, moref, properties_to_collect, skip_op_id=False):
# def get_object_properties_dict(vim, moref, properties_to_collect):
# def _get_token(retrieve_result):
# def cancel_retrieval(vim, retrieve_result):
# def continue_retrieval(vim, retrieve_result):
#     def __init__(self, vim, retrieve_result):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_value, traceback):
#     def __iter__(self):
# def get_object_property(vim, moref, property_name, skip_op_id=False):
# def find_extension(vim, key):
# def register_extension(vim, key, type, label='OpenStack',
#                        summary='OpenStack services', version='1.0'):
# def get_vc_version(session):
# def get_inventory_path(vim, entity_ref, max_objects=100):
# def get_http_service_request_spec(client_factory, method, uri):
# def get_prop_spec(client_factory, spec_type, properties):
# def get_obj_spec(client_factory, obj, select_set=None):
# def get_prop_filter_spec(client_factory, obj_spec, prop_spec):
# def get_properties_for_a_collection_of_objects(vim, type_,
#                                                obj_list, properties,
#                                                max_objects=None):
# def propset_dict(propset):
# def storage_placement_spec(client_factory,
#                            dsc_ref,
#                            type,
#                            clone_spec=None,
#                            config_spec=None,
#                            relocate_spec=None,
#                            vm_ref=None,
#                            folder=None,
#                            clone_name=None,
#                            res_pool_ref=None,
#                            host_ref=None):
# def serialize_object(obj):
# class WithRetrieval(object):


import collections
from unittest import mock
from oslo_vmware import dvs_util
from oslo_vmware.tests import base
from oslo_vmware import vim_util
        def wait_for_task_side_effect(task):
            task_info = mock.Mock()
            task_info.result = pg_moref
            return task_info

        session.wait_for_task.side_effect = wait_for_task_side_effect
        pg = dvs_util.add_port_group(session, dvs_moref, 'pg',
                                     vlan_id=7)
        self.assertEqual(pg, pg_moref)
        session.invoke_api.assert_called_once_with(
            session.vim, 'CreateDVPortgroup_Task', dvs_moref,
            spec=spec)

    @mock.patch.object(dvs_util, 'get_port_group_spec')
    def test_add_port_group_trunk(self, mock_spec):
        session = mock.Mock()
        dvs_moref = dvs_util.get_dvs_moref('dvs-123')
        spec = dvs_util.get_port_group_spec(session, 'pg', None,
                                            trunk_mode=True)
        mock_spec.return_value = spec
        dvs_util.add_port_group(session, dvs_moref, 'pg',
                                trunk_mode=True)
        session.invoke_api.assert_called_once_with(
            session.vim, 'CreateDVPortgroup_Task', dvs_moref,
            spec=spec)

    def test_get_portgroups_empty(self):
        session = mock.Mock()
        dvs_moref = dvs_util.get_dvs_moref('dvs-123')
        session.invoke_api.return_value = []

# Path: oslo_vmware/dvs_util.py
# LOG = logging.getLogger(__name__)
# def get_dvs_moref(value):
# def get_vlan_spec(session, vlan_id):
# def get_trunk_vlan_spec(session, start=0, end=4094):
# def get_port_group_spec(session, name, vlan_id, trunk_mode=False):
# def add_port_group(session, dvs_moref, name, vlan_id=None,
#                    trunk_mode=False):
# def get_portgroups(session, dvs_moref):
# def delete_port_group(session, portgroup_moref):
# 
# Path: oslo_vmware/vim_util.py
# LOG = logging.getLogger(__name__)
# def get_moref(value, type_):
# def get_moref_value(moref):
# def get_moref_type(moref):
# def build_selection_spec(client_factory, name):
# def build_traversal_spec(client_factory, name, type_, path, skip, select_set):
# def build_recursive_traversal_spec(client_factory):
# def build_property_spec(client_factory, type_='VirtualMachine',
#                         properties_to_collect=None, all_properties=False):
# def build_object_spec(client_factory, root_folder, traversal_specs):
# def build_property_filter_spec(client_factory, property_specs, object_specs):
# def get_objects(vim, type_, max_objects, properties_to_collect=None,
#                 all_properties=False):
# def get_object_properties(vim, moref, properties_to_collect, skip_op_id=False):
# def get_object_properties_dict(vim, moref, properties_to_collect):
# def _get_token(retrieve_result):
# def cancel_retrieval(vim, retrieve_result):
# def continue_retrieval(vim, retrieve_result):
#     def __init__(self, vim, retrieve_result):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_value, traceback):
#     def __iter__(self):
# def get_object_property(vim, moref, property_name, skip_op_id=False):
# def find_extension(vim, key):
# def register_extension(vim, key, type, label='OpenStack',
#                        summary='OpenStack services', version='1.0'):
# def get_vc_version(session):
# def get_inventory_path(vim, entity_ref, max_objects=100):
# def get_http_service_request_spec(client_factory, method, uri):
# def get_prop_spec(client_factory, spec_type, properties):
# def get_obj_spec(client_factory, obj, select_set=None):
# def get_prop_filter_spec(client_factory, obj_spec, prop_spec):
# def get_properties_for_a_collection_of_objects(vim, type_,
#                                                obj_list, properties,
#                                                max_objects=None):
# def propset_dict(propset):
# def storage_placement_spec(client_factory,
#                            dsc_ref,
#                            type,
#                            clone_spec=None,
#                            config_spec=None,
#                            relocate_spec=None,
#                            vm_ref=None,
#                            folder=None,
#                            clone_name=None,
#                            res_pool_ref=None,
#                            host_ref=None):
# def serialize_object(obj):
# class WithRetrieval(object):


# Path: oslo_vmware/tests/test_dvs_util.py
import collections
from unittest import mock
from oslo_vmware import dvs_util
from oslo_vmware.tests import base
from oslo_vmware import vim_util

        def wait_for_task_side_effect(task):
            task_info = mock.Mock()
            task_info.result = pg_moref
            return task_info

        session.wait_for_task.side_effect = wait_for_task_side_effect
        pg = dvs_util.add_port_group(session, dvs_moref, 'pg',
                                     vlan_id=7)
        self.assertEqual(pg, pg_moref)
        session.invoke_api.assert_called_once_with(
            session.vim, 'CreateDVPortgroup_Task', dvs_moref,
            spec=spec)

    @mock.patch.object(dvs_util, 'get_port_group_spec')
    def test_add_port_group_trunk(self, mock_spec):
        session = mock.Mock()
        dvs_moref = dvs_util.get_dvs_moref('dvs-123')
        spec = dvs_util.get_port_group_spec(session, 'pg', None,
                                            trunk_mode=True)
        mock_spec.return_value = spec
        dvs_util.add_port_group(session, dvs_moref, 'pg',
                                trunk_mode=True)
        session.invoke_api.assert_called_once_with(
            session.vim, 'CreateDVPortgroup_Task', dvs_moref,
            spec=spec)

    def test_get_portgroups_empty(self):
        session = mock.Mock()
        dvs_moref = dvs_util.get_dvs_moref('dvs-123')
        session.invoke_api.return_value = []

        pgs = dvs_util.get_portgroups(session, dvs_moref)