예제 #1
0
def list_volume_snapshots(volume_id, profile, **libcloud_kwargs):
    '''
    Return a list of storage volumes snapshots for this cloud

    :param volume_id: The volume identifier
    :type  volume_id: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's list_volume_snapshots method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.list_volume_snapshots vol1 profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    volume = _get_by_id(conn.list_volumes(), volume_id)
    snapshots = conn.list_volume_snapshots(volume, **libcloud_kwargs)

    ret = []
    for snapshot in snapshots:
        ret.append(_simple_volume_snapshot(snapshot))
    return ret
예제 #2
0
def attach_volume(node_id, volume_id, profile, device=None, **libcloud_kwargs):
    '''
    Attaches volume to node.

    :param node_id:  Node ID to target
    :type  node_id: ``str``

    :param volume_id:  Volume ID from which to attach
    :type  volume_id: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param device: Where the device is exposed, e.g. '/dev/sdb'
    :type device: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's attach_volume method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.detach_volume vol1 profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    volume = _get_by_id(conn.list_volumes(), volume_id)
    node = _get_by_id(conn.list_nodes(), node_id)
    return conn.attach_volume(node, volume, device=device, **libcloud_kwargs)
예제 #3
0
def create_volume_snapshot(volume_id, profile, name=None, **libcloud_kwargs):
    '''
    Create a storage volume snapshot

    :param volume_id:  Volume ID from which to create the new
                        snapshot.
    :type  volume_id: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param name: Name of the snapshot to be created (optional)
    :type name: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's create_volume_snapshot method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.create_volume_snapshot vol1 profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    volume = _get_by_id(conn.list_volumes(), volume_id)

    snapshot = conn.create_volume_snapshot(volume,
                                           name=name,
                                           **libcloud_kwargs)
    return _simple_volume_snapshot(snapshot)
예제 #4
0
def destroy_volume_snapshot(volume_id, snapshot_id, profile,
                            **libcloud_kwargs):
    '''
    Destroy a volume snapshot.

    :param volume_id:  Volume ID from which the snapshot belongs
    :type  volume_id: ``str``

    :param snapshot_id:  Volume Snapshot ID from which to destroy
    :type  snapshot_id: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's destroy_volume_snapshot method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.destroy_volume_snapshot snap1 profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    volume = _get_by_id(conn.list_volumes(), volume_id)
    snapshot = _get_by_id(conn.list_volume_snapshots(volume), snapshot_id)
    return conn.destroy_volume_snapshot(snapshot, **libcloud_kwargs)
예제 #5
0
def balancer_attach_member(balancer_id, ip, port, profile, extra=None, **libcloud_kwargs):
    '''
    Add a new member to the load balancer

    :param balancer_id: id of a load balancer you want to fetch
    :type  balancer_id: ``str``

    :param ip: IP address for the new member
    :type  ip: ``str``

    :param port: Port for the new member
    :type  port: ``int``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's balancer_attach_member method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_storage.balancer_attach_member balancer123 1.2.3.4 80 profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    member = Member(id=None, ip=ip, port=port, balancer=None, extra=extra)
    balancer = conn.get_balancer(balancer_id)
    member_saved = conn.balancer_attach_member(balancer, member, **libcloud_kwargs)
    return _simple_member(member_saved)
예제 #6
0
def get_balancer_by_name(name, profile, **libcloud_kwargs):
    '''
    Get the details for a load balancer by name

    :param name: Name of a load balancer you want to fetch
    :type  name: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's list_balancers method
    :type  libcloud_kwargs: ``dict``

    :return: the load balancer details

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_storage.get_balancer_by_name my_balancer profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    balancers = conn.list_balancers(**libcloud_kwargs)
    match = [b for b in balancers if b.name == name]
    if len(match) == 1:
        return _simple_balancer(match[0])
    elif len(match) > 1:
        raise ValueError("Ambiguous argument, found mulitple records")
    else:
        raise ValueError("Bad argument, found no records")
예제 #7
0
def get_balancer(balancer_id, profile, **libcloud_kwargs):
    '''
    Get the details for a load balancer by ID

    :param balancer_id: id of a load balancer you want to fetch
    :type  balancer_id: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's get_balancer method
    :type  libcloud_kwargs: ``dict``

    :return: the load balancer details

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_storage.get_balancer balancer123 profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    balancer = conn.get_balancer(balancer_id, **libcloud_kwargs)
    return _simple_balancer(balancer)
예제 #8
0
def list_images(profile, location_id=None, **libcloud_kwargs):
    '''
    Return a list of images for this cloud

    :param profile: The profile key
    :type  profile: ``str``

    :param location_id: The location key, from list_locations
    :type  location_id: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's list_images method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.list_images profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    if location_id is not None:
        location = _get_by_id(conn.list_locations(), location_id)
    else:
        location = None
    images = conn.list_images(location=location, **libcloud_kwargs)

    ret = []
    for image in images:
        ret.append(_simple_image(image))
    return ret
예제 #9
0
def destroy_balancer(balancer_id, profile, **libcloud_kwargs):
    '''
    Destroy a load balancer

    :param balancer_id: LoadBalancer ID which should be used
    :type  balancer_id: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's destroy_balancer method
    :type  libcloud_kwargs: ``dict``

    :return: ``True`` if the destroy was successful, otherwise ``False``.
    :rtype: ``bool``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_storage.destroy_balancer balancer_1 profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    balancer = conn.get_balancer(balancer_id)
    return conn.destroy_balancer(balancer, **libcloud_kwargs)
예제 #10
0
def delete_container(container_name, profile, **libcloud_kwargs):
    '''
    Delete an object container in the cloud

    :param container_name: Container name
    :type  container_name: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's delete_container method
    :type  libcloud_kwargs: ``dict``

    :return: True if an object container has been successfully deleted, False
                otherwise.
    :rtype: ``bool``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_storage.delete_container MyFolder profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    container = conn.get_container(container_name)
    return conn.delete_container(container, **libcloud_kwargs)
예제 #11
0
def create_image(node_id, name, profile, description=None, **libcloud_kwargs):
    '''
    Create an image from a node

    :param node_id: Node to run the task on.
    :type node_id: ``str``

    :param name: name for new image.
    :type name: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param description: description for new image.
    :type description: ``description``

    :param libcloud_kwargs: Extra arguments for the driver's create_image method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.create_image server1 my_image profile1
        salt myminion libcloud_compute.create_image server1 my_image profile1 description='test image'
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    node = _get_by_id(conn.list_nodes(), node_id)
    return _simple_image(
        conn.create_image(node,
                          name,
                          description=description,
                          **libcloud_kwargs))
예제 #12
0
def import_key_pair(name, key, profile, key_type=None, **libcloud_kwargs):
    '''
    Import a new public key from string or a file path

    :param name: Key pair name.
    :type name: ``str``

    :param key: Public key material, the string or a path to a file
    :type  key: ``str`` or path ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param key_type: The key pair type, either `FILE` or `STRING`. Will detect if not provided
        and assume that if the string is a path to an existing path it is a FILE, else STRING.
    :type  key_type: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's import_key_pair_from_xxx method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.import_key_pair pair1 key_value_data123 profile1
        salt myminion libcloud_compute.import_key_pair pair1 /path/to/key profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    if os.path.exists(key) or key_type == 'FILE':
        return _simple_key_pair(
            conn.import_key_pair_from_file(name, key, **libcloud_kwargs))
    else:
        return _simple_key_pair(
            conn.import_key_pair_from_string(name, key, **libcloud_kwargs))
예제 #13
0
def get_container_object(container_name, object_name, profile,
                         **libcloud_kwargs):
    '''
    Get the details for a container object (file or object in the cloud)

    :param container_name: Container name
    :type  container_name: ``str``

    :param object_name: Object name
    :type  object_name: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's get_container_object method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_storage.get_container_object MyFolder MyFile.xyz profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    obj = conn.get_container_object(container_name, object_name,
                                    **libcloud_kwargs)
    return {
        'name': obj.name,
        'size': obj.size,
        'hash': obj.hash,
        'container': obj.container.name,
        'extra': obj.extra,
        'meta_data': obj.meta_data
    }
예제 #14
0
def list_container_objects(container_name, profile, **libcloud_kwargs):
    '''
    List container objects (e.g. files) for the given container_id on the given profile

    :param container_name: Container name
    :type  container_name: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's list_container_objects method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_storage.list_container_objects MyFolder profile1
    '''
    conn = _get_driver(profile=profile)
    container = conn.get_container(container_name)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    objects = conn.list_container_objects(container, **libcloud_kwargs)
    ret = []
    for obj in objects:
        ret.append({
            'name': obj.name,
            'size': obj.size,
            'hash': obj.hash,
            'container': obj.container.name,
            'extra': obj.extra,
            'meta_data': obj.meta_data
        })
    return ret
예제 #15
0
def all_removed(name, **kwargs):
    '''
    Removes all containers from the host. Note this also applies to containers that are not on any map.

    name
        State name - has no effect.
    kwargs
        Keyword arguments forwarded to ``container_map.remove_all_containers``.
    '''
    res = __salt__['container_map.remove_all_containers'](**clean_kwargs(**kwargs))
    res['name'] = '__all__'
    return res
예제 #16
0
def upload_object(file_path,
                  container_name,
                  object_name,
                  profile,
                  extra=None,
                  verify_hash=True,
                  headers=None,
                  **libcloud_kwargs):
    '''
    Upload an object currently located on a disk.

    :param file_path: Path to the object on disk.
    :type file_path: ``str``

    :param container_name: Destination container.
    :type container_name: ``str``

    :param object_name: Object name.
    :type object_name: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param verify_hash: Verify hash
    :type verify_hash: ``bool``

    :param extra: Extra attributes (driver specific). (optional)
    :type extra: ``dict``

    :param headers: (optional) Additional request headers,
        such as CORS headers. For example:
        headers = {'Access-Control-Allow-Origin': 'http://mozilla.com'}
    :type headers: ``dict``

    :param libcloud_kwargs: Extra arguments for the driver's upload_object method
    :type  libcloud_kwargs: ``dict``

    :return: The object name in the cloud
    :rtype: ``str``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_storage.upload_object /file/to/me.jpg MyFolder me.jpg profile1

    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    container = conn.get_container(container_name)
    obj = conn.upload_object(file_path, container, object_name, extra,
                             verify_hash, headers, **libcloud_kwargs)
    return obj.name
def all_removed(name, **kwargs):
    '''
    Removes all containers from the host. Note this also applies to containers that are not on any map.

    name
        State name - has no effect.
    kwargs
        Keyword arguments forwarded to ``container_map.remove_all_containers``.
    '''
    res = __salt__['container_map.remove_all_containers'](**clean_kwargs(
        **kwargs))
    res['name'] = '__all__'
    return res
예제 #18
0
def download_object(container_name,
                    object_name,
                    destination_path,
                    profile,
                    overwrite_existing=False,
                    delete_on_failure=True,
                    **libcloud_kwargs):
    '''
    Download an object to the specified destination path.

    :param container_name: Container name
    :type  container_name: ``str``

    :param object_name: Object name
    :type  object_name: ``str``

    :param destination_path: Full path to a file or a directory where the
                                incoming file will be saved.
    :type destination_path: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param overwrite_existing: True to overwrite an existing file,
                                defaults to False.
    :type overwrite_existing: ``bool``

    :param delete_on_failure: True to delete a partially downloaded file if
                                the download was not successful (hash
                                mismatch / file size).
    :type delete_on_failure: ``bool``

    :param libcloud_kwargs: Extra arguments for the driver's download_object method
    :type  libcloud_kwargs: ``dict``

    :return: True if an object has been successfully downloaded, False
                otherwise.
    :rtype: ``bool``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_storage.download_object MyFolder me.jpg /tmp/me.jpg profile1

    '''
    conn = _get_driver(profile=profile)
    obj = conn.get_object(container_name, object_name)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    return conn.download_object(obj, destination_path, overwrite_existing,
                                delete_on_failure, **libcloud_kwargs)
예제 #19
0
def create_balancer(name, port, protocol, profile, algorithm=None, members=None, **libcloud_kwargs):
    '''
    Create a new load balancer instance

    :param name: Name of the new load balancer (required)
    :type  name: ``str``

    :param port: Port the load balancer should listen on, defaults to 80
    :type  port: ``str``

    :param protocol: Loadbalancer protocol, defaults to http.
    :type  protocol: ``str``

    :param algorithm: Load balancing algorithm, defaults to ROUND_ROBIN. See Algorithm type
        in Libcloud documentation for a full listing.
    :type algorithm: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's create_balancer method
    :type  libcloud_kwargs: ``dict``

    :return: The details of the new balancer

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_storage.create_balancer my_balancer 80 http profile1
    '''
    if algorithm is None:
        algorithm = Algorithm.ROUND_ROBIN
    else:
        if isinstance(algorithm, six.string_types):
            algorithm = _algorithm_maps()[algorithm]
    starting_members = []
    if members is not None:
        if isinstance(members, list):
            for m in members:
                starting_members.append(Member(id=None, ip=m['ip'], port=m['port']))
        else:
            raise ValueError("members must be of type list")

    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    conn = _get_driver(profile=profile)
    balancer = conn.create_balancer(name, port, protocol, algorithm, starting_members, **libcloud_kwargs)
    return _simple_balancer(balancer)
예제 #20
0
def _get_endpoint(endpoint, id=None, **kwargs):
    username, password = _get_auth(kwargs.pop('username', None),
                                   kwargs.pop('password', None))
    kwargs = clean_kwargs(**kwargs)
    url = _build_url(endpoint, id=id)
    ret = {'comment': '', 'result': True, 'out': None}
    res = salt.utils.http.query(url,
                                method='GET',
                                decode=True,
                                username=username,
                                password=password,
                                params=kwargs)
    if 'error' in res:
        ret.update({'result': False, 'comment': res['error']})
        return ret
    ret['out'] = res['dict']['data']
    return ret
예제 #21
0
def hmset(key, **fieldsvals):
    '''
    Sets multiple hash fields to multiple values.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hmset foo_hash bar_field1=bar_value1 bar_field2=bar_value2
    '''
    host = fieldsvals.pop('host', None)
    port = fieldsvals.pop('port', None)
    database = fieldsvals.pop('db', None)
    password = fieldsvals.pop('password', None)
    server = _connect(host, port, database, password)
    return server.hmset(key, clean_kwargs(**fieldsvals))
예제 #22
0
def copy_image(source_region,
               image_id,
               name,
               profile,
               description=None,
               **libcloud_kwargs):
    '''
    Copies an image from a source region to the current region.

    :param source_region: Region to copy the node from.
    :type source_region: ``str``

    :param image_id: Image to copy.
    :type image_id: ``str``

    :param name: name for new image.
    :type name: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param description: description for new image.
    :type name: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's copy_image method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.copy_image us-east1 image1 'new image' profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    image = conn.get_image(image_id, **libcloud_kwargs)
    new_image = conn.copy_image(source_region,
                                image,
                                name,
                                description=description,
                                **libcloud_kwargs)
    return _simple_image(new_image)
예제 #23
0
def create_volume(size, name, profile, location_id=None, **libcloud_kwargs):
    '''
    Create a storage volume

    :param size: Size of volume in gigabytes (required)
    :type size: ``int``

    :param name: Name of the volume to be created
    :type name: ``str``

    :param location_id: Which data center to create a volume in. If
                            empty, undefined behavior will be selected.
                            (optional)
    :type location_id: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's list_volumes method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.create_volume 1000 vol1 profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    if location_id is not None:
        location = _get_by_id(conn.list_locations(), location_id)
    else:
        location = None
    # TODO : Support creating from volume snapshot

    volume = conn.create_volume(size,
                                name,
                                location,
                                snapshot=None,
                                **libcloud_kwargs)
    return _simple_volume(volume)
예제 #24
0
def list_supported_algorithms(profile, **libcloud_kwargs):
    '''
    Get the supported algorithms for a profile

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's list_supported_algorithms method
    :type  libcloud_kwargs: ``dict``

    :return: The supported algorithms

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_storage.list_supported_algorithms profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    return conn.list_supported_algorithms(**libcloud_kwargs)
예제 #25
0
def list_protocols(profile, **libcloud_kwargs):
    '''
    Return a list of supported protocols.

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's list_protocols method
    :type  libcloud_kwargs: ``dict``

    :return: a list of supported protocols
    :rtype: ``list`` of ``str``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_storage.list_protocols profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    return conn.list_protocols(**libcloud_kwargs)
예제 #26
0
def create_key_pair(name, profile, **libcloud_kwargs):
    '''
    Create a single key pair by name

    :param name: Name of the key pair to create.
    :type name: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's create_key_pair method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.create_key_pair pair1 profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    return _simple_key_pair(conn.create_key_pair(name, **libcloud_kwargs))
예제 #27
0
def get_image(image_id, profile, **libcloud_kwargs):
    '''
    Get an image of a node

    :param image_id: Image to fetch
    :type image_id: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's delete_image method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.get_image image1 profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    image = conn.get_image(image_id, **libcloud_kwargs)
    return _simple_image(image)
예제 #28
0
def delete_image(image_id, profile, **libcloud_kwargs):
    '''
    Delete an image of a node

    :param image_id: Image to delete
    :type image_id: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's delete_image method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.delete_image image1 profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    image = _get_by_id(conn.list_images(), image_id)
    return conn.delete_image(image, **libcloud_kwargs)
예제 #29
0
def list_nodes(profile, **libcloud_kwargs):
    '''
    Return a list of nodes

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's list_nodes method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.list_nodes profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    nodes = conn.list_nodes(**libcloud_kwargs)
    ret = []
    for node in nodes:
        ret.append(_simple_node(node))
    return ret
예제 #30
0
def extra(method, profile, **libcloud_kwargs):
    '''
    Call an extended method on the driver

    :param method: Driver's method name
    :type  method: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.extra ex_get_permissions google container_name=my_container object_name=me.jpg --out=yaml
    '''
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    conn = _get_driver(profile=profile)
    connection_method = getattr(conn, method)
    return connection_method(**libcloud_kwargs)
예제 #31
0
def delete_key_pair(name, profile, **libcloud_kwargs):
    '''
    Delete a key pair

    :param name: Key pair name.
    :type  name: ``str``

    :param profile: The profile key
    :type  profile: ``str``

    :param libcloud_kwargs: Extra arguments for the driver's import_key_pair_from_xxx method
    :type  libcloud_kwargs: ``dict``

    CLI Example:

    .. code-block:: bash

        salt myminion libcloud_compute.delete_key_pair pair1 profile1
    '''
    conn = _get_driver(profile=profile)
    libcloud_kwargs = clean_kwargs(**libcloud_kwargs)
    key = conn.get_key_pair(name)
    return conn.delete_key_pair(key, **libcloud_kwargs)
예제 #32
0
def run(*args, **kwargs):
    '''
    Execute a puppet run and return a dict with the stderr, stdout,
    return code, etc. The first positional argument given is checked as a
    subcommand. Following positional arguments should be ordered with arguments
    required by the subcommand first, followed by non-keyvalue pair options.
    Tags are specified by a tag keyword and comma separated list of values. --
    http://projects.puppetlabs.com/projects/1/wiki/Using_Tags

    CLI Examples::

        salt '*' puppet.run

        salt '*' puppet.run tags=basefiles::edit,apache::server

        salt '*' puppet.run debug

        salt '*' puppet.run apply /a/b/manifest.pp modulepath=/a/b/modules tags=basefiles::edit,apache::server
    '''
    _check_puppet()

    puppet = _Puppet()

    if args:
        # based on puppet documentation action must come first. making the same
        # assertion. need to ensure the list of supported cmds here matches those
        # defined in _Puppet.arguments()
        if args[0] in ['agent', 'apply']:
            puppet.subcmd = args[0]
            puppet.arguments(args[1:])
    else:
        # args will exist as an empty list even if none have been provided
        puppet.arguments(args)

    puppet.kwargs.update(utils.clean_kwargs(**kwargs))

    return __salt__['cmd.run_all'](repr(puppet))
예제 #33
0
def _get_endpoint(endpoint, id=None, **kwargs):
    username, password = _get_auth(kwargs.pop('username', None),
                                   kwargs.pop('password', None))
    kwargs = clean_kwargs(**kwargs)
    url = _build_url(endpoint, id=id)
    ret = {
        'comment': '',
        'result': True,
        'out': None
    }
    res = salt.utils.http.query(url,
                                method='GET',
                                decode=True,
                                username=username,
                                password=password,
                                params=kwargs)
    if 'error' in res:
        ret.update({
            'result': False,
            'comment': res['error']
        })
        return ret
    ret['out'] = res['dict']['data']
    return ret
예제 #34
0
파일: utils_test.py 프로젝트: bemehow/salt
 def test_clean_kwargs(self):
     self.assertDictEqual(utils.clean_kwargs(foo="bar"), {"foo": "bar"})
     self.assertDictEqual(utils.clean_kwargs(__pub_foo="bar"), {})
     self.assertDictEqual(utils.clean_kwargs(__foo_bar="gwar"), {"__foo_bar": "gwar"})
예제 #35
0
 def test_clean_kwargs(self):
     self.assertDictEqual(utils.clean_kwargs(foo='bar'), {'foo': 'bar'})
     self.assertDictEqual(utils.clean_kwargs(__pub_foo='bar'), {})
     self.assertDictEqual(utils.clean_kwargs(__foo_bar='gwar'), {'__foo_bar': 'gwar'})