def handle(self, request, data): image_id = data['image_id'] tenant_id = data['tenant_id'] try: image = api.image_get_meta(request, image_id) flavor = api.flavor_get(request, data['flavor']) api.server_create(request, data['name'], image, flavor, data.get('key_name'), normalize_newlines(data.get('user_data')), data.get('security_groups')) msg = _('Instance was successfully launched') LOG.info(msg) messages.success(request, msg) return redirect( 'steer:engine:instances_and_volumes:instances:index') except api_exceptions.ApiException, e: LOG.exception('ApiException while creating instances of image "%s"' % image_id) messages.error(request, _('Unable to launch instance: %s') % e.message)
def handle(self, request, data): try: flavor_id = data['flavorid'] flavor = api.flavor_get(request, flavor_id) LOG.info('Deleting flavor with id "%s"' % flavor_id) api.flavor_delete(request, flavor_id, False) messages.info(request, _('Successfully deleted flavor: %s') % flavor.name) except api_exceptions.ApiException, e: messages.error(request, _('Unable to delete flavor: %s') % e.message)
def handle(self, request, data): image_id = data['image_id'] tenant_id = data['tenant_id'] try: image = api.image_get_meta(request, image_id) flavor = api.flavor_get(request, data['flavor']) api.server_create(request, data['name'], image, flavor, data.get('key_name'), normalize_newlines(data.get('user_data')), data.get('security_groups')) msg = _('Instance was successfully launched') LOG.info(msg) messages.success(request, msg) return redirect( 'steer:engine:instances_and_volumes:instances:index') except api_exceptions.ApiException, e: LOG.exception( 'ApiException while creating instances of image "%s"' % image_id) messages.error(request, _('Unable to launch instance: %s') % e.message)
def test_launch_form_apiexception(self): FLAVOR_ID = self.flavors[0].id IMAGE_ID = '1' KEY_NAME = self.keypairs[0].name SERVER_NAME = 'serverName' USER_DATA = 'userData' form_data = {'method': 'LaunchForm', 'flavor': FLAVOR_ID, 'image_id': IMAGE_ID, 'key_name': KEY_NAME, 'name': SERVER_NAME, 'tenant_id': self.TEST_TENANT, 'user_data': USER_DATA, 'security_groups': 'default', } self.mox.StubOutWithMock(api, 'image_get_meta') api.image_get_meta(IgnoreArg(), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'tenant_quota_get') api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT).AndReturn(FakeQuota) self.mox.StubOutWithMock(api, 'flavor_list') api.flavor_list(IgnoreArg()).AndReturn(self.flavors) self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IgnoreArg()).AndReturn(self.keypairs) self.mox.StubOutWithMock(api, 'security_group_list') api.security_group_list(IsA(http.HttpRequest)).AndReturn( self.security_groups) # called again by the form api.image_get_meta(IgnoreArg(), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'flavor_get') api.flavor_get(IgnoreArg(), IsA(unicode)).AndReturn(self.flavors[0]) self.mox.StubOutWithMock(api, 'server_create') exception = api_exceptions.ApiException('apiException') api.server_create(IsA(http.HttpRequest), SERVER_NAME, self.visibleImage, self.flavors[0], KEY_NAME, USER_DATA, self.security_groups).AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(basestring)) self.mox.ReplayAll() url = reverse('steer:engine:images_and_snapshots:images:launch', args=[IMAGE_ID]) res = self.client.post(url, form_data) self.assertTemplateUsed(res, 'engine/images_and_snapshots/images/launch.html')
def test_launch_post(self): FLAVOR_ID = self.flavors[0].id IMAGE_ID = '1' KEY_NAME = self.keypairs[0].name SERVER_NAME = 'serverName' USER_DATA = 'userData' form_data = {'method': 'LaunchForm', 'flavor': FLAVOR_ID, 'image_id': IMAGE_ID, 'key_name': KEY_NAME, 'name': SERVER_NAME, 'user_data': USER_DATA, 'tenant_id': self.TEST_TENANT, 'security_groups': 'default', } self.mox.StubOutWithMock(api, 'image_get_meta') api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'tenant_quota_get') api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT).AndReturn(FakeQuota) self.mox.StubOutWithMock(api, 'flavor_list') api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) self.mox.StubOutWithMock(api, 'security_group_list') api.security_group_list(IsA(http.HttpRequest)).AndReturn( self.security_groups) # called again by the form api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'flavor_get') api.flavor_get(IsA(http.HttpRequest), IsA(unicode)).AndReturn(self.flavors[0]) self.mox.StubOutWithMock(api, 'server_create') api.server_create(IsA(http.HttpRequest), SERVER_NAME, self.visibleImage, self.flavors[0], KEY_NAME, USER_DATA, [self.security_groups[0].name]) self.mox.StubOutWithMock(messages, 'success') messages.success(IsA(http.HttpRequest), IsA(basestring)) self.mox.ReplayAll() res = self.client.post( reverse('steer:engine:images_and_snapshots:images:launch', args=[IMAGE_ID]), form_data) self.assertRedirectsNoFollow(res, reverse('steer:engine:instances_and_volumes:instances:index'))