Ejemplo n.º 1
0
def create(nova_client, args, **kwargs):
    if use_external_resource(ctx, nova_client, FLAVOR_OPENSTACK_TYPE):
        return

    flavor_dict = create_object_dict(ctx, FLAVOR_OPENSTACK_TYPE, args, {})
    flavor = nova_client.flavors.create(**flavor_dict)
    set_openstack_runtime_properties(ctx, flavor, FLAVOR_OPENSTACK_TYPE)
def update_project(keystone_client, args, **kwargs):

    project_dict = create_object_dict(ctx, PROJECT_OPENSTACK_TYPE, args,
                                      {'domain': 'default'})
    project_dict[PROJECT_OPENSTACK_TYPE] = get_openstack_id(ctx)
    project = keystone_client.projects.update(**project_dict)
    set_openstack_runtime_properties(ctx, project, PROJECT_OPENSTACK_TYPE)
Ejemplo n.º 3
0
def create(keystone_client, args, **kwargs):
    if use_external_resource(ctx, keystone_client, USER_OPENSTACK_TYPE):
        return

    user_dict = create_object_dict(ctx, USER_OPENSTACK_TYPE, args, {})
    user = keystone_client.users.create(**user_dict)

    set_openstack_runtime_properties(ctx, user, USER_OPENSTACK_TYPE)
Ejemplo n.º 4
0
def update(nova_client, args, **kwargs):
    if HOST_AGGREGATE_OPENSTACK_TYPE in args:
        host_aggregate = nova_client.aggregates.update(
            get_openstack_id(ctx), args.get(HOST_AGGREGATE_OPENSTACK_TYPE))

        set_openstack_runtime_properties(ctx, host_aggregate,
                                         HOST_AGGREGATE_OPENSTACK_TYPE)

    _set_metadata(ctx, nova_client, get_openstack_id(ctx), args)
def create(keystone_client, args, **kwargs):
    if use_external_resource(ctx, keystone_client, PROJECT_OPENSTACK_TYPE):
        return

    project_dict = create_object_dict(ctx, PROJECT_OPENSTACK_TYPE, args,
                                      {'domain': 'default'})

    project = keystone_client.projects.create(**project_dict)
    set_openstack_runtime_properties(ctx, project, PROJECT_OPENSTACK_TYPE)
def create(nova_client, args, **kwargs):
    if use_external_resource(ctx, nova_client, SERVER_GROUP_OPENSTACK_TYPE):
        return

    server_grp = create_object_dict(
        ctx, SERVER_GROUP_OPENSTACK_TYPE, args,
        {'policies': [ctx.node.properties['policy']]})

    server_grp = nova_client.server_groups.create(**server_grp)
    set_openstack_runtime_properties(ctx, server_grp,
                                     SERVER_GROUP_OPENSTACK_TYPE)
Ejemplo n.º 7
0
def create(nova_client, args, **kwargs):
    if use_external_resource(ctx, nova_client, FLAVOR_OPENSTACK_TYPE):
        return

    flavor_dict = create_object_dict(ctx, FLAVOR_OPENSTACK_TYPE, args, {})
    ctx.logger.info('Creating flavor: {0}'.format(flavor_dict))

    flavor = nova_client.flavors.create(**flavor_dict)
    set_openstack_runtime_properties(ctx, flavor, FLAVOR_OPENSTACK_TYPE)

    _set_extra_specs(ctx, flavor)
    _set_tenants_access(ctx, nova_client, flavor)
def update(nova_client, args, **kwargs):
    host_aggregate_dict = create_object_dict(ctx,
                                             HOST_AGGREGATE_OPENSTACK_TYPE,
                                             args)

    _remove_hosts(ctx, nova_client, get_openstack_id(ctx), kwargs)
    host_aggregate = nova_client.aggregates.update(get_openstack_id(ctx),
                                                   host_aggregate_dict)
    _add_hosts(ctx, nova_client, host_aggregate, kwargs)
    _set_metadata(ctx, nova_client, host_aggregate, kwargs)

    set_openstack_runtime_properties(ctx, host_aggregate,
                                     HOST_AGGREGATE_OPENSTACK_TYPE)
