예제 #1
0
def _get_neutron_limits():
    limits = {}
    if not CONF.use_neutron:
        return limits
    neutron = neutron_client.client()
    tenant_id = context.ctx().tenant_id
    total_lim = neutron.show_quota(tenant_id)['quota']

    if CONF.use_floating_ips:
        usage_fip = neutron.list_floatingips(
            tenant_id=tenant_id)['floatingips']
        limits['floatingips'] = _sub_limit(total_lim['floatingip'],
                                           len(usage_fip))

    usage_sg = neutron.list_security_groups(
        tenant_id=tenant_id)['security_groups']
    limits['security_groups'] = _sub_limit(total_lim['security_group'],
                                           len(usage_sg))

    usage_sg_rules = (neutron.list_security_group_rules(
        tenant_id=tenant_id)['security_group_rules'])
    limits['security_group_rules'] = _sub_limit(
        total_lim['security_group_rule'], len(usage_sg_rules))

    usage_ports = neutron.list_ports(tenant_id=tenant_id)['ports']
    limits['ports'] = _sub_limit(total_lim['port'], len(usage_ports))

    return limits
예제 #2
0
def _get_neutron_limits():
    limits = {}
    neutron = neutron_client.client()
    tenant_id = context.ctx().tenant_id
    total_lim = b.execute_with_retries(neutron.show_quota, tenant_id)['quota']

    # tmckay-fp here we would just get the limits all the time
    usage_fip = b.execute_with_retries(neutron.list_floatingips,
                                       tenant_id=tenant_id)['floatingips']
    limits['floatingips'] = _sub_limit(total_lim['floatingip'], len(usage_fip))

    usage_sg = b.execute_with_retries(neutron.list_security_groups,
                                      tenant_id=tenant_id).get(
                                          'security_groups', [])
    limits['security_groups'] = _sub_limit(total_lim['security_group'],
                                           len(usage_sg))

    usage_sg_rules = b.execute_with_retries(neutron.list_security_group_rules,
                                            tenant_id=tenant_id).get(
                                                'security_group_rules', [])
    limits['security_group_rules'] = _sub_limit(
        total_lim['security_group_rule'], len(usage_sg_rules))

    usage_ports = b.execute_with_retries(neutron.list_ports,
                                         tenant_id=tenant_id)['ports']
    limits['ports'] = _sub_limit(total_lim['port'], len(usage_ports))

    return limits
예제 #3
0
def init_instances_ips(instance):
    """Extracts internal and management ips.

    As internal ip will be used the first ip from the nova networks CIDRs.
    If use_floating_ip flag is set than management ip will be the first
    non-internal ip.
    """

    server = nova.get_instance_info(instance)

    management_ip = None
    internal_ip = None

    for network_label, addresses in six.iteritems(server.addresses):
        for address in addresses:
            if address['OS-EXT-IPS:type'] == 'fixed':
                internal_ip = internal_ip or address['addr']
            else:
                management_ip = management_ip or address['addr']

    cluster = instance.cluster
    if (not CONF.use_floating_ips or
            (cluster.has_proxy_gateway() and
             not instance.node_group.is_proxy_gateway)):
        management_ip = internal_ip

    # NOTE(aignatov): Once bug #1262529 is fixed this 'if' block should be
    # reviewed and reformatted again, probably removed completely.
    if CONF.use_neutron and not (management_ip and internal_ip):
        LOG.debug("Instance doesn't yet contain Floating IP or Internal IP. "
                  "Floating IP={mgmt_ip}, Internal IP={internal_ip}. "
                  "Trying to get via Neutron.".format(
                      mgmt_ip=management_ip, internal_ip=internal_ip))
        neutron_client = neutron.client()
        ports = b.execute_with_retries(
            neutron_client.list_ports, device_id=server.id)["ports"]
        if ports:
            target_port_id = ports[0]['id']
            fl_ips = b.execute_with_retries(
                neutron_client.list_floatingips,
                port_id=target_port_id)['floatingips']
            if fl_ips:
                fl_ip = fl_ips[0]
                if not internal_ip:
                    internal_ip = fl_ip['fixed_ip_address']
                    LOG.debug('Found fixed IP {internal_ip}'
                              .format(internal_ip=internal_ip))
                # Zeroing management_ip if Sahara in private network
                if not CONF.use_floating_ips:
                    management_ip = internal_ip
                elif not management_ip:
                    management_ip = fl_ip['floating_ip_address']
                    LOG.debug('Found floating IP {mgmt_ip}'
                              .format(mgmt_ip=management_ip))

    conductor.instance_update(context.ctx(), instance,
                              {"management_ip": management_ip,
                               "internal_ip": internal_ip})

    return internal_ip and management_ip
