def test_get_ea_for_network_view(self):
     ea = ea_manager.get_ea_for_network_view(self.tenant_id,
                                             self.tenant_name, self.grid_id)
     self.assertEqual(self.tenant_id, ea.get('Tenant ID'))
     self.assertEqual(self.tenant_name, ea.get('Tenant Name'))
     self.assertEqual(str(False), ea.get('Cloud API Owned'))
     self.assertEqual('100', ea.get('Cloud Adapter ID'))
     self.assertEqual('OpenStack', ea.get('CMP Type'))
 def test_get_ea_for_network_view(self):
     ea = ea_manager.get_ea_for_network_view(self.tenant_id,
                                             self.tenant_name,
                                             self.grid_id)
     self.assertEqual(self.tenant_id, ea.get('Tenant ID'))
     self.assertEqual(self.tenant_name, ea.get('Tenant Name'))
     self.assertEqual(str(False), ea.get('Cloud API Owned'))
     self.assertEqual('100', ea.get('Cloud Adapter ID'))
     self.assertEqual('OpenStack', ea.get('CMP Type'))
Exemplo n.º 3
0
    def _create_ib_network_view(self):
        session = self.ib_cxt.context.session

        ea_network_view = eam.get_ea_for_network_view(self.ib_cxt.tenant_id,
                                                      self.ib_cxt.tenant_name,
                                                      self.grid_id)
        ib_network_view, obj_created = (
            ib_objects.NetworkView.create_check_exists(
                self.ib_cxt.connector,
                name=self.ib_cxt.mapping.network_view,
                extattrs=ea_network_view))

        network_view_id = utils.get_network_view_id(self.grid_id,
                                                    ib_network_view._ref)
        dbi.update_network_view_id(session,
                                   self.ib_cxt.mapping.network_view_id,
                                   network_view_id)
        self.ib_cxt.mapping.network_view_id = network_view_id

        LOG.info(_LI("Created a network view: %s"), ib_network_view)
        return ib_network_view, obj_created
Exemplo n.º 4
0
    def _create_ib_network_view(self):
        session = self.ib_cxt.context.session

        ea_network_view = eam.get_ea_for_network_view(
            self.ib_cxt.tenant_id,
            self.ib_cxt.tenant_name,
            self.grid_id)

        ib_network_view = self.ib_cxt.ibom.create_network_view(
            self.ib_cxt.mapping.network_view,
            ea_network_view)

        network_view_id = utils.get_network_view_id(self.grid_id,
                                                    ib_network_view._ref)
        dbi.update_network_view_id(session,
                                   self.ib_cxt.mapping.network_view_id,
                                   network_view_id)
        self.ib_cxt.mapping.network_view_id = network_view_id

        LOG.info(_LI("Created a network view: %s"), ib_network_view)
        return ib_network_view