def create(nova_client, args, **kwargs):
    if use_external_resource(ctx, nova_client, HOST_AGGREGATE_OPENSTACK_TYPE):
        return

    host_aggregate_dict = create_object_dict(ctx,
                                             HOST_AGGREGATE_OPENSTACK_TYPE,
                                             args)

    host_aggregate = nova_client.aggregates.create(**host_aggregate_dict)
    _add_hosts(ctx, nova_client, host_aggregate, kwargs)
    _set_metadata(ctx, nova_client, host_aggregate, kwargs)

    set_openstack_runtime_properties(ctx, host_aggregate,
                                     HOST_AGGREGATE_OPENSTACK_TYPE)
Ejemplo n.º 10
0
def create(nova_client, args, **kwargs):

    private_key_path = _get_private_key_path()
    pk_exists = _check_private_key_exists(private_key_path)

    if use_external_resource(ctx, nova_client, KEYPAIR_OPENSTACK_TYPE):
        if not pk_exists:
            delete_runtime_properties(ctx, RUNTIME_PROPERTIES_KEYS)
            raise NonRecoverableError(
                'Failed to use external keypair (node {0}): the public key {1}'
                ' is available on Openstack, but the private key could not be '
                'found at {2}'.format(ctx.node.id,
                                      ctx.node.properties['resource_id'],
                                      private_key_path))
        return

    if pk_exists:
        raise NonRecoverableError(
            "Can't create keypair - private key path already exists: {0}".
            format(private_key_path))

    keypair = create_object_dict(ctx, KEYPAIR_OPENSTACK_TYPE, args, {})

    keypair = nova_client.keypairs.create(keypair['name'],
                                          keypair.get('public_key'))

    set_openstack_runtime_properties(ctx, keypair, KEYPAIR_OPENSTACK_TYPE)

    try:
        # write private key file
        _mkdir_p(os.path.dirname(private_key_path))
        with open(private_key_path, 'w') as f:
            f.write(keypair.private_key)
        os.chmod(private_key_path, 0600)
    except Exception:
        _delete_private_key_file()
        delete_resource_and_runtime_properties(ctx, nova_client,
                                               RUNTIME_PROPERTIES_KEYS)
        raise
Ejemplo n.º 11
0
def create(glance_client, args, **kwargs):
    if use_external_resource(ctx, glance_client, IMAGE_OPENSTACK_TYPE):
        return

    _validate_image_dictionary()
    img_dict = create_object_dict(ctx, IMAGE_OPENSTACK_TYPE, args, {})
    img_path = img_dict.pop('data', '')
    img = glance_client.images.create(**img_dict)
    img_url = ctx.node.properties.get('image_url')
    try:
        _validate_image()
        if img_path:
            with open(img_path, 'rb') as image_file:
                glance_client.images.upload(image_id=img.id,
                                            image_data=image_file)
        elif img_url:
            img = glance_client.images.add_location(img.id, img_url, {})
    except Exception:
        _remove_protected(glance_client)
        glance_client.images.delete(image_id=img.id)
        raise

    set_openstack_runtime_properties(ctx, img, IMAGE_OPENSTACK_TYPE)
Ejemplo n.º 12
0
def update(glance_client, args, **kwargs):
    image_dict = create_object_dict(ctx, IMAGE_OPENSTACK_TYPE, args)
    image_dict[IMAGE_OPENSTACK_TYPE] = get_openstack_id(ctx)
    image = glance_client.images.update(**image_dict)
    set_openstack_runtime_properties(ctx, image, IMAGE_OPENSTACK_TYPE)
Ejemplo n.º 13
0
def update(keystone_client, args, **kwargs):
    user_dict = create_object_dict(ctx, USER_OPENSTACK_TYPE, args, {})
    user_dict[USER_OPENSTACK_TYPE] = get_openstack_id(ctx)
    user = keystone_client.users.update(**user_dict)
    set_openstack_runtime_properties(ctx, user, USER_OPENSTACK_TYPE)