Beispiel #1
0
 def test_default_timeout_delete(self, resp_mock):
     """Tests that default timeout for delete request is set correctly."""
     resp_mock.return_value.status_code = http.client.OK
     resp_mock.return_value.text = 'foo'
     restclient.delete('http://foo.com', '/')
     resp_mock.assert_called_with(
         'http://foo.com/', stream=None, auth=mock.ANY,
         headers=None, json=None, timeout=(0.5, None), proxies=None
     )
Beispiel #2
0
    def assign(allocation, env, cell, pattern, priority, delete):
        """Assign application pattern:priority to the allocation.

        Application pattern must start with <PROID>. and is a glob expression.

        Environments of the proid and one specified in command line using
        --env option must match.

        Once scheduled, Treadmill scheduler will match application against all
        available patterns and assign application to a reserved capacity.

        All application assigned to a capacity are ordered by priority from
        high to low.
        """
        restapi = context.GLOBAL.admin_api(ctx.get('api'))

        _check_tenant_exists(restapi, allocation)
        _make_allocation(restapi, allocation, env)

        reservation_url = '/allocation/{}/{}/reservation/{}'.format(
            allocation, env, cell)

        try:
            restclient.get(restapi, reservation_url)
        except restclient.NotFoundError:
            # TODO: default partition should be resolved in API, not in CLI.
            restclient.post(restapi,
                            reservation_url,
                            payload={
                                'memory': '0M',
                                'disk': '0M',
                                'cpu': '0%',
                                'partition': admin.DEFAULT_PARTITION
                            })

        url = '/allocation/{}/{}/assignment/{}/{}'.format(
            allocation, env, cell, pattern)

        if delete:
            restclient.delete(restapi, url)
        else:
            default_prio = None
            existing = restclient.get(restapi, url).json()
            for assignment in existing:
                if assignment['pattern'] == pattern:
                    default_prio = assignment['priority']
            if default_prio is None:
                default_prio = _DEFAULT_PRIORITY

            data = {'priority': priority if priority else default_prio}
            restclient.put(restapi, url, payload=data)

        _display_tenant(restapi, allocation)
Beispiel #3
0
    def assign(allocation, cell, pattern, priority, delete):
        """Assign application pattern:priority to the allocation."""
        restapi = context.GLOBAL.admin_api(ctx.get('api'))
        url = '/allocation/%s/assignment/%s/%s' % (allocation, cell, pattern)
        if delete:
            restclient.delete(restapi, url)
        else:
            try:
                restclient.post(restapi, url, payload={'priority': priority})
            except restclient.AlreadyExistsError:
                restclient.put(restapi, url, payload={'priority': priority})

        _display_alloc(restapi, allocation)
 def test_verify_delete(self, resp_mock):
     """Tests that 'verify' for delete request is set correctly."""
     resp_mock.return_value.status_code = http_client.OK
     resp_mock.return_value.text = 'foo'
     restclient.delete('http://foo.com', '/', verify='/path/to/ca/certs')
     resp_mock.assert_called_with('http://foo.com/',
                                  stream=None,
                                  auth=mock.ANY,
                                  headers=None,
                                  json=None,
                                  timeout=(0.5, None),
                                  proxies=None,
                                  verify='/path/to/ca/certs')
