Ejemplo n.º 1
0
 def test_get_keystone_client(self, client_mock, environ):
     clients.get_keystone_client()
     client_mock.assert_called_once_with(
         username=environ["OS_USERNAME"],
         password=environ["OS_PASSWORD"],
         auth_url=environ["OS_AUTH_URL"],
         tenant_name=environ["OS_TENANT_NAME"])
Ejemplo n.º 2
0
 def test_get_keystone_client(self, client_mock, environ):
     clients.get_keystone_client()
     client_mock.assert_called_once_with(
         username=environ["OS_USERNAME"],
         password=environ["OS_PASSWORD"],
         auth_url=environ["OS_AUTH_URL"],
         tenant_name=environ["OS_TENANT_NAME"])
Ejemplo n.º 3
0
def using_ironic(keystone=None):
    LOG.debug('Checking for usage of ironic.')
    if keystone is None:
        LOG.warn('Creating keystone client inline is deprecated, please pass '
                 'the client as parameter.')
        keystone = clients.get_keystone_client()
    return 'ironic' in [service.name for service in keystone.services.list()]
Ejemplo n.º 4
0
def using_ironic(keystone=None):
    LOG.debug('Checking for usage of ironic.')
    if keystone is None:
        LOG.warn('Creating keystone client inline is deprecated, please pass '
                 'the client as parameter.')
        keystone = clients.get_keystone_client()
    return 'ironic' in [service.name for service in keystone.services.list()]
Ejemplo n.º 5
0
def main():
    args = parse_args()
    environment._configure_logging(args)

    try:
        with open(args.nodes, 'r') as node_file:
            nodes_list = json.load(node_file)
        environment._ensure()

        keystone_client = _clients.get_keystone_client()
        glance_client = _clients.get_glance_client()
        client = _clients.get_ironic_client()

        nodes.register_all_nodes(args.service_host,
                                 nodes_list,
                                 client=client,
                                 remove=args.remove,
                                 blocking=True,
                                 keystone_client=keystone_client,
                                 glance_client=glance_client,
                                 kernel_name=args.kernel_name,
                                 ramdisk_name=args.ramdisk_name)
    except Exception:
        logging.exception("Unexpected error during command execution")
        return 1
    return 0
Ejemplo n.º 6
0
def initialize_neutron(network_desc,
                       neutron_client=None,
                       keystone_client=None):
    if not neutron_client:
        LOG.warn('Creating neutron client inline is deprecated, please pass '
                 'the client as parameter.')
        neutron_client = clients.get_neutron_client()
    if not keystone_client:
        LOG.warn('Creating keystone client inline is deprecated, please pass '
                 'the client as parameter.')
        keystone_client = clients.get_keystone_client()

    admin_tenant = _get_admin_tenant_id(keystone_client)
    if 'physical' in network_desc:
        network_type = 'physical'
        if not admin_tenant:
            raise ValueError("No admin tenant registered in Keystone")
        if not network_desc['physical']['metadata_server']:
            raise ValueError("metadata_server is required for physical "
                             "networks")
    elif 'float' in network_desc:
        network_type = 'float'
    else:
        raise ValueError("No float or physical network defined.")
    net = _create_net(neutron_client, network_desc, network_type, admin_tenant)
    subnet = _create_subnet(neutron_client, net, network_desc, network_type,
                            admin_tenant)
    if 'external' in network_desc:
        router = _create_router(neutron_client, subnet)
        ext_net = _create_net(neutron_client, network_desc, 'external', None)
        _create_subnet(neutron_client, ext_net, network_desc, 'external', None)
        neutron_client.add_gateway_router(
            router['router']['id'], {'network_id': ext_net['network']['id']})
    LOG.debug("Neutron configured.")
Ejemplo n.º 7
0
def initialize_neutron(network_desc, neutron_client=None,
                       keystone_client=None):
    if not neutron_client:
        LOG.warn('Creating neutron client inline is deprecated, please pass '
                 'the client as parameter.')
        neutron_client = clients.get_neutron_client()
    if not keystone_client:
        LOG.warn('Creating keystone client inline is deprecated, please pass '
                 'the client as parameter.')
        keystone_client = clients.get_keystone_client()

    admin_tenant = _get_admin_tenant_id(keystone_client)
    if 'physical' in network_desc:
        network_type = 'physical'
        if not admin_tenant:
            raise ValueError("No admin tenant registered in Keystone")
        if not network_desc['physical']['metadata_server']:
            raise ValueError("metadata_server is required for physical "
                             "networks")
    elif 'float' in network_desc:
        network_type = 'float'
    else:
        raise ValueError("No float or physical network defined.")
    net = _create_net(neutron_client, network_desc, network_type, admin_tenant)
    subnet = _create_subnet(neutron_client, net, network_desc, network_type,
                            admin_tenant)
    if 'external' in network_desc:
        router = _create_router(neutron_client, subnet)
        ext_net = _create_net(neutron_client, network_desc, 'external', None)
        _create_subnet(neutron_client, ext_net, network_desc, 'external', None)
        neutron_client.add_gateway_router(
            router['router']['id'], {'network_id': ext_net['network']['id']})
    LOG.debug("Neutron configured.")
Ejemplo n.º 8
0
def main():
    args = parse_args()
    environment._configure_logging(args)

    try:
        environment._ensure()
        with open(args.json, 'r') as jsonfile:
            network_desc = json.load(jsonfile)

        neutron_client = _clients.get_neutron_client()
        keystone_client = _clients.get_keystone_client()
        neutron.initialize_neutron(network_desc,
                                   neutron_client=neutron_client,
                                   keystone_client=keystone_client)
    except Exception:
        logging.exception("Unexpected error during command execution")
        return 1
    return 0
Ejemplo n.º 9
0
def main(stdout=None):
    args = parse_args()
    environment._configure_logging(args)

    if os.path.isfile(args.services):
        with open(args.services, 'r') as service_file:
            services = simplejson.load(service_file)
    else:
        # we assume it's just JSON string
        services = simplejson.loads(args.services)

    client = _clients.get_keystone_client()

    keystone.setup_endpoints(services,
                             public_host=args.public_host,
                             region=args.region,
                             os_auth_url=os.environ["OS_AUTH_URL"],
                             client=client)
Ejemplo n.º 10
0
def main(stdout=None):
    args = parse_args()
    environment._configure_logging(args)

    if os.path.isfile(args.services):
        with open(args.services, 'r') as service_file:
            services = simplejson.load(service_file)
    else:
        # we assume it's just JSON string
        services = simplejson.loads(args.services)

    client = _clients.get_keystone_client()

    keystone.setup_endpoints(
        services,
        public_host=args.public_host,
        region=args.region,
        os_auth_url=os.environ["OS_AUTH_URL"],
        client=client)
Ejemplo n.º 11
0
def main():
    args = parse_args()
    environment._configure_logging(args)

    try:
        with open(args.nodes, 'r') as node_file:
            nodes_list = json.load(node_file)
        environment._ensure()

        keystone_client = _clients.get_keystone_client()
        if nodes.using_ironic(keystone=keystone_client):
            client = _clients.get_ironic_client()
        else:
            client = _clients.get_nova_bm_client()

        nodes.register_all_nodes(
            args.service_host, nodes_list, client=client, remove=args.remove)
    except Exception:
        logging.exception("Unexpected error during command execution")
        return 1
    return 0
Ejemplo n.º 12
0
def main():
    args = parse_args()
    environment._configure_logging(args)

    try:
        with open(args.nodes, 'r') as node_file:
            nodes_list = json.load(node_file)
        environment._ensure()

        keystone_client = _clients.get_keystone_client()
        glance_client = _clients.get_glance_client()
        client = _clients.get_ironic_client()

        nodes.register_all_nodes(
            args.service_host, nodes_list, client=client, remove=args.remove,
            blocking=True, keystone_client=keystone_client,
            glance_client=glance_client, kernel_name=args.kernel_name,
            ramdisk_name=args.ramdisk_name)
    except Exception:
        logging.exception("Unexpected error during command execution")
        return 1
    return 0
Ejemplo n.º 13
0
def main():
    args = parse_args()
    environment._configure_logging(args)

    try:
        with open(args.nodes, 'r') as node_file:
            nodes_list = json.load(node_file)
        environment._ensure()

        keystone_client = _clients.get_keystone_client()
        if nodes.using_ironic(keystone=keystone_client):
            client = _clients.get_ironic_client()
        else:
            client = _clients.get_nova_bm_client()

        nodes.register_all_nodes(args.service_host,
                                 nodes_list,
                                 client=client,
                                 remove=args.remove)
    except Exception:
        logging.exception("Unexpected error during command execution")
        return 1
    return 0