예제 #1
0
    def scale_app(self, app_id, instances, force=None):
        """Scales an application to the requested number of instances.

        :param app_id: the ID of the application to scale
        :type app_id: str
        :param instances: the requested number of instances
        :type instances: int
        :param force: whether to override running deployments
        :type force: bool
        :returns: the resulting deployment ID
        :rtype: bool
        """

        app_id = self.normalize_app_id(app_id)

        if not force:
            params = None
        else:
            params = {'force': 'true'}

        url = self._create_url('v2/apps{}'.format(app_id))

        response = http.put(url,
                            params=params,
                            json={'instances': int(instances)},
                            to_exception=_to_exception)

        deployment = response.json()['deploymentId']
        return (deployment, None)
예제 #2
0
    def _update(self, resource_id, payload, force=None, url_endpoint="apps"):
        """Update an application or group.

        :param resource_id: the app or group id
        :type resource_id: str
        :param payload: the json payload
        :type payload: dict
        :param force: whether to override running deployments
        :type force: bool
        :param url_endpoint: resource type to update ("apps" or "groups")
        :type url_endpoint: str
        :returns: the resulting deployment ID
        :rtype: str
        """

        resource_id = self.normalize_app_id(resource_id)

        if not force:
            params = None
        else:
            params = {'force': 'true'}

        url = self._create_url('v2/{}{}'.format(url_endpoint, resource_id))

        response = http.put(url,
                            params=params,
                            json=payload,
                            to_exception=_to_exception)

        return response.json().get('deploymentId')
예제 #3
0
def set_service_account_permissions(service_account,
                                    resource='dcos:superuser',
                                    action='full'):
    """Set permissions for given `{service_account}` for passed `{resource}` with
       `{action}`. For more information consult the DC/OS documentation:
       https://docs.mesosphere.com/1.9/administration/id-and-access-mgt/permissions/user-service-perms/
    """
    try:
        print('Granting {} permissions to {}/users/{}'.format(
            action, resource, service_account))
        url = urljoin(
            shakedown.dcos_url(),
            'acs/api/v1/acls/{}/users/{}/{}'.format(resource, service_account,
                                                    action))
        req = http.put(url)
        msg = 'Failed to grant permissions to the service account: {}, {}'.format(
            req, req.text)
        assert req.status_code == 204, msg
    except DCOSHTTPException as e:
        if (e.response.status_code == 409):
            print('Service account {} already has {} permissions set'.format(
                service_account, resource))
        else:
            print("Unexpected HTTP error: {}".format(e.response))
            raise
    except:
        print("Unexpected error:", sys.exc_info()[0])
        raise
예제 #4
0
def add_acs_resource(resource):
    """Create given ACS `{resource}`. For more information consult the DC/OS documentation:
       https://docs.mesosphere.com/1.9/administration/id-and-access-mgt/permissions/user-service-perms/
    """
    import json
    try:
        print('Adding ACS resource: {}'.format(resource))
        url = urljoin(shakedown.dcos_url(),
                      'acs/api/v1/acls/{}'.format(resource))
        extra_args = {'headers': {'Content-Type': 'application/json'}}
        req = http.put(url,
                       data=json.dumps({'description': resource}),
                       **extra_args)
        assert req.status_code == 201, 'Failed create ACS resource: {}, {}'.format(
            req, req.text)
    except DCOSHTTPException as e:
        if (e.response.status_code == 409):
            print('ACS resource {} already exists'.format(resource))
        else:
            print("Unexpected HTTP error: {}, {}".format(
                e.response, e.response.text))
            raise
    except:
        print("Unexpected error:", sys.exc_info()[0])
        raise
예제 #5
0
    def scale_group(self, group_id, scale_factor, force=None):
        """Scales a group with the requested scale-factor.
        :param group_id: the ID of the group to scale
        :type group_id: str
        :param scale_factor: the requested value of scale-factor
        :type scale_factor: float
        :param force: whether to override running deployments
        :type force: bool
        :returns: the resulting deployment ID
        :rtype: bool
        """

        group_id = self.normalize_app_id(group_id)

        if not force:
            params = None
        else:
            params = {'force': 'true'}

        url = self._create_url('v2/groups{}'.format(group_id))

        response = http.put(url,
                            params=params,
                            json={'scaleBy': scale_factor},
                            timeout=self._timeout)

        deployment = response.json()['deploymentId']
        return deployment
예제 #6
0
    def scale_group(self, group_id, scale_factor, force=None):
        """Scales a group with the requested scale-factor.
        :param group_id: the ID of the group to scale
        :type group_id: str
        :param scale_factor: the requested value of scale-factor
        :type scale_factor: float
        :param force: whether to override running deployments
        :type force: bool
        :returns: the resulting deployment ID
        :rtype: bool
        """

        group_id = self.normalize_app_id(group_id)

        if not force:
            params = None
        else:
            params = {'force': 'true'}

        url = self._create_url('v2/groups{}'.format(group_id))

        response = http.put(url,
                            params=params,
                            json={'scaleBy': scale_factor},
                            timeout=self._timeout)

        deployment = response.json()['deploymentId']
        return deployment
예제 #7
0
def set_service_account_permissions(service_account, ressource='dcos:superuser', action='full'):
    """Set permissions for given `{service_account}` for passed `{ressource}` with
       `{action}`. For more information consult the DC/OS documentation:
       https://docs.mesosphere.com/1.9/administration/id-and-access-mgt/permissions/user-service-perms/
    """
    print('Granting {} permissions to {}/users/{}'.format(action, ressource, service_account))
    url = urljoin(shakedown.dcos_url(), 'acs/api/v1/acls/{}/users/{}/{}'.format(ressource, service_account, action))
    req = http.put(url)
    assert req.status_code == 204, 'Failed to grant permissions to the service account: {}, {}'.format(req, req.text)
def start_cleanup(nodes, keyspaces=None, column_families=None):
    req = {'nodes': nodes}
    if keyspaces is not None:
        req['key_spaces'] = keyspaces
    if column_families is not None:
        req['column_families'] = column_families
    return http.put(cu.api_url("/cleanup/start"),
                    json=req,
                    headers={'Content-Type': 'application/json'})
def start_restore(name, external_location, s3_access_key, s3_secret_key):
    req = {
        'backup_name': name,
        'external_location': external_location,
        's3_access_key': s3_access_key,
        's3_secret_key': s3_secret_key
    }
    return http.put(cu.api_url("/restore/start"),
                    json=req,
                    headers={'Content-Type': 'application/json'})
예제 #10
0
def start_backup(name, external_location,
                 s3_access_key, s3_secret_key, azure_account, azure_key):
    req = {
        'backup_name': name,
        'external_location': external_location,
        's3_access_key': s3_access_key,
        's3_secret_key': s3_secret_key,
        'azure_account': azure_account,
        'azure_key': azure_key
    }
    return http.put(cu.api_url("/backup/start"),
                    json=req,
                    headers={'Content-Type': 'application/json'})
예제 #11
0
파일: security.py 프로젝트: dcos/shakedown
def ensure_resource(rid):
    """ Creates or confirms that a resource is added into the DCOS Enterprise System.
        Example:  dcos:service:marathon:marathon:services:/example-secure

        :param rid: resource ID
        :type rid: str
    """
    try:
        acl_url = urljoin(_acl_url(), 'acls/{}'.format(rid))
        r = http.put(acl_url, json={'description': 'jope'})
        assert r.status_code == 201
    except DCOSHTTPException as e:
        if e.response.status_code != 409:
            raise
예제 #12
0
def ensure_resource(rid):
    """ Creates or confirms that a resource is added into the DCOS Enterprise System.
        Example:  dcos:service:marathon:marathon:services:/example-secure

        :param rid: resource ID
        :type rid: str
    """
    try:
        acl_url = urljoin(_acl_url(), 'acls/{}'.format(rid))
        r = http.put(acl_url, json={'description': 'jope'})
        assert r.status_code == 201
    except DCOSHTTPException as e:
        if e.response.status_code != 409:
            raise
예제 #13
0
파일: main.py 프로젝트: sis-tools/dcos-cli
def _put_job(job_id, job_json):
    """
    :param job_id: Id of the job
    :type job_id: str
    :param job_json: json object representing a job
    :type job_file: json
    :returns: response json
    :rtype: json
    """

    timeout = _get_timeout()
    url = "{}/{}".format(_get_api_url('v1/jobs'), job_id)

    response = http.put(url, json=job_json, timeout=timeout)

    return response.json()
예제 #14
0
파일: main.py 프로젝트: unterstein/dcos-cli
def _put_job(job_id, job_json):
    """
    :param job_id: Id of the job
    :type job_id: str
    :param job_json: json object representing a job
    :type job_file: json
    :returns: response json
    :rtype: json
    """

    timeout = _get_timeout()
    url = "{}/{}".format(_get_api_url('v1/jobs'), job_id)

    response = http.put(url, json=job_json, timeout=timeout)

    return response.json()
예제 #15
0
파일: security.py 프로젝트: dcos/shakedown
def add_user_to_group(uid, gid, exist_ok=True):
    """ Adds a user to a group within DCOS Enterprise.  The group and
        user must exist.

        :param uid: user id
        :type uid: str
        :param gid: group id
        :type gid: str
        :param exist_ok: True if it is ok for the relationship to pre-exist.
        :type exist_ok: bool
    """
    acl_url = urljoin(_acl_url(), 'groups/{}/users/{}'.format(gid, uid))
    try:
        r = http.put(acl_url)
        assert r.status_code == 204
    except DCOSHTTPException as e:
        if e.response.status_code == 409 and exist_ok:
            pass
        else:
            raise
예제 #16
0
def add_user_to_group(uid, gid, exist_ok=True):
    """ Adds a user to a group within DCOS Enterprise.  The group and
        user must exist.

        :param uid: user id
        :type uid: str
        :param gid: group id
        :type gid: str
        :param exist_ok: True if it is ok for the relationship to pre-exist.
        :type exist_ok: bool
    """
    acl_url = urljoin(_acl_url(), 'groups/{}/users/{}'.format(gid, uid))
    try:
        r = http.put(acl_url)
        assert r.status_code == 204
    except DCOSHTTPException as e:
        if e.response.status_code == 409 and exist_ok:
            pass
        else:
            raise
예제 #17
0
파일: common.py 프로젝트: guenter/marathon
def set_service_account_permissions(service_account, resource='dcos:superuser', action='full'):
    """Set permissions for given `{service_account}` for passed `{resource}` with
       `{action}`. For more information consult the DC/OS documentation:
       https://docs.mesosphere.com/1.9/administration/id-and-access-mgt/permissions/user-service-perms/
    """
    try:
        print('Granting {} permissions to {}/users/{}'.format(action, resource, service_account))
        url = urljoin(shakedown.dcos_url(), 'acs/api/v1/acls/{}/users/{}/{}'.format(resource, service_account, action))
        req = http.put(url)
        msg = 'Failed to grant permissions to the service account: {}, {}'.format(req, req.text)
        assert req.status_code == 204, msg
    except DCOSHTTPException as e:
        if (e.response.status_code == 409):
            print('Service account {} already has {} permissions set'.format(service_account, resource))
        else:
            print("Unexpected HTTP error: {}".format(e.response))
            raise
    except Exception:
        print("Unexpected error:", sys.exc_info()[0])
        raise
예제 #18
0
def add_group(id, description=None):
    """ Adds group to the DCOS Enterprise.  If not description
        is provided the id will be used for the description.

        :param id: group id
        :type id: str
        :param desc: description of user
        :type desc: str
    """

    if not description:
        description = id
    data = {'description': description}
    acl_url = urljoin(_acl_url(), 'groups/{}'.format(id))
    try:
        r = http.put(acl_url, json=data)
        assert r.status_code == 201
    except DCOSHTTPException as e:
        if e.response.status_code != 409:
            raise
예제 #19
0
파일: common.py 프로젝트: guenter/marathon
def add_acs_resource(resource):
    """Create given ACS `{resource}`. For more information consult the DC/OS documentation:
       https://docs.mesosphere.com/1.9/administration/id-and-access-mgt/permissions/user-service-perms/
    """
    import json
    try:
        print('Adding ACS resource: {}'.format(resource))
        url = urljoin(shakedown.dcos_url(), 'acs/api/v1/acls/{}'.format(resource))
        extra_args = {'headers': {'Content-Type': 'application/json'}}
        req = http.put(url, data=json.dumps({'description': resource}), **extra_args)
        assert req.status_code == 201, 'Failed create ACS resource: {}, {}'.format(req, req.text)
    except DCOSHTTPException as e:
        if (e.response.status_code == 409):
            print('ACS resource {} already exists'.format(resource))
        else:
            print("Unexpected HTTP error: {}, {}".format(e.response, e.response.text))
            raise
    except Exception:
        print("Unexpected error:", sys.exc_info()[0])
        raise
예제 #20
0
파일: security.py 프로젝트: dcos/shakedown
def add_user(uid, password, desc=None):
    """ Adds user to the DCOS Enterprise.  If not description
        is provided the uid will be used for the description.

        :param uid: user id
        :type uid: str
        :param password: password
        :type password: str
        :param desc: description of user
        :type desc: str
    """
    try:
        desc = uid if desc is None else desc
        user_object = {"description": desc, "password": password}
        acl_url = urljoin(_acl_url(), 'users/{}'.format(uid))
        r = http.put(acl_url, json=user_object)
        assert r.status_code == 201
    except DCOSHTTPException as e:
        # already exists
        if e.response.status_code != 409:
            raise
예제 #21
0
def add_user(uid, password, desc=None):
    """ Adds user to the DCOS Enterprise.  If not description
        is provided the uid will be used for the description.

        :param uid: user id
        :type uid: str
        :param password: password
        :type password: str
        :param desc: description of user
        :type desc: str
    """
    try:
        desc = uid if desc is None else desc
        user_object = {"description": desc, "password": password}
        acl_url = urljoin(_acl_url(), 'users/{}'.format(uid))
        r = http.put(acl_url, json=user_object)
        assert r.status_code == 201
    except DCOSHTTPException as e:
        # already exists
        if e.response.status_code != 409:
            raise
예제 #22
0
파일: security.py 프로젝트: dcos/shakedown
def add_group(id, description=None):
    """ Adds group to the DCOS Enterprise.  If not description
        is provided the id will be used for the description.

        :param id: group id
        :type id: str
        :param desc: description of user
        :type desc: str
    """

    if not description:
        description = id
    data = {
        'description': description
    }
    acl_url = urljoin(_acl_url(), 'groups/{}'.format(id))
    try:
        r = http.put(acl_url, json=data)
        assert r.status_code == 201
    except DCOSHTTPException as e:
        if e.response.status_code != 409:
            raise
예제 #23
0
파일: security.py 프로젝트: dcos/shakedown
def set_user_permission(rid, uid, action='full'):
    """ Sets users permission on a given resource.  The resource will be created
        if it doesn't exist.  Actions are: read, write, update, delete, full.

        :param uid: user id
        :type uid: str
        :param rid: resource ID
        :type rid: str
        :param action: read, write, update, delete or full
        :type action: str
    """
    rid = rid.replace('/', '%252F')
    # Create ACL if it does not yet exist.
    ensure_resource(rid)

    # Set the permission triplet.
    try:
        acl_url = urljoin(_acl_url(), 'acls/{}/users/{}/{}'.format(rid, uid, action))
        r = http.put(acl_url)
        assert r.status_code == 204
    except DCOSHTTPException as e:
        if e.response.status_code != 409:
            raise
예제 #24
0
def set_user_permission(rid, uid, action='full'):
    """ Sets users permission on a given resource.  The resource will be created
        if it doesn't exist.  Actions are: read, write, update, delete, full.

        :param uid: user id
        :type uid: str
        :param rid: resource ID
        :type rid: str
        :param action: read, write, update, delete or full
        :type action: str
    """
    rid = rid.replace('/', '%252F')
    # Create ACL if it does not yet exist.
    ensure_resource(rid)

    # Set the permission triplet.
    try:
        acl_url = urljoin(_acl_url(),
                          'acls/{}/users/{}/{}'.format(rid, uid, action))
        r = http.put(acl_url)
        assert r.status_code == 204
    except DCOSHTTPException as e:
        if e.response.status_code != 409:
            raise
예제 #25
0
def put(dcos_mode, host, url, **kwargs):
    kwargs = enrich_args(host, **kwargs)
    if dcos_mode:
        return http.put(url, **kwargs)
    else:
        return requests.put(url, **kwargs)
예제 #26
0
def replace(id):
    url = "/nodes/replace?node=node-{}".format(str(id))
    response = http.put(cu.api_url(url), headers={})
    return response.status_code % 200 < 100
예제 #27
0
def replace(id):
    url = "/nodes/replace?node=node-{}".format(str(id))
    response = http.put(cu.api_url(url), headers={})
    return response.status_code % 200 < 100