Esempio n. 1
0
def os_try_access(username,
                  password,
                  tenant,
                  ip,
                  timeout=5,
                  region=None,
                  auth_url=None,
                  log=None):
    (kip, kport, auth_url) = ks_ip_port(ip, auth_url=auth_url)
    rc, msg = verify_connectivity(kip, kport)
    if not rc:
        return (None, msg)

    skwopts = {'timeout': 60, 'verify': False}
    ckwopts = {'connect_retries': const.CONNECT_RETRIES, 'region_name': region}
    try:
        rc, uksc, tksc = ks_clients(auth_url,
                                    username,
                                    password,
                                    pd_name=tenant,
                                    skwopts=skwopts,
                                    ckwopts=ckwopts,
                                    logger=log)
        eps = get_endpoints(tksc, eptype='public', region=region)
        for ep in ENDPOINTS:
            if not eps.get(ep):
                msg = (
                    'Endpoint for %s not found in region %s (possibly bad region)'
                    % (ep, region))
                return (None, msg)
    except Exception as e:
        msg = str(e)
        return (None, msg)

    return (tksc, 'Success')
Esempio n. 2
0
def main():
    ds = datastore.Datastore()
    cuuid, oscfg = fetch_oscfg(ds)
    if not oscfg:
        log.error("OpenStack Configuration not found!")
        sys.exit(1)

    (kip, kport, auth_url) = osutils.ks_ip_port(oscfg.keystone_host,
                                                auth_url=oscfg.auth_url)
    ksc, err = os_try_access(oscfg.username, oscfg.password,
                             oscfg.admin_tenant, oscfg.keystone_host,
                             const.REQUEST_TIMEOUT, oscfg.region,
                             auth_url=auth_url, log=log)
    if not ksc:
        log.error("Cloudn't establish connection to OpenStack, error: "
                  "%s", err)
        sys.exit(1)

    eptype = 'internal' if oscfg.use_internal_endpoints else 'public'
    ckwopts = {'connect_retries': const.CONNECT_RETRIES,
               'region_name': oscfg.region, 'interface': eptype}
    neuc = nnclient.Client('2', session=ksc.session,
                           retries=const.API_RETRIES, **ckwopts)

    # Get all SEs from DB
    # For each SE, get all ports using device_id field,
    # and update the AAP entry if it has it.
    ses = ds.get_all('serviceengine')
    for se in ses:
        secfg = se['config']
        if secfg.cloud_uuid != cuuid:
            continue

        devid = secfg.uuid.split('se-')[1]
        log.info("Updating ports for se %s, %s", secfg.name, devid)
        data = neuc.list_ports(device_id=devid)
        ports = data.get('ports', [])
        for port in ports:
            aaps = port.get('allowed_address_pairs', [])
            if not aaps:
                continue

            new_aaps = []
            for aap in aaps:
                tokens = aap['ip_address'].split('/')
                if len(tokens) < 2:
                    continue

                ip = tokens[0] + '/%s' % '32'
                naap = {'ip_address': ip}
                if aap.get('mac_address', None):
                    naap['mac_address'] = aap['mac_address']

                new_aaps.append(naap)

            if new_aaps:
                body = {'port': {'allowed_address_pairs': new_aaps}}
                neuc.update_port(port=port['id'], body=body)
                log.info("Updated port %s with new AAP %s", port['name'],
                         new_aaps)
Esempio n. 3
0
def get_neuc(tname):
    global ksc
    _, oscfg = fetch_oscfg()
    if not oscfg:
        log.error("OpenStack Configuration not found!")
        sys.exit(1)

    (_, _, auth_url) = osutils.ks_ip_port(oscfg.keystone_host,
                                          auth_url=oscfg.auth_url)
    aneuc, ksc = get_tneuc(oscfg.admin_tenant, auth_url, oscfg)
    if tname == oscfg.admin_tenant:
        tneuc = aneuc
    else:
        tneuc, _ = get_tneuc(tname, auth_url, oscfg)

    return aneuc, tneuc
Esempio n. 4
0
def get_clients(oscfg):
    (_, _, auth_url) = osutils.ks_ip_port(oscfg.keystone_host,
                                          auth_url=oscfg.auth_url)
    return get_cls(oscfg.admin_tenant, auth_url, oscfg)