Beispiel #5
0
    def assign(allocation, env, cell, pattern, priority, delete):
        """Assign application pattern:priority to the allocation.

        Application pattern must start with <PROID>. and is a glob expression.

        Environments of the proid and one specified in command line using
        --env option must match.

        Once scheduled, Treadmill scheduler will match application against all
        available patterns and assign application to a reserved capacity.

        All application assigned to a capacity are ordered by priority from
        high to low.
        """
        restapi = context.GLOBAL.admin_api()

        _check_tenant_exists(restapi, allocation)
        _make_allocation(restapi, allocation, env)

        reservation_url = '/allocation/{}/{}/reservation/{}'.format(
            allocation, env, cell)

        try:
            restclient.get(restapi, reservation_url)
        except restclient.NotFoundError:
            restclient.post(restapi,
                            reservation_url,
                            payload={
                                'memory': '0M',
                                'disk': '0M',
                                'cpu': '0%'
                            })

        url = '/allocation/{}/{}/assignment/{}/{}'.format(
            allocation, env, cell, pattern)

        if delete:
            restclient.delete(restapi, url)
        else:
            data = {}
            if priority:
                data['priority'] = priority
            existing = restclient.get(restapi, url).json()
            rest_func = restclient.post
            for assignment in existing:
                if assignment['pattern'] == pattern:
                    rest_func = restclient.put
                    break
            rest_func(restapi, url, payload=data)

            _display_tenant(restapi, allocation)
Beispiel #6
0
    def assign(allocation, cell, pattern, priority, delete):
        """Assign application pattern:priority to the allocation."""
        restapi = context.GLOBAL.admin_api(ctx.get('api'))
        url = '/allocation/%s/assignment/%s/%s' % (allocation, cell, pattern)

        if not delete and priority is None:
            raise click.UsageError(
                'Must specify priority when creating/modifying assignments.')

        if delete:
            restclient.delete(restapi, url)
        else:
            restclient.put(restapi, url, payload={'priority': priority})

        _display_alloc(restapi, allocation)
 def test_raw_payload_delete(self, resp_mock):
     """Tests that delete can handle not json serializable payload."""
     resp_mock.return_value.status_code = http_client.OK
     resp_mock.return_value.text = 'foo'
     restclient.delete('http://foo.com',
                       '/',
                       'payload',
                       payload_to_json=False)
     resp_mock.assert_called_with('http://foo.com/',
                                  stream=None,
                                  auth=mock.ANY,
                                  headers=None,
                                  timeout=(0.5, None),
                                  proxies=None,
                                  data='payload',
                                  verify=True)
Beispiel #8
0
 def delete_host(ctx, hostname):
     """Deletes an IPA Host"""
     cli.out(
         restclient.delete(
             api=ctx.obj.get('API'),
             url='/ipa/host/' + hostname,
             headers={'Content-Type': 'application/json'}
         ).content
     )
Beispiel #9
0
 def delete_user(ctx, username):
     """Deletes an IPA User"""
     response = restclient.delete(
         api=ctx.obj.get('API'),
         url='/ipa/user/' + username,
         headers={'Content-Type': 'application/json'}
     )
     cli.out(
         response.content
     )
Beispiel #10
0
    def delete(item):
        """Delete a tenant/allocation/reservation."""
        restapi = context.GLOBAL.admin_api(ctx.get('api'))

        path = item.split('/')
        if len(path) == 1:
            # delete a tenant
            url = '/tenant/%s' % item
            restclient.delete(restapi, url)
        elif len(path) == 2:
            # delete an allocation
            url = '/allocation/%s' % item
            restclient.delete(restapi, url)
        elif len(path) == 3:
            # delete a reservation
            url = '/allocation/%s/%s/reservation/%s' % (path[0], path[1],
                                                        path[2])
            restclient.delete(restapi, url)
        else:
            # error
            click.echo('Wrong format: %s' % item, err=True)
Beispiel #11
0
    def delete(item):
        """Delete a tenant/allocation/reservation."""
        restapi = context.GLOBAL.admin_api()

        path = item.split('/')
        if len(path) == 1:
            # delete a tenant
            if not _tenant_empty(restapi, item):
                url = '/tenant/{}'.format(item)
                restclient.delete(restapi, url)
        elif len(path) == 2:
            # delete all reservations and all patterns
            url = '/allocation/{}'.format(item)
            restclient.delete(restapi, url)
        elif len(path) == 3:
            # delete a reservation
            # API automatically clears the pattern under it
            url = '/allocation/{}/{}/reservation/{}'.format(
                path[0], path[1], path[2])
            restclient.delete(restapi, url)
        else:
            # error
            click.echo('Wrong format: {}'.format(item), err=True)
