コード例 #1
0
    def take_action(self, parsed_args):
        column_headers = ('id', 'uuid', 'name', 'renewal_strategy',
                          'compute_allowed', 'compute_used',
                          'global_burn_rate', 'user_compute_used',
                          'user_burn_rate', 'start_date', 'end_date')
        api = AtmosphereAPI(self.app_args.auth_token,
                            base_url=self.app_args.base_url,
                            timeout=self.app_args.api_server_timeout,
                            verify=self.app_args.verify_cert)
        data = api.get_allocation_source(parsed_args.id)
        allocation_source = ()
        if data.ok:
            message = data.message
            start_date = ts_to_isodate(message['start_date'])
            end_date = ''
            if message['end_date']:
                end_date = ts_to_isodate(message['end_date'])
            allocation_source = (message['id'], message['uuid'],
                                 message['name'], message['renewal_strategy'],
                                 message['compute_allowed'],
                                 message['compute_used'],
                                 message['global_burn_rate'],
                                 message['user_compute_used'],
                                 message['user_burn_rate'], start_date,
                                 end_date)

        return (column_headers, allocation_source)
コード例 #2
0
 def test_getting_identities_when_response_is_ok(self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     response = api.get_identities()
     assert response.ok
     assert response.message['results'][0]['user'][
         'id'] == 1010 and response.message['results'][0]['quota'][
             'cpu'] == 132
コード例 #3
0
 def test_getting_volume_status_when_response_is_ok(self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     response = api.get_volume_status(
         "210bdc21-ca09-4765-ab21-c9cd86826dc8")
     if response.ok:
         data = response.message
         assert data['id'] == 2953 and data['status'] == 'in-use'
コード例 #4
0
 def test_getting_volumes_when_response_is_ok(self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     response = api.get_volumes()
     if response.ok:
         data = response.message
         assert data['count'] == 1 and data['results'][0][
             'name'] == 'myfirstvolume'
コード例 #5
0
ファイル: provider.py プロジェクト: eriksf/atmosphere-cli
    def take_action(self, parsed_args):
        column_headers = ('id', 'uuid', 'name', 'description', 'type',
                          'virtualization', 'sizes', 'auto_imaging', 'public',
                          'is_admin', 'active', 'start_date', 'end_date')
        api = AtmosphereAPI(self.app_args.auth_token,
                            base_url=self.app_args.base_url,
                            timeout=self.app_args.api_server_timeout,
                            verify=self.app_args.verify_cert)
        data = api.get_provider(parsed_args.id)
        provider = ()
        if data.ok:
            message = data.message
            start_date = ts_to_isodate(message['start_date'])
            end_date = ''
            if message['end_date']:
                end_date = ts_to_isodate(message['end_date'])
            provider = (message['id'], message['uuid'], message['name'],
                        message['description'], message['type']['name'],
                        message['virtualization']['name'], ', '.join([
                            value['name'] for value in message['sizes']
                        ]), message['auto_imaging'], message['public'],
                        message['is_admin'], message['active'], start_date,
                        end_date)

        return (column_headers, provider)
コード例 #6
0
    def take_action(self, parsed_args):
        column_headers = ('uuid', 'name', 'size', 'provider', 'status',
                          'start_date', 'end_date')
        api = AtmosphereAPI(self.app_args.auth_token,
                            base_url=self.app_args.base_url,
                            timeout=self.app_args.api_server_timeout,
                            verify=self.app_args.verify_cert)
        data = api.get_instance_history(parsed_args.id)
        history = []
        if data.ok:
            for status in data.message['results']:
                start_date = ts_to_date(status['start_date'])
                end_date = ''
                if status['end_date']:
                    end_date = ts_to_date(status['end_date'])
                history.append((
                    status['instance']['uuid'],
                    status['instance']['name'],
                    status['size']['name'],
                    status['provider']['name'],
                    status['status'],
                    start_date,
                    end_date,
                ))

        return (column_headers, tuple(history))
コード例 #7
0
ファイル: project.py プロジェクト: eriksf/atmosphere-cli
    def take_action(self, parsed_args):
        api = AtmosphereAPI(self.app_args.auth_token,
                            base_url=self.app_args.base_url,
                            timeout=self.app_args.api_server_timeout,
                            verify=self.app_args.verify_cert)
        payload = {
            "name": parsed_args.name,
            "description": parsed_args.description,
            "owner": parsed_args.owner
        }
        self.log.debug('INPUT: {}'.format(json.dumps(payload)))
        data = api.create_project(json.dumps(payload))
        project = ()
        column_headers = ('id', 'uuid', 'name', 'description', 'owner',
                          'start_date')
        if data.ok:
            message = data.message
            project = (message['id'], message['uuid'], message['name'],
                       message['description'], message['owner']['name'],
                       message['start_date'])
        else:
            self.app.stdout.write(
                'Error, project not created! Make sure to supply a name, description, and owner (group name).'
            )

        return (column_headers, project)
コード例 #8
0
ファイル: project.py プロジェクト: eriksf/atmosphere-cli
    def take_action(self, parsed_args):
        column_headers = ('id', 'uuid', 'name', 'description', 'owner',
                          'created_by', 'start_date', 'end_date', 'leaders',
                          'users', 'images', 'instances', 'volumes', 'links')
        api = AtmosphereAPI(self.app_args.auth_token,
                            base_url=self.app_args.base_url,
                            timeout=self.app_args.api_server_timeout,
                            verify=self.app_args.verify_cert)
        data = api.get_project(parsed_args.id)
        project = ()
        if data.ok:
            message = data.message
            start_date = ts_to_isodate(message['start_date'])
            end_date = ''
            if message['end_date']:
                end_date = ts_to_isodate(message['end_date'])
            project = (message['id'], message['uuid'], message['name'],
                       message['description'], message['owner']['name'],
                       message['created_by']['username'], start_date, end_date,
                       ', '.join([
                           value['username'] for value in message['leaders']
                       ]), ', '.join([
                           value['username'] for value in message['users']
                       ]), len(message['images']), len(message['instances']),
                       len(message['volumes']), len(message['links']))

        return (column_headers, project)
コード例 #9
0
ファイル: test_images.py プロジェクト: eriksf/atmosphere-cli
 def test_getting_image_version_when_response_is_ok(self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     response = api.get_image_version('40440e67-8644-4949-ba2f-b36c66f9d40b')
     assert response.ok
     assert response.message['id'] == '40440e67-8644-4949-ba2f-b36c66f9d40b' and \
         response.message['change_log'] == 'v1.7 - patched up to 9-14-17' and \
         len(response.message['machines']) == 2
コード例 #10
0
 def test_getting_maintenance_records_when_response_is_ok_and_showing_all_records(
         self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     response = api.get_maintenance_records(show_all=True)
     assert response.ok
     assert response.message['count'] == 18 and response.message['results'][
         0]['title'] == '8/14/18 - v33 deployment'
コード例 #11
0
ファイル: volume.py プロジェクト: eriksf/atmosphere-cli
    def take_action(self, parsed_args):
        api = AtmosphereAPI(self.app_args.auth_token,
                            base_url=self.app_args.base_url,
                            timeout=self.app_args.api_server_timeout,
                            verify=self.app_args.verify_cert)
        payload = {
            "name": parsed_args.name,
            "identity": parsed_args.identity,
            "size": parsed_args.size,
            "project": parsed_args.project,
            "description": parsed_args.description
        }
        if parsed_args.snapshot_id:
            payload['snapshot_id'] = parsed_args.snapshot_id
        if parsed_args.image_id:
            payload['image_id'] = parsed_args.image_id
        self.log.debug('INPUT: {}'.format(json.dumps(payload)))
        data = api.create_volume(json.dumps(payload))
        volume = ()
        column_headers = ('id', 'uuid', 'name', 'description', 'size',
                          'project', 'provider', 'user', 'start_date')
        if data.ok:
            message = data.message
            volume = (message['id'], message['uuid'], message['name'],
                      message['description'], message['size'],
                      message['project']['name'], message['provider']['name'],
                      message['user']['username'], message['start_date'])
        else:
            self.app.stdout.write(
                'Error, volume not created! Make sure to supply a name, identity, size, project, and description.'
            )

        return (column_headers, volume)
コード例 #12
0
 def test_creating_project_when_response_is_not_ok(self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     payload = {
         'name': '',
         'description': 'my first project',
         'owner': 'eriksf'
     }
     response = api.create_project(json.dumps(payload))
     assert not response.ok
     assert response.message['name'][0] == 'This field may not be blank.'
コード例 #13
0
 def test_detaching_volume_to_instance_when_response_is_not_ok(self):
     responses.add(responses.POST,
                   'https://local.atmo.cloud/api/v2/instances/ecdcdd9e-cf0e-42c4-9a7c-a950c6d8b822/actions',
                   status=403,
                   json={"errors": [{"code": 403, "message": "Instance ecdcdd9e-cf0e-42c4-9a7c-a950c6d8b822 must be active, suspended, or stopped before detaching a volume. (Current: shelved_offloaded) Retry request when instance is active."}]})
     api = AtmosphereAPI('token')
     options = {'volume_id': 'b94a0146-10d3-4c91-8482-3c9758c81ddf'}
     response = api.do_instance_volume_action('detach_volume', 'ecdcdd9e-cf0e-42c4-9a7c-a950c6d8b822', options=options)
     assert not response.ok
     assert response.message['errors'][0]['message'] == "Instance ecdcdd9e-cf0e-42c4-9a7c-a950c6d8b822 must be active, suspended, or stopped before detaching a volume. (Current: shelved_offloaded) Retry request when instance is active."
コード例 #14
0
ファイル: test_images.py プロジェクト: eriksf/atmosphere-cli
 def test_searching_images_when_response_is_ok(self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     response = api.search_images('galaxy')
     assert response.ok
     results = response.message['results']
     fcount = 0
     for r in results:
         if is_term_in_image_result(r, 'galaxy'):
             fcount += 1
     assert response.message['count'] == 3 and fcount == 3
コード例 #15
0
ファイル: test_images.py プロジェクト: eriksf/atmosphere-cli
 def test_getting_images_when_response_is_ok_and_filtering_on_creator(self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     response = api.get_images(created_by='jfischer')
     assert response.ok
     results = response.message['results']
     fcount = 0
     for r in results:
         if is_term_in_image_result(r, 'jfischer'):
             fcount += 1
     assert response.message['count'] == 9 and fcount == 9
コード例 #16
0
ファイル: test_images.py プロジェクト: eriksf/atmosphere-cli
 def test_getting_images_when_response_is_ok_and_filtering_on_tag(self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     response = api.get_images(tag_name='docker')
     assert response.ok
     results = response.message['results']
     fcount = 0
     for r in results:
         if is_term_in_image_result(r, 'docker'):
             fcount += 1
     assert response.message['count'] == 11 and fcount == 11
コード例 #17
0
 def take_action(self, parsed_args):
     api = AtmosphereAPI(self.app_args.auth_token,
                         base_url=self.app_args.base_url,
                         timeout=self.app_args.api_server_timeout,
                         verify=self.app_args.verify_cert)
     data = api.do_instance_action('unshelve', parsed_args.id)
     if data.ok and data.message['result'] == 'success':
         self.app.stdout.write('{}\n'.format(data.message['message']))
     else:
         self.app.stdout.write('Error: {}\n'.format(data.message))
コード例 #18
0
 def test_creating_project_when_owner_is_invalid(self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     payload = {
         'name': 'myfirstproject',
         'description': 'my first project',
         'owner': 'xxxxx'
     }
     response = api.create_project(json.dumps(payload))
     assert not response.ok
     assert response.message['owner'][
         0] == "Group with Field: name 'xxxxx' does not exist."
コード例 #19
0
ファイル: version.py プロジェクト: eriksf/atmosphere-cli
 def take_action(self, parsed_args):
     api = AtmosphereAPI(self.app_args.auth_token,
                         base_url=self.app_args.base_url,
                         timeout=self.app_args.api_server_timeout,
                         verify=self.app_args.verify_cert)
     data = api.get_version()
     if data.ok:
         message = data.message
         self.app.stdout.write('Atmosphere {} {} [Built: {}]\n'.format(
             message['git_branch'], message['git_sha_abbrev'],
             ts_to_isodate(message['commit_date'], include_time=True)))
コード例 #20
0
 def take_action(self, parsed_args):
     api = AtmosphereAPI(self.app_args.auth_token,
                         base_url=self.app_args.base_url,
                         timeout=self.app_args.api_server_timeout,
                         verify=self.app_args.verify_cert)
     if parsed_args.delete:
         data = api.delete_instance(parsed_args.id)
         if data.ok and data.message and data.message != '':
             self.app.stdout.write('Instance deleted: {}\n'.format(
                 data.message))
         else:
             self.app.stdout.write('Instance deleted\n')
コード例 #21
0
 def test_shelving_instance_when_response_is_not_ok(self):
     responses.add(responses.GET,
                   'https://local.atmo.cloud/api/v2/instances/ecdcdd9e-cf0e-42c4-9a7c-a950c6d8b822/actions',
                   status=200,
                   json=[{"description": "Shelves an instance when it is in the 'active' State", "key": "Shelve"}])
     responses.add(responses.POST,
                   'https://local.atmo.cloud/api/v2/instances/ecdcdd9e-cf0e-42c4-9a7c-a950c6d8b822/actions',
                   status=403,
                   json={"errors": [{"code": 403, "message": "The requested action reboot encountered an irrecoverable exception: message"}]})
     api = AtmosphereAPI('token')
     response = api.do_instance_action('shelve', 'ecdcdd9e-cf0e-42c4-9a7c-a950c6d8b822')
     assert not response.ok
     assert response.message['errors'][0]['message'] == "The requested action reboot encountered an irrecoverable exception: message"
コード例 #22
0
 def test_unshelving_instance_when_response_is_not_ok(self):
     responses.add(responses.GET,
                   'https://local.atmo.cloud/api/v2/instances/ecdcdd9e-cf0e-42c4-9a7c-a950c6d8b822/actions',
                   status=200,
                   json=[{"description": "Unshelves an instance when it is in the 'shelved' State", "key": "Unshelve"}])
     responses.add(responses.POST,
                   'https://local.atmo.cloud/api/v2/instances/ecdcdd9e-cf0e-42c4-9a7c-a950c6d8b822/actions',
                   status=409,
                   json={"errors": [{"code": 409, "message": "409 Conflict Cannot 'unshelve' instance ecdcdd9e-cf0e-42c4-9a7c-a950c6d8b822 while it is in vm_state stopped"}]})
     api = AtmosphereAPI('token')
     response = api.do_instance_action('unshelve', 'ecdcdd9e-cf0e-42c4-9a7c-a950c6d8b822')
     assert not response.ok
     assert response.message['errors'][0]['message'] == "409 Conflict Cannot 'unshelve' instance ecdcdd9e-cf0e-42c4-9a7c-a950c6d8b822 while it is in vm_state stopped"
コード例 #23
0
ファイル: group.py プロジェクト: eriksf/atmosphere-cli
    def take_action(self, parsed_args):
        column_headers = ('uuid', 'name')
        api = AtmosphereAPI(self.app_args.auth_token,
                            base_url=self.app_args.base_url,
                            timeout=self.app_args.api_server_timeout,
                            verify=self.app_args.verify_cert)
        data = api.get_groups()
        groups = []
        if data.ok:
            for group in data.message['results']:
                groups.append((group['uuid'], group['name']))

        return (column_headers, tuple(groups))
コード例 #24
0
ファイル: group.py プロジェクト: eriksf/atmosphere-cli
    def take_action(self, parsed_args):
        column_headers = ('uuid', 'name', 'users', 'leaders')
        api = AtmosphereAPI(self.app_args.auth_token,
                            base_url=self.app_args.base_url,
                            timeout=self.app_args.api_server_timeout,
                            verify=self.app_args.verify_cert)
        data = api.get_group(parsed_args.id)
        group = ()
        if data.ok:
            message = data.message
            group = (message['uuid'], message['name'], '\n'.join([
                value['username'] for value in message['users']
            ]), '\n'.join([value['username'] for value in message['leaders']]))

        return (column_headers, group)
コード例 #25
0
 def test_creating_volume_when_response_is_ok(self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     payload = {
         "name": "mydata",
         "identity": "8e735cfe-efd7-4d6a-a131-3af3d781533d",
         "size": 1,
         "project": "6a463e48-97e0-45c6-a1aa-923d5b95fcf8",
         "description": "My data volume",
         "snapshot_id": None,
         "image_id": None
     }
     response = api.create_volume(json.dumps(payload))
     assert response.ok
     assert response.message['id'] == 1 and response.message[
         'name'] == 'mydata'
コード例 #26
0
 def take_action(self, parsed_args):
     api = AtmosphereAPI(self.app_args.auth_token,
                         base_url=self.app_args.base_url,
                         timeout=self.app_args.api_server_timeout,
                         verify=self.app_args.verify_cert)
     options = None
     if parsed_args.hard_reboot:
         options = {'reboot_type': 'HARD'}
     data = api.do_instance_action('reboot',
                                   parsed_args.id,
                                   options=options)
     if data.ok and data.message['result'] == 'success':
         self.app.stdout.write('{}\n'.format(data.message['message']))
     else:
         self.app.stdout.write('Error: {}\n'.format(data.message))
コード例 #27
0
ファイル: identity.py プロジェクト: eriksf/atmosphere-cli
    def take_action(self, parsed_args):
        column_headers = ('id',
                          'uuid',
                          'username',
                          'user_id',
                          'user_uuid',
                          'key',
                          'is_leader',
                          'provider',
                          'provider_id',
                          'provider_uuid',
                          'usage',
                          'quota_cpu',
                          'quota_memory',
                          'quota_storage',
                          'quota_floating_ip_count',
                          'quota_instance_count',
                          'quota_port_count',
                          'quota_snapshot_count',
                          'quota_storage_count')
        api = AtmosphereAPI(self.app_args.auth_token, base_url=self.app_args.base_url, timeout=self.app_args.api_server_timeout, verify=self.app_args.verify_cert)
        data = api.get_identity(parsed_args.id)
        identity = ()
        if data.ok:
            message = data.message
            identity = (
                message['id'],
                message['uuid'],
                message['user']['username'],
                message['user']['id'],
                message['user']['uuid'],
                message['key'],
                message['is_leader'],
                message['provider']['name'],
                message['provider']['id'],
                message['provider']['uuid'],
                message['usage'],
                message['quota']['cpu'],
                message['quota']['memory'],
                message['quota']['storage'],
                message['quota']['floating_ip_count'],
                message['quota']['instance_count'],
                message['quota']['port_count'],
                message['quota']['snapshot_count'],
                message['quota']['storage_count']
            )

        return (column_headers, identity)
コード例 #28
0
    def take_action(self, parsed_args):
        column_headers = ('action', 'description')
        api = AtmosphereAPI(self.app_args.auth_token,
                            base_url=self.app_args.base_url,
                            timeout=self.app_args.api_server_timeout,
                            verify=self.app_args.verify_cert)
        data = api.get_instance_actions(parsed_args.id)
        actions = []
        if data.ok:
            for action in data.message:
                actions.append((
                    action['name'],
                    action['description'],
                ))

        return (column_headers, tuple(actions))
コード例 #29
0
 def test_creating_instance_when_response_is_not_ok(self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     payload = {
         "identity": "a5a6140d-1122-4581-87dc-bd9704fa07ec",
         "name": "myfirstinstance",
         "project": "7c8d34b1-1b2d-4f7f-bd62-4e0929295fd4",
         "size_alias": "100",
         "source_alias": "ec4fb434-a7b7-4c57-b882-0a1bf34506df",
         "scripts": [],
         "deploy": True,
         "extra": {}
     }
     response = api.create_instance(json.dumps(payload))
     assert not response.ok
     assert response.message['errors'][0]['code'] == 400
     assert response.message['errors'][0]['message']['allocation_source_id'] == 'This field is required.'
コード例 #30
0
 def test_creating_instance_when_response_is_ok(self):
     api = AtmosphereAPI('token', base_url=self.mock_users_base_url)
     payload = {
         "identity": "a5a6140d-1122-4581-87dc-bd9704fa07ec",
         "name": "myfirstinstance",
         "project": "7c8d34b1-1b2d-4f7f-bd62-4e0929295fd4",
         "size_alias": "100",
         "source_alias": "ec4fb434-a7b7-4c57-b882-0a1bf34506df",
         "allocation_source_id": "f4cca788-e039-4f82-bc77-9fb92141eca6",
         "scripts": [],
         "deploy": True,
         "extra": {}
     }
     response = api.create_instance(json.dumps(payload))
     assert response.ok
     assert response.message['id'] == 1 and response.message['name'] == 'myfirstinstance'