def participate_network_views(grid_id):
    print("Associating/Unassociating network views for OpenStack...")
    print(("-" * PRINT_LINE))
    print("")

    netview_input = None
    if cfg.CONF.participating_network_views:
        netview_input = cfg.CONF.participating_network_views
    elif ENV_NETWORK_VIEW_PARTICIPATION_LIST in os.environ:
        netview_input = os.environ[ENV_NETWORK_VIEW_PARTICIPATION_LIST]

    grid_id_str = str(grid_id)
    conn = utils.get_connector()

    ib_netviews = objects.NetworkView.search_all(conn)
    if not ib_netviews:
        print("No network view exists\n")
        return

    netview_names = [ib_netview.name for ib_netview in ib_netviews]
    print(("Found %s network views from the grid.\n" % len(netview_names)))

    operation = 'ASSOCIATION'
    if not netview_input and not cfg.CONF.script:
        expected_answers_operation = ['a', 'u']
        expected_answers_yes_no = ['y', 'n']

        question = ("Please type 'a' to associate network views, 'u' to "
                    "unassociate.")
        choice = ask_question(question, expected_answers_operation)
        operation = 'ASSOCIATION' if choice == 'a' else 'UNASSOCIATION'

        question = "Do you want to list network views?"
        choice = ask_question(question, expected_answers_yes_no)
        if choice == 'y':
            print((', '.join(netview_names)))
            print("")
        question = "Please provide a comma separated list of network views: "
        netview_input = input(question)

    if (not netview_input or not isinstance(netview_input, six.string_types)):
        msg = ("Participating network views should be in the "
               "comma-delimited string format.")
        if cfg.CONF.script:
            LOG.warning(msg)
        else:
            print(msg)
        return

    netview_list = []
    [
        netview_list.append(x.strip()) for x in netview_input.split(',')
        if x and x not in netview_list
    ]
    if not netview_list:
        print("")
        return

    for nv in netview_list:
        ib_netview_found = [
            ib_net for ib_net in ib_netviews if ib_net.name == nv
        ]
        if not ib_netview_found:
            print(("'%s' is not found." % nv))
            continue

        ib_netview = ib_netview_found[0]
        ea_netview = eam.get_ea_for_network_view(None, None, grid_id)
        if operation == 'ASSOCIATION':
            if ib_netview.extattrs is None:
                ib_netview.extattrs = ea_netview
            else:
                cloud_adapter_ids = ib_netview.extattrs.get(
                    const.EA_CLOUD_ADAPTER_ID)
                if cloud_adapter_ids:
                    if isinstance(cloud_adapter_ids, six.string_types):
                        cloud_adapter_ids = [cloud_adapter_ids]

                    found_ids = [
                        id for id in cloud_adapter_ids if id == grid_id_str
                    ]
                    if found_ids:
                        print(("'%s' already associated." % nv))
                        continue

                    cloud_adapter_ids.append(grid_id_str)
                else:
                    cloud_adapter_ids = [grid_id_str]

                ib_netview.extattrs.set(const.EA_CLOUD_ADAPTER_ID,
                                        cloud_adapter_ids)
            try:
                ib_netview.update()
            except ib_ex.InfobloxCannotUpdateObject as e:
                if 'Write permission' in e.msg:
                    print(("'%s' has no write permission." % nv))
                    continue
                else:
                    print(("'%s' failed to associate: %s" % (nv, e.msg)))
                    continue
            print(("'%s' is now associated." % nv))
        else:
            if ib_netview.extattrs is None:
                print(("'%s' not associated." % nv))
                continue

            cloud_adapter_ids = ib_netview.extattrs.get(
                const.EA_CLOUD_ADAPTER_ID)
            if cloud_adapter_ids:
                if isinstance(cloud_adapter_ids, six.string_types):
                    cloud_adapter_ids = [cloud_adapter_ids]

                found_ids = [
                    id for id in cloud_adapter_ids if id == grid_id_str
                ]
                if found_ids:
                    cloud_adapter_ids.remove(grid_id_str)
                    ib_netview.extattrs.set(const.EA_CLOUD_ADAPTER_ID,
                                            cloud_adapter_ids)
                    try:
                        ib_netview.update()
                    except ib_ex.InfobloxCannotUpdateObject as e:
                        if 'Write permission' in e.msg:
                            print(("'%s' has no write permission." % nv))
                            continue
                        else:
                            print(("'%s' failed to unassociated: %s" %
                                   (nv, e.msg)))
                            continue
                    print(("'%s' is now unassociated." % nv))
                else:
                    print(("'%s' not associated." % nv))
            else:
                print(("'%s' not associated." % nv))

    print("\n")
def participate_network_views(grid_id):
    print("Associating/Unassociating network views for OpenStack...")
    print("-" * PRINT_LINE)
    print("")

    netview_input = None
    if cfg.CONF.participating_network_views:
        netview_input = cfg.CONF.participating_network_views
    elif ENV_NETWORK_VIEW_PARTICIPATION_LIST in os.environ:
        netview_input = os.environ[ENV_NETWORK_VIEW_PARTICIPATION_LIST]

    grid_id_str = str(grid_id)
    conn = utils.get_connector()

    ib_netviews = objects.NetworkView.search_all(conn)
    if not ib_netviews:
        print("No network view exists\n")
        return

    netview_names = [ib_netview.name for ib_netview in ib_netviews]
    print("Found %s network views from the grid.\n" % len(netview_names))

    operation = 'ASSOCIATION'
    if not netview_input and not cfg.CONF.script:
        expected_answers_operation = ['a', 'u']
        expected_answers_yes_no = ['y', 'n']

        question = ("Please type 'a' to associate network views, 'u' to "
                    "unassociate.")
        choice = ask_question(question, expected_answers_operation)
        operation = 'ASSOCIATION' if choice == 'a' else 'UNASSOCIATION'

        question = "Do you want to list network views?"
        choice = ask_question(question, expected_answers_yes_no)
        if choice == 'y':
            print(', '.join(netview_names))
            print("")
        question = "Please provide a comma separated list of network views: "
        netview_input = raw_input(question)

    if (not netview_input or
            not isinstance(netview_input, six.string_types)):
        msg = ("Participating network views should be in the "
               "comma-delimited string format.")
        if cfg.CONF.script:
            LOG.warning(msg)
        else:
            print(msg)
        return

    netview_list = []
    [netview_list.append(x.strip()) for x in netview_input.split(',')
     if x and x not in netview_list]
    if not netview_list:
        print("")
        return

    for nv in netview_list:
        ib_netview_found = [ib_net for ib_net in ib_netviews
                            if ib_net.name == nv]
        if not ib_netview_found:
            print("'%s' is not found." % nv)
            continue

        ib_netview = ib_netview_found[0]
        ea_netview = eam.get_ea_for_network_view(None, None, grid_id)
        if operation == 'ASSOCIATION':
            if ib_netview.extattrs is None:
                ib_netview.extattrs = ea_netview
            else:
                cloud_adapter_ids = ib_netview.extattrs.get(
                    const.EA_CLOUD_ADAPTER_ID)
                if cloud_adapter_ids:
                    if isinstance(cloud_adapter_ids, six.string_types):
                        cloud_adapter_ids = [cloud_adapter_ids]

                    found_ids = [id for id in cloud_adapter_ids
                                 if id == grid_id_str]
                    if found_ids:
                        print("'%s' already associated." % nv)
                        continue

                    cloud_adapter_ids.append(grid_id_str)
                else:
                    cloud_adapter_ids = [grid_id_str]

                ib_netview.extattrs.set(const.EA_CLOUD_ADAPTER_ID,
                                        cloud_adapter_ids)
            try:
                ib_netview.update()
            except ib_ex.InfobloxCannotUpdateObject as e:
                if 'Write permission' in e.msg:
                    print("'%s' has no write permission." % nv)
                    continue
                else:
                    print("'%s' failed to associate: %s" % (nv, e.msg))
                    continue
            print("'%s' is now associated." % nv)
        else:
            if ib_netview.extattrs is None:
                print("'%s' not associated." % nv)
                continue

            cloud_adapter_ids = ib_netview.extattrs.get(
                const.EA_CLOUD_ADAPTER_ID)
            if cloud_adapter_ids:
                if isinstance(cloud_adapter_ids, six.string_types):
                    cloud_adapter_ids = [cloud_adapter_ids]

                found_ids = [id for id in cloud_adapter_ids
                             if id == grid_id_str]
                if found_ids:
                    cloud_adapter_ids.remove(grid_id_str)
                    ib_netview.extattrs.set(const.EA_CLOUD_ADAPTER_ID,
                                            cloud_adapter_ids)
                    try:
                        ib_netview.update()
                    except ib_ex.InfobloxCannotUpdateObject as e:
                        if 'Write permission' in e.msg:
                            print("'%s' has no write permission." % nv)
                            continue
                        else:
                            print("'%s' failed to unassociated: %s" %
                                  (nv, e.msg))
                            continue
                    print("'%s' is now unassociated." % nv)
                else:
                    print("'%s' not associated." % nv)
            else:
                print("'%s' not associated." % nv)

    print("\n")