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))
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"
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"
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))
def test_unshelving_instance_when_response_is_ok(self): api = AtmosphereAPI('token', base_url=self.mock_users_base_url) response = api.do_instance_action('unshelve', 1) assert response.ok assert response.message['result'] == 'success' and response.message['message'] == 'The requested action <unshelve> was run successfully'