Beispiel #12
0
    def delete(path):
        """REST DELETE request."""
        response = restclient.delete(ctx['api'], path)

        formatter = cli.make_formatter(None)
        cli.out(formatter(response.json()))
Beispiel #13
0
 def delete(name):
     """Delete app monitor"""
     restapi = context.GLOBAL.cell_api()
     url = _REST_PATH + name
     restclient.delete(restapi, url)
Beispiel #14
0
    def reserve(allocation, env, cell, partition, rank, rank_adjustment,
                max_utilization, empty, memory, cpu, disk, traits, delete):
        """Reserve capacity on the cell for given environment."""
        _check_reserve_usage(empty, memory, cpu, disk)

        restapi = context.GLOBAL.admin_api()

        _check_tenant_exists(restapi, allocation)

        if delete:
            url = '/allocation/{}/{}/reservation/{}'.format(
                allocation, env, cell)
            restclient.delete(restapi, url)
            _display_tenant(restapi, allocation)
            return

        _make_allocation(restapi, allocation, env)

        data = {}
        if empty:
            data['memory'] = '0M'
            data['disk'] = '0M'
            data['cpu'] = '0%'

        if memory:
            data['memory'] = memory
        if cpu:
            data['cpu'] = cpu
        if disk:
            data['disk'] = disk
        if partition:
            data['partition'] = partition

        reservation_url = '/allocation/{}/{}/reservation/{}'.format(
            allocation, env, cell)

        try:
            existing = restclient.get(restapi, reservation_url).json()
            if data:
                # To meet the json schema required in create
                if 'memory' not in data:
                    data['memory'] = existing['memory']
                if 'cpu' not in data:
                    data['cpu'] = existing['cpu']
                if 'disk' not in data:
                    data['disk'] = existing['disk']
                if 'partition' not in data:
                    data['partition'] = existing['partition']
                restclient.put(restapi, reservation_url, payload=data)
        except restclient.NotFoundError:
            if rank is not None:
                data['rank'] = rank
            if rank_adjustment is not None:
                data['rank_adjustment'] = rank_adjustment
            if max_utilization is not None:
                data['max_utilization'] = max_utilization
            if traits:
                data['traits'] = cli.combine(traits)

            restclient.post(restapi, reservation_url, payload=data)

        _display_tenant(restapi, allocation)
Beispiel #15
0
def _delete(apis, appname):
    """Deletes the app by name."""
    restclient.delete(apis, _APP_REST_PATH + appname)
    return None
Beispiel #16
0
def _delete(apis, appname):
    """Deletes the app by name."""
    restclient.delete(apis, '/v3/app/' + appname)
    return None
Beispiel #17
0
 def delete(name):
     """Delete identity group"""
     restapi = context.GLOBAL.cell_api(ctx['api'])
     url = _REST_PATH + name
     restclient.delete(restapi, url)
Beispiel #18
0
 def delete(name):
     """Delete Treadmill App Group entry"""
     restapi = context.GLOBAL.admin_api()
     url = _REST_PATH + name
     restclient.delete(restapi, url)
Beispiel #19
0
 def delete(name):
     """Delete AWS image"""
     restapi = ctx['api']
     url = _REST_PATH + name
     restclient.delete(restapi, url)
Beispiel #20
0
 def delete(job_id):
     """Delete a cron events"""
     restapi = context.GLOBAL.cell_api(ctx['api'])
     url = _REST_PATH + job_id
     restclient.delete(restapi, url)
Beispiel #21
0
 def delete(name):
     """Delete AWS image"""
     restapi = context.GLOBAL.cell_api(ctx['api'])
     url = _REST_PATH + name
     restclient.delete(restapi, url)