예제 #4
0
파일: quotas.py 프로젝트: openstack/sahara
def _get_neutron_limits():
    limits = {}
    neutron = neutron_client.client()
    tenant_id = context.ctx().tenant_id
    total_lim = b.execute_with_retries(neutron.show_quota, tenant_id)['quota']

    # tmckay-fp here we would just get the limits all the time
    usage_fip = b.execute_with_retries(
        neutron.list_floatingips, tenant_id=tenant_id)['floatingips']
    limits['floatingips'] = _sub_limit(total_lim['floatingip'],
                                       len(usage_fip))

    usage_sg = b.execute_with_retries(
        neutron.list_security_groups, tenant_id=tenant_id).get(
        'security_groups', [])
    limits['security_groups'] = _sub_limit(total_lim['security_group'],
                                           len(usage_sg))

    usage_sg_rules = b.execute_with_retries(
        neutron.list_security_group_rules, tenant_id=tenant_id).get(
        'security_group_rules', [])
    limits['security_group_rules'] = _sub_limit(
        total_lim['security_group_rule'], len(usage_sg_rules))

    usage_ports = b.execute_with_retries(
        neutron.list_ports, tenant_id=tenant_id)['ports']
    limits['ports'] = _sub_limit(total_lim['port'], len(usage_ports))

    return limits
예제 #5
0
def _get_neutron_limits():
    limits = {}
    if not CONF.use_neutron:
        return limits
    neutron = neutron_client.client()
    tenant_id = context.ctx().tenant_id
    total_lim = neutron.show_quota(tenant_id)['quota']

    if CONF.use_floating_ips:
        usage_fip = neutron.list_floatingips(
            tenant_id=tenant_id)['floatingips']
        limits['floatingips'] = _sub_limit(total_lim['floatingip'],
                                           len(usage_fip))

    usage_sg = neutron.list_security_groups(
        tenant_id=tenant_id)['security_groups']
    limits['security_groups'] = _sub_limit(total_lim['security_group'],
                                           len(usage_sg))

    usage_sg_rules = (neutron.list_security_group_rules(
        tenant_id=tenant_id)['security_group_rules'])
    limits['security_group_rules'] = _sub_limit(
        total_lim['security_group_rule'], len(usage_sg_rules))

    usage_ports = neutron.list_ports(tenant_id=tenant_id)['ports']
    limits['ports'] = _sub_limit(total_lim['port'], len(usage_ports))

    return limits
예제 #6
0
def init_instances_ips(instance):
    """Extracts internal and management ips.

    As internal ip will be used the first ip from the nova networks CIDRs.
    If use_floating_ip flag is set than management ip will be the first
    non-internal ip.
    """

    server = nova.get_instance_info(instance)

    management_ip = None
    internal_ip = None

    for network_label, addresses in six.iteritems(server.addresses):
        for address in addresses:
            if address['OS-EXT-IPS:type'] == 'fixed':
                internal_ip = internal_ip or address['addr']
            else:
                management_ip = management_ip or address['addr']

    cluster = instance.cluster
    if (not CONF.use_floating_ips
            or (cluster.has_proxy_gateway()
                and not instance.node_group.is_proxy_gateway)):
        management_ip = internal_ip

    # NOTE(aignatov): Once bug #1262529 is fixed this 'if' block should be
    # reviewed and reformatted again, probably removed completely.
    if CONF.use_neutron and not (management_ip and internal_ip):
        LOG.debug(
            "Instance %s doesn't contain yet Floating IP or Internal IP."
            " Floating IP=%s, Internal IP=%s. Trying to get via Neutron." %
            (server.name, management_ip, internal_ip))
        neutron_client = neutron.client()
        ports = neutron_client.list_ports(device_id=server.id)["ports"]
        if ports:
            target_port_id = ports[0]['id']
            fl_ips = neutron_client.list_floatingips(
                port_id=target_port_id)['floatingips']
            if fl_ips:
                fl_ip = fl_ips[0]
                if not internal_ip:
                    internal_ip = fl_ip['fixed_ip_address']
                    LOG.debug('Found fixed IP %s for %s' %
                              (internal_ip, server.name))
                # Zeroing management_ip if Sahara in private network
                if not CONF.use_floating_ips:
                    management_ip = internal_ip
                elif not management_ip:
                    management_ip = fl_ip['floating_ip_address']
                    LOG.debug('Found floating IP %s for %s' %
                              (management_ip, server.name))

    conductor.instance_update(context.ctx(), instance, {
        "management_ip": management_ip,
        "internal_ip": internal_ip
    })

    return internal_ip and management_ip
