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