def get_security_groups(neutron_client):
    logger.debug("Getting Security groups...")
    dic_secgroups = {}
    secgroups = os_utils.get_security_groups(neutron_client)
    if not (secgroups is None or len(secgroups) == 0):
        for secgroup in secgroups:
            dic_secgroups.update({secgroup['id']: secgroup['name']})
    return {'secgroups': dic_secgroups}
Example #2
0
def get_security_groups(neutron_client):
    logger.debug("Getting Security groups...")
    dic_secgroups = {}
    secgroups = os_utils.get_security_groups(neutron_client)
    if not (secgroups is None or len(secgroups) == 0):
        for secgroup in secgroups:
            dic_secgroups.update({secgroup['id']: secgroup['name']})
    return {'secgroups': dic_secgroups}
Example #3
0
def setup_ingress_egress_secgroup(neutron_client, protocol,
                                  min_port=None, max_port=None):
    secgroups = os_utils.get_security_groups(neutron_client)
    for sg in secgroups:
        os_utils.create_secgroup_rule(neutron_client, sg['id'],
                                      'ingress', protocol,
                                      port_range_min=min_port,
                                      port_range_max=max_port)
        os_utils.create_secgroup_rule(neutron_client, sg['id'],
                                      'egress', protocol,
                                      port_range_min=min_port,
                                      port_range_max=max_port)
    return
Example #4
0
def setup_ingress_egress_secgroup(neutron_client, protocol,
                                  min_port=None, max_port=None):
    secgroups = os_utils.get_security_groups(neutron_client)
    for sg in secgroups:
        # TODO: the version of the create_secgroup_rule function in
        # functest swallows the exception thrown when a secgroup rule
        # already exists and prints a ton of noise in the test output.
        # Instead of making changes in functest code this late in the
        # release cycle, we keep our own version without the exception
        # logging. We must find a way to properly cleanup sec group
        # rules using "functest openstack clean" or pretty printing the
        # specific exception in the next release
        create_secgroup_rule(neutron_client, sg['id'],
                             'ingress', protocol,
                             port_range_min=min_port,
                             port_range_max=max_port)
        create_secgroup_rule(neutron_client, sg['id'],
                             'egress', protocol,
                             port_range_min=min_port,
                             port_range_max=max_port)
Example #5
0
def remove_security_groups(neutron_client, default_security_groups):
    logger.debug("Removing Security groups...")
    secgroups = os_utils.get_security_groups(neutron_client)
    if secgroups is None or len(secgroups) == 0:
        logger.debug("No security groups found.")
        return

    for secgroup in secgroups:
        secgroup_name = secgroup['name']
        secgroup_id = secgroup['id']
        logger.debug("'%s', ID=%s " % (secgroup_name, secgroup_id))
        if secgroup_id not in default_security_groups:
            logger.debug(" Removing '%s'..." % secgroup_name)
            if os_utils.delete_security_group(neutron_client, secgroup_id):
                logger.debug("  > Done!")
            else:
                logger.error("There has been a problem removing the "
                             "security group %s..." % secgroup_id)
        else:
            logger.debug("   > this is a default security group and will NOT "
                         "be deleted.")
def remove_security_groups(neutron_client, default_security_groups):
    logger.info("Removing Security groups...")
    secgroups = os_utils.get_security_groups(neutron_client)
    if secgroups is None or len(secgroups) == 0:
        logger.debug("No security groups found.")
        return

    for secgroup in secgroups:
        secgroup_name = secgroup['name']
        secgroup_id = secgroup['id']
        logger.debug("'%s', ID=%s " % (secgroup_name, secgroup_id))
        if secgroup_id not in default_security_groups:
            logger.debug(" Removing '%s'..." % secgroup_name)
            if os_utils.delete_security_group(neutron_client, secgroup_id):
                logger.debug("  > Done!")
            else:
                logger.error("There has been a problem removing the "
                             "security group %s..." % secgroup_id)
        else:
            logger.debug("   > this is a default security group and will NOT "
                         "be deleted.")