예제 #7
0
파일: base.py 프로젝트: stackhpc/sahara
def check_security_groups_exist(security_groups):
    security_group_list = neutron.client().list_security_groups()
    allowed_groups = set()
    for sg in security_group_list['security_groups']:
        allowed_groups.add(sg['name'])
        allowed_groups.add(sg['id'])

    for sg in security_groups:
        if sg not in allowed_groups:
            raise ex.NotFoundException(sg, _("Security group '%s' not found"))
예제 #8
0
파일: base.py 프로젝트: openstack/sahara
def check_security_groups_exist(security_groups):
    security_group_list = neutron.client().list_security_groups()
    allowed_groups = set()
    for sg in security_group_list['security_groups']:
        allowed_groups.add(sg['name'])
        allowed_groups.add(sg['id'])

    for sg in security_groups:
        if sg not in allowed_groups:
            raise ex.NotFoundException(
                sg, _("Security group '%s' not found"))
예제 #9
0
파일: networks.py 프로젝트: uladz/sahara
def init_instances_ips(instance):
    """Extracts internal and management ips.

    As internal ip will be used the first ip from the nova networks CIDRs.
    If use_floating_ip flag is set than management ip will be the first
    non-internal ip.
    """

    server = nova.get_instance_info(instance)

    management_ip = None
    internal_ip = None

    for addresses in six.itervalues(server.addresses):
        # selects IPv4 preferentially
        for address in sorted(addresses, key=lambda addr: addr['version']):
            if address['OS-EXT-IPS:type'] == 'fixed':
                internal_ip = internal_ip or address['addr']
            else:
                management_ip = management_ip or address['addr']

    cluster = instance.cluster
    if (not CONF.use_floating_ips
            or (cluster.has_proxy_gateway()
                and not instance.node_group.is_proxy_gateway)):
        management_ip = internal_ip

    # NOTE(aignatov): Once bug #1262529 is fixed this 'if' block should be
    # reviewed and reformatted again, probably removed completely.
    if CONF.use_neutron and not (management_ip and internal_ip):
        LOG.debug("Instance doesn't yet contain Floating IP or Internal IP. "
                  "Floating IP={mgmt_ip}, Internal IP={internal_ip}. "
                  "Trying to get via Neutron.".format(mgmt_ip=management_ip,
                                                      internal_ip=internal_ip))
        neutron_client = neutron.client()
        ports = b.execute_with_retries(neutron_client.list_ports,
                                       device_id=server.id)["ports"]
        if ports:
            target_port_id = ports[0]['id']
            fl_ips = b.execute_with_retries(
                neutron_client.list_floatingips,
                port_id=target_port_id)['floatingips']
            if fl_ips:
                fl_ip = fl_ips[0]
                if not internal_ip:
                    internal_ip = fl_ip['fixed_ip_address']
                    LOG.debug('Found fixed IP {internal_ip}'.format(
                        internal_ip=internal_ip))
                # Zeroing management_ip if Sahara in private network
                if not CONF.use_floating_ips:
                    management_ip = internal_ip
                elif not management_ip:
                    management_ip = fl_ip['floating_ip_address']
                    LOG.debug('Found floating IP {mgmt_ip}'.format(
                        mgmt_ip=management_ip))

    conductor.instance_update(context.ctx(), instance, {
        "management_ip": management_ip,
        "internal_ip": internal_ip
    })

    return internal_ip and management_ip