Beispiel #1
0
    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')
        api.image_get(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(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('horizon:nova:images:launch',
                                       args=[IMAGE_ID]),
                               form_data)

        self.assertRedirectsNoFollow(res,
                                     reverse('horizon:nova:instances:index'))
Beispiel #2
0
    def test_launch_flavorlist_error(self):
        image = self.images.first()

        self.mox.StubOutWithMock(api, 'image_get')
        self.mox.StubOutWithMock(api, 'tenant_quota_usages')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api, 'volume_snapshot_list')
        self.mox.StubOutWithMock(api, 'volume_list')

        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.volumes.list())
        api.image_get(IsA(http.HttpRequest),
                           image.id).AndReturn(image)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(
                self.quota_usages.first())
        api.flavor_list(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova)
        api.flavor_list(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova)
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        self.mox.ReplayAll()

        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.get(url)
        self.assertTemplateUsed(res,
                                'nova/images_and_snapshots/images/launch.html')
Beispiel #3
0
    def test_launch_get(self):
        image = self.images.first()
        quota_usages = self.quota_usages.first()

        self.mox.StubOutWithMock(api, 'image_get')
        self.mox.StubOutWithMock(api, 'tenant_quota_usages')
        # Two flavor_list calls, however, flavor_list is now memoized.
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.image_get(IsA(http.HttpRequest), image.id).AndReturn(image)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(quota_usages)
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        self.mox.ReplayAll()

        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.get(url)
        form = res.context['form']
        self.assertTemplateUsed(res,
                                'nova/images_and_snapshots/images/launch.html')
        self.assertEqual(res.context['image'].name, image.name)
        self.assertIn(self.flavors.first().name,
                      form.fields['flavor'].choices[0][1])
        self.assertEqual(self.keypairs.first().name,
                         form.fields['keypair'].choices[1][0])
Beispiel #4
0
    def test_launch_keypairlist_error(self):
        image = self.images.first()

        self.mox.StubOutWithMock(api, 'image_get')
        self.mox.StubOutWithMock(api, 'tenant_quota_usages')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.image_get(IsA(http.HttpRequest), image.id).AndReturn(image)
        api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(
                self.quota_usages.first())
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        exception = keystone_exceptions.ClientException('Failed.')
        api.keypair_list(IsA(http.HttpRequest)).AndRaise(exception)
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        self.mox.ReplayAll()

        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.get(url)
        self.assertTemplateUsed(res,
                                'nova/images_and_snapshots/images/launch.html')
        self.assertEqual(len(res.context['form'].fields['keypair'].choices), 1)
Beispiel #5
0
    def test_launch_keypairlist_error(self):
        IMAGE_ID = '2'

        self.mox.StubOutWithMock(api, 'image_get')
        api.image_get(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)

        exception = api_exceptions.ApiException('apiException')
        self.mox.StubOutWithMock(api, 'keypair_list')
        api.keypair_list(IsA(http.HttpRequest)).AndRaise(exception)

        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(
                                    self.security_groups)

        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:nova:images:launch',
                                      args=[IMAGE_ID]))

        self.assertTemplateUsed(res, 'nova/images/launch.html')

        form = res.context['form']

        form_keyfield = form.fields['key_name']
        self.assertEqual(len(form_keyfield.choices), 0)
Beispiel #6
0
    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')
        api.image_get(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(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('horizon:nova:images:launch', args=[IMAGE_ID])
        res = self.client.post(url, form_data)

        self.assertTemplateUsed(res, 'nova/images/launch.html')
Beispiel #7
0
    def test_launch_post(self):
        flavor = self.flavors.first()
        image = self.images.first()
        keypair = self.keypairs.first()
        server = self.servers.first()
        volume = self.volumes.first()
        sec_group = self.security_groups.first()
        USER_DATA = 'user data'
        device_name = u'vda'
        volume_choice = "%s:vol" % volume.id
        block_device_mapping = {device_name: u"%s::0" % volume_choice}

        self.mox.StubOutWithMock(api, 'image_get')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api, 'server_create')
        self.mox.StubOutWithMock(api, 'volume_list')
        self.mox.StubOutWithMock(api, 'volume_snapshot_list')

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.volumes.list())
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        api.image_get(IsA(http.HttpRequest), image.id).AndReturn(image)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.server_create(IsA(http.HttpRequest),
                          server.name,
                          image.id,
                          flavor.id,
                          keypair.name,
                          USER_DATA,
                          [sec_group.name],
                          block_device_mapping,
                          instance_count=IsA(int))
        self.mox.ReplayAll()

        form_data = {'method': 'LaunchForm',
                     'flavor': flavor.id,
                     'image_id': image.id,
                     'keypair': keypair.name,
                     'name': server.name,
                     'user_data': USER_DATA,
                     'tenant_id': self.tenants.first().id,
                     'security_groups': sec_group.name,
                     'volume': volume_choice,
                     'device_name': device_name,
                     'count': 1}
        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.post(url, form_data)
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res,
                 reverse('horizon:nova:instances_and_volumes:index'))
Beispiel #8
0
    def test_launch_form_keystone_exception(self):
        flavor = self.flavors.first()
        image = self.images.first()
        keypair = self.keypairs.first()
        server = self.servers.first()
        sec_group = self.security_groups.first()
        USER_DATA = 'userData'

        self.mox.StubOutWithMock(api, 'image_get')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api, 'server_create')
        self.mox.StubOutWithMock(api, 'volume_list')
        self.mox.StubOutWithMock(api, 'volume_snapshot_list')

        api.volume_snapshot_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.volumes.list())
        api.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())
        api.keypair_list(IgnoreArg()).AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        api.image_get(IgnoreArg(), image.id).AndReturn(image)
        api.volume_list(IgnoreArg()).AndReturn(self.volumes.list())
        api.server_create(IsA(http.HttpRequest),
                          server.name,
                          image.id,
                          flavor.id,
                          keypair.name,
                          USER_DATA,
                          [sec_group.name],
                          None,
                          instance_count=IsA(int)) \
                      .AndRaise(self.exceptions.keystone)
        self.mox.ReplayAll()

        form_data = {'method': 'LaunchForm',
                     'flavor': flavor.id,
                     'image_id': image.id,
                     'keypair': keypair.name,
                     'name': server.name,
                     'tenant_id': self.tenant.id,
                     'user_data': USER_DATA,
                     'count': 1,
                     'security_groups': sec_group.name}
        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.post(url, form_data)
        self.assertRedirectsNoFollow(res, IMAGES_INDEX_URL)
Beispiel #9
0
def update(request, image_id):
    try:
        image = api.image_get(request, image_id)
    except glance_exception.ClientConnectionError, e:
        LOG.exception("Error connecting to glance")
        messages.error(request,
                       _("Error connecting to glance: %s") % e.message)
Beispiel #10
0
def update(request, image_id):
    try:
        image = api.image_get(request, image_id)
    except glance_exception.ClientConnectionError, e:
        LOG.exception("Error connecting to glance")
        messages.error(request, _("Error connecting to glance: %s")
                                 % e.message)
Beispiel #11
0
    def test_launch_form_instance_count_error(self):
        flavor = self.flavors.first()
        image = self.images.first()
        keypair = self.keypairs.first()
        server = self.servers.first()
        volume = self.volumes.first()
        sec_group = self.security_groups.first()
        USER_DATA = 'user data'
        device_name = u'vda'
        volume_choice = "%s:vol" % volume.id

        self.mox.StubOutWithMock(api, 'image_get')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'flavor_list')
        self.mox.StubOutWithMock(api, 'keypair_list')
        self.mox.StubOutWithMock(api, 'security_group_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        self.mox.StubOutWithMock(api, 'volume_snapshot_list')
        self.mox.StubOutWithMock(api, 'tenant_quota_usages')

        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
        api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list())
        api.security_group_list(IsA(http.HttpRequest)) \
                                .AndReturn(self.security_groups.list())
        api.image_get(IsA(http.HttpRequest), image.id).AndReturn(image)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list())
        api.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn([])
        api.tenant_quota_usages(IsA(http.HttpRequest)) \
                                .AndReturn(self.quota_usages.first())
        self.mox.ReplayAll()

        form_data = {'method': 'LaunchForm',
                     'flavor': flavor.id,
                     'image_id': image.id,
                     'keypair': keypair.name,
                     'name': server.name,
                     'user_data': USER_DATA,
                     'tenant_id': self.tenants.first().id,
                     'security_groups': sec_group.name,
                     'volume': volume_choice,
                     'device_name': device_name,
                     'count': 0}
        url = reverse('horizon:nova:images_and_snapshots:images:launch',
                      args=[image.id])
        res = self.client.post(url, form_data)
        self.assertFormErrors(res, count=1)
Beispiel #12
0
 def get_object(self, *args, **kwargs):
     try:
         self.object = api.image_get(self.request, kwargs['image_id'])
     except:
         msg = _('Unable to retrieve image.')
         redirect = reverse('horizon:nova:images_and_snapshots:index')
         exceptions.handle(self.request, msg, redirect=redirect)
     return self.object
Beispiel #13
0
 def get_object(self, *args, **kwargs):
     try:
         self.object = api.image_get(self.request, kwargs['image_id'])
     except:
         msg = _('Unable to retrieve image.')
         redirect = reverse('horizon:nova:images_and_snapshots:index')
         exceptions.handle(self.request, msg, redirect=redirect)
     return self.object
Beispiel #14
0
 def get_object(self):
     if not hasattr(self, "_object"):
         try:
             self._object = api.image_get(self.request, self.kwargs["image_id"])
         except:
             msg = _("Unable to retrieve image.")
             redirect = reverse("horizon:nova:images_and_snapshots:index")
             exceptions.handle(self.request, msg, redirect=redirect)
     return self._object
Beispiel #15
0
 def get_object(self):
     if not hasattr(self, "_object"):
         try:
             self._object = api.image_get(self.request,
                                          self.kwargs['image_id'])
         except:
             msg = _('Unable to retrieve image.')
             url = reverse('horizon:project:images_and_snapshots:index')
             exceptions.handle(self.request, msg, redirect=url)
     return self._object
Beispiel #16
0
    def test_image_update_get(self):
        image = self.images.first()
        image.disk_format = "ami"
        image.is_public = True
        api.image_get(IsA(http.HttpRequest), str(image.id)) \
           .AndReturn(image)
        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:images_and_snapshots:images:update',
                    args=[image.id]))

        self.assertTemplateUsed(res,
                            'nova/images_and_snapshots/images/_update.html')
        self.assertEqual(res.context['image'].name, image.name)
        # Bug 1076216 - is_public checkbox not being set correctly
        self.assertContains(res, "<input type='checkbox' id='id_public'"
                                 " name='public' checked='checked'>",
                            html=True,
                            msg_prefix="The is_public checkbox is not checked")
Beispiel #17
0
    def test_launch_get(self):
        IMAGE_ID = '1'

        self.mox.StubOutWithMock(api, 'image_get')
        api.image_get(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)

        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:nova:images:launch',
                                      args=[IMAGE_ID]))

        self.assertTemplateUsed(res, 'nova/images/launch.html')

        image = res.context['image']
        self.assertEqual(image.name, self.visibleImage.name)

        form = res.context['form']

        form_flavorfield = form.fields['flavor']
        self.assertIn('m1.massive', form_flavorfield.choices[0][1])

        form_keyfield = form.fields['key_name']
        self.assertEqual(form_keyfield.choices[0][0],
                         self.keypairs[0].name)

        self.mox.VerifyAll()
Beispiel #18
0
    def handle(self, request, data):
        image_id = data['image_id']
        tenant_id = request.user.tenant_id
        error_retrieving = _('Unable to retrieve image info from glance: %s' %
                             image_id)
        error_updating = _('Error updating image with id: %s' % image_id)

        try:
            image = api.image_get(request, image_id)
        except glance_exception.ClientConnectionError, e:
            LOG.exception(_('Error connecting to glance'))
            messages.error(request, error_retrieving)
Beispiel #19
0
    def handle(self, request, data):
        image_id = data['image_id']
        tenant_id = request.user.tenant_id
        error_retrieving = _('Unable to retreive image info from glance: %s'
                             % image_id)
        error_updating = _('Error updating image with id: %s' % image_id)

        try:
            image = api.image_get(request, image_id)
        except glance_exception.ClientConnectionError, e:
            LOG.exception(_('Error connecting to glance'))
            messages.error(request, error_retrieving)
Beispiel #20
0
    def test_launch_get(self):
        IMAGE_ID = '1'

        self.mox.StubOutWithMock(api, 'image_get')
        api.image_get(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)

        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:nova:images:launch',
                                      args=[IMAGE_ID]))

        self.assertTemplateUsed(res, 'nova/images/launch.html')

        image = res.context['image']
        self.assertEqual(image.name, self.visibleImage.name)

        form = res.context['form']

        form_flavorfield = form.fields['flavor']
        self.assertIn('m1.massive', form_flavorfield.choices[0][1])

        form_keyfield = form.fields['key_name']
        self.assertEqual(form_keyfield.choices[0][0],
                         self.keypairs[0].name)
Beispiel #21
0
 def handle(self, request, data):
     image_id = data['image_id']
     tenant_id = request.user.tenant_id
     try:
         image = api.image_get(request, image_id)
         if image.owner == request.user.username:
             api.image_delete(request, image_id)
         else:
             messages.info(request, _("Unable to delete image, you are not \
                                      its owner."))
             return redirect('dash_images_update', tenant_id, image_id)
     except glance_exception.ClientConnectionError, e:
         LOG.exception("Error connecting to glance")
         messages.error(request, _("Error connecting to glance: %s")
                                 % e.message)
Beispiel #22
0
 def handle(self, request, data):
     image_id = data['image_id']
     tenant_id = request.user.tenant_id
     try:
         image = api.image_get(request, image_id)
         if image.owner == request.user.username:
             api.image_delete(request, image_id)
         else:
             messages.info(
                 request,
                 _("Unable to delete image, you are not \
                                      its owner."))
             return redirect('dash_images_update', tenant_id, image_id)
     except glance_exception.ClientConnectionError, e:
         LOG.exception("Error connecting to glance")
         messages.error(request,
                        _("Error connecting to glance: %s") % e.message)
Beispiel #23
0
    def handle(self, request, data):
        image_id = data['image_id']
        tenant_id = data['tenant_id']
        try:
            image = api.image_get(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('horizon:nova: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)
Beispiel #24
0
    def handle(self, request, data):
        image_id = data['image_id']
        tenant_id = data['tenant_id']
        try:
            image = api.image_get(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('horizon:nova: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)
Beispiel #25
0
            LOG.exception('Unable to retrieve list of keypairs')
            return []

    def securitygrouplist():
        try:
            fl = api.security_group_list(request)
            sel = [(f.name, f.name) for f in fl]
            return sel
        except novaclient_exceptions.ClientException, e:
            LOG.exception('Unable to retrieve list of security groups')
            return []

    tenant_id = request.user.tenant_id
    # TODO(mgius): Any reason why these can't be after the launchform logic?
    # If The form is valid, we've just wasted these two api calls
    image = api.image_get(request, image_id)
    quotas = api.tenant_quota_get(request, request.user.tenant_id)
    try:
        quotas.ram = int(quotas.ram)
    except Exception, e:
        messages.error(request,
                _('Error parsing quota  for %(image)s: %(msg)s') %
                {"image": image_id, "msg": e.message})
        return shortcuts.redirect('horizon:nova:instances:index')

    form, handled = LaunchForm.maybe_handle(
            request, initial={'flavorlist': flavorlist(),
                              'keynamelist': keynamelist(),
                              'securitygrouplist': securitygrouplist(),
                              'image_id': image_id,
                              'tenant_id': tenant_id})
Beispiel #26
0
 def get_data(self, request, image_id):
     image = api.image_get(request, image_id)
     return image
Beispiel #27
0
 def get_data(self, request, image_id):
     image = api.image_get(request, image_id)
     return image