Beispiel #1
0
def _unlink(name):
    """
    Unlink a DC/OS cluster.

    :param name: ID or name of the cluster
    :type name: str
    :returns: process status
    :rtype: int
    """

    c = cluster.get_cluster(name)
    if c:
        name = c.get_cluster_id()

    dcos_url = config.get_config_val('core.dcos_url')
    endpoint = urllib.parse.urljoin(dcos_url, '/cluster/v1/links/' + name)

    try:
        http.delete(endpoint)
    except DCOSHTTPException as e:
        if e.status() == 404:
            raise DCOSException('Unknown cluster link {}.'.format(name))
        raise

    return 0
Beispiel #2
0
def delete_zk_node(znode):
    """Delete Zookeeper node

    :param znode: znode to delete
    :type znode: str
    :rtype: None
    """

    dcos_url = config.get_config_val('core.dcos_url')
    znode_url = urllib.parse.urljoin(
        dcos_url, '/exhibitor/exhibitor/v1/explorer/znode/{}'.format(znode))
    http.delete(znode_url)
Beispiel #3
0
def delete_zk_node(znode):
    """Delete Zookeeper node

    :param znode: znode to delete
    :type znode: str
    :rtype: None
    """

    dcos_url = util.get_config_vals(['core.dcos_url'])[0]
    znode_url = urllib.parse.urljoin(
        dcos_url,
        '/exhibitor/exhibitor/v1/explorer/znode/{}'.format(znode))
    http.delete(znode_url)
Beispiel #4
0
    def _cancel_deployment(self, deployment_id, force):
        """Cancels an application deployment.

        :param deployment_id: the deployment id
        :type deployment_id: str
        :param force: if set to `False`, stop the deployment and
                      create a new rollback deployment to reinstate the
                      previous configuration. If set to `True`, simply stop the
                      deployment.
        :type force: bool
        :returns: cancelation deployment
        :rtype: dict
        """

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

        url = self._create_url('v2/deployments/{}'.format(deployment_id))

        response = http.delete(
            url,
            params=params,
            to_exception=_to_exception)

        if force:
            return None
        else:
            return response.json()
Beispiel #5
0
def abdicate_marathon_leader(params="", marathon_name='marathon'):
    """
    Abdicates current leader. Waits until the HTTP service is stopped.

    params arg should include a "?" prefix.
    """
    leader_endpoint = get_marathon_endpoint('/v2/leader', marathon_name)
    result = http.delete(leader_endpoint + params)
    wait_until_fail(leader_endpoint)
    return result
Beispiel #6
0
    def remove_app(self, app_id, force=None):
        """Completely removes the requested application.

        :param app_id: the ID of the application to remove
        :type app_id: str
        :param force: whether to override running deployments
        :type force: bool
        :rtype: None
        """

        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))

        http.delete(url, params=params, to_exception=_to_exception)
Beispiel #7
0
    def remove_group(self, group_id, force=None):
        """Completely removes the requested application.

        :param group_id: the ID of the application to remove
        :type group_id: str
        :param force: whether to override running deployments
        :type force: bool
        :rtype: None
        """

        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))

        http.delete(url, params=params, to_exception=_to_exception)
Beispiel #8
0
def _unlink(name):
    """
    Unlink a DC/OS cluster.

    :param name:  name of the cluster
    :type name: str
    :returns: process status
    :rtype: int
    """

    c = cluster.get_cluster(name)
    if not c:
        raise DCOSException('Unknown cluster {}.'.format(name))

    dcos_url = config.get_config_val('core.dcos_url')
    endpoint = urllib.parse.urljoin(
            dcos_url, '/cluster/v1/links/' + c.get_cluster_id())

    http.delete(endpoint)

    return 0
Beispiel #9
0
def remove_user(uid):
    """ Removes a user from the DCOS Enterprise.

        :param uid: user id
        :type uid: str
    """
    try:
        acl_url = urljoin(_acl_url(), 'users/{}'.format(uid))
        r = http.delete(acl_url)
        assert r.status_code == 204
    except DCOSHTTPException as e:
        # doesn't exist
        if e.response.status_code != 400:
            raise
Beispiel #10
0
def remove_group(id):
    """ Removes a group from the DCOS Enterprise.  The group is
        removed regardless of associated users.

        :param id: group id
        :type id: str
    """
    acl_url = urljoin(_acl_url(), 'groups/{}'.format(id))
    try:
        r = http.delete(acl_url)
        print(r.status_code)
    except DCOSHTTPException as e:
        if e.response.status_code != 400:
            raise
Beispiel #11
0
def remove_user(uid):
    """ Removes a user from the DCOS Enterprise.

        :param uid: user id
        :type uid: str
    """
    try:
        acl_url = urljoin(_acl_url(), 'users/{}'.format(uid))
        r = http.delete(acl_url)
        assert r.status_code == 204
    except DCOSHTTPException as e:
        # doesn't exist
        if e.response.status_code != 400:
            raise
Beispiel #12
0
def remove_group(id):
    """ Removes a group from the DCOS Enterprise.  The group is
        removed regardless of associated users.

        :param id: group id
        :type id: str
    """
    acl_url = urljoin(_acl_url(), 'groups/{}'.format(id))
    try:
        r = http.delete(acl_url)
        print(r.status_code)
    except DCOSHTTPException as e:
        if e.response.status_code != 400:
            raise
Beispiel #13
0
def remove_user_from_group(uid, gid):
    """ Removes a user from a group within DCOS Enterprise.

        :param uid: user id
        :type uid: str
        :param gid: group id
        :type gid: str
    """
    acl_url = urljoin(_acl_url(), 'groups/{}/users/{}'.format(gid, uid))
    try:
        r = http.delete(acl_url)
        assert r.status_code == 204
    except dcos.errors.DCOSBadRequest:
        pass
Beispiel #14
0
def remove_user_from_group(uid, gid):
    """ Removes a user from a group within DCOS Enterprise.

        :param uid: user id
        :type uid: str
        :param gid: group id
        :type gid: str
    """
    acl_url = urljoin(_acl_url(), 'groups/{}/users/{}'.format(gid, uid))
    try:
        r = http.delete(acl_url)
        assert r.status_code == 204
    except dcos.errors.DCOSBadRequest:
        pass
Beispiel #15
0
def _do_request(url, method, timeout=None, stream=False, **kwargs):
    """
    make HTTP request

    :param url: url
    :type url: string
    :param method: HTTP method, GET or POST
    :type  method: string
    :param timeout: HTTP request timeout, default 3 seconds
    :type  timeout: integer
    :param stream: stream parameter for requests lib
    :type  stream: bool
    :return: http response
    :rtype: requests.Response
    """
    def _is_success(status_code):
        # consider 400 and 503 to be successful status codes.
        # API will return the error message.
        if status_code in [200, 400, 503]:
            return True
        return False

    if timeout is None:
        timeout = _get_timeout()

    url = urllib.parse.urljoin(_get_metronome_url(), url)
    if method.lower() == 'get':
        http_response = http.get(url,
                                 is_success=_is_success,
                                 timeout=timeout,
                                 **kwargs)
    elif method.lower() == 'post':
        http_response = http.post(url,
                                  is_success=_is_success,
                                  timeout=timeout,
                                  stream=stream,
                                  **kwargs)
    elif method.lower() == 'delete':
        http_response = http.delete(url,
                                    is_success=_is_success,
                                    timeout=timeout,
                                    stream=stream,
                                    **kwargs)
    else:
        raise DCOSException('Unsupported HTTP method: ' + method)
    return http_response
Beispiel #16
0
def remove_user_permission(rid, uid, action='full'):
    """ Removes user permission on a given resource.

        :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')

    try:
        acl_url = urljoin(_acl_url(), 'acls/{}/users/{}/{}'.format(rid, uid, action))
        r = http.delete(acl_url)
        assert r.status_code == 204
    except DCOSHTTPException as e:
        if e.response.status_code != 400:
            raise
Beispiel #17
0
def remove_user_permission(rid, uid, action='full'):
    """ Removes user permission on a given resource.

        :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')

    try:
        acl_url = urljoin(_acl_url(),
                          'acls/{}/users/{}/{}'.format(rid, uid, action))
        r = http.delete(acl_url)
        assert r.status_code == 204
    except DCOSHTTPException as e:
        if e.response.status_code != 400:
            raise
Beispiel #18
0
def _do_request(url, method, timeout=None, stream=False, **kwargs):
    """
    make HTTP request

    :param url: url
    :type url: string
    :param method: HTTP method, GET or POST
    :type  method: string
    :param timeout: HTTP request timeout, default 3 seconds
    :type  timeout: integer
    :param stream: stream parameter for requests lib
    :type  stream: bool
    :return: http response
    :rtype: requests.Response
    """

    def _is_success(status_code):
        # consider 400 and 503 to be successful status codes.
        # API will return the error message.
        if status_code in [200, 400, 503]:
            return True
        return False

    if timeout is None:
        timeout = _get_timeout()

    url = urllib.parse.urljoin(_get_metronome_url(), url)
    if method.lower() == 'get':
        http_response = http.get(url, is_success=_is_success,
                                 timeout=timeout, **kwargs)
    elif method.lower() == 'post':
        http_response = http.post(url, is_success=_is_success,
                                  timeout=timeout, stream=stream, **kwargs)
    elif method.lower() == 'delete':
        http_response = http.delete(url, is_success=_is_success,
                                    timeout=timeout, stream=stream, **kwargs)
    else:
        raise DCOSException('Unsupported HTTP method: ' + method)
    return http_response
Beispiel #19
0
def delete_marathon_path(name, marathon_name='marathon'):
    """Invokes HTTP DELETE for marathon url with name.
       For example, name='v2/leader': http GET {dcos_url}/service/marathon/v2/leader
    """
    url = get_marathon_endpoint(name, marathon_name)
    return http.delete(url)
def delete(dcos_mode, host, url, **kwargs):
    kwargs = enrich_args(host, **kwargs)
    if dcos_mode:
        return http.delete(url, **kwargs)
    else:
        return requests.delete(url, **kwargs)
Beispiel #21
0
def delete_marathon_path(name, marathon_name='marathon'):
    """Invokes HTTP DELETE for marathon url with name.
       For example, name='v2/leader': http GET {dcos_url}/service/marathon/v2/leader
    """
    url = get_marathon_endpoint(name, marathon_name)
    return http.delete(url)