Exemple #1
0
def get_openstack_info():
    cloud_config = OpenStackConfig().get_one_cloud(
        cloud=os_environ.get('OS_CLOUD'))

    keystone_session = keystoneauth1_session.Session(
        auth=cloud_config.get_auth(), verify=cloud_config.verify)

    keystone = keystoneclient_v3.client.Client(
        session=keystone_session,
        debug=True,
        interface=cloud_config.get_interface())
    keystone_projects = keystone.projects.list()

    neutron = neutronclient_v2_0.Client(session=keystone_session)
    networks = neutron.list_networks()['networks']
    subnets = neutron.list_subnets()['subnets']

    networks = [
        n for n in networks
        if n['tenant_id'] in [p.id for p in keystone_projects]
    ]
    subnets = [
        s for s in subnets if s['network_id'] in [n['id'] for n in networks]
    ]
    return (networks, subnets)
Exemple #2
0
def get_regions(cloud_name, yaml_file):
    occ = OpenStackConfig(config_files=[yaml_file])
    return occ._get_regions(cloud_name)
Exemple #3
0
def _connect(cloud_name, region, yaml_file):
    occ = OpenStackConfig(config_files=[yaml_file])
    cloud = occ.get_one_cloud(cloud_name, region_name=region)
    _cloud_name = cloud.get_auth_args().get('project_id')
    return (_cloud_name, connection.from_config(cloud_config=cloud))
Exemple #4
0
                    default=None,
                    help='Name or ID of network to attach')
parser.add_argument('-T',
                    '--timeout',
                    type=int,
                    default=10,
                    help='Maximum number of minutes to wait for shutdown.')
args = parser.parse_args()

userdata = ('#!/bin/sh\n' + '# Image and Kickstart URLs\n' + 'vmlinuz_url=' +
            args.mirrorurl + 'images/pxeboot/vmlinuz\n' + 'initrd_url=' +
            args.mirrorurl + 'images/pxeboot/initrd.img\n' + 'ks_url=' +
            args.ksurl + '\n' + BOOTSTRAP_SCRIPT)

# Connect to Openstack API using config from environment or files
cfg = OpenStackConfig(pw_func=getpass)
if args.cloud:
    envauth = shade.openstack_cloud().auth
    cloud = shade.openstack_cloud(config=cfg, cloud=args.cloud, **envauth)
else:
    cloud = shade.openstack_clouds(config=cfg)[0]

# Set up argument list for create_server call
kwargs = {'security_groups': [args.secgroup], 'userdata': userdata}
if args.key: kwargs['key_name'] = args.key

# Pick a network
if args.network: kwargs['network'] = args.network
else: kwargs['network'] = cloud.list_networks()[0]['id']

# Set disk mapping if needed