Add ability to create images
Change-Id: I1095614a50873d00f5e80ee31e1f358ac9e59416
This commit is contained in:
parent
64d8c3b82c
commit
bf59764b9a
@ -27,6 +27,10 @@ class DeleteImage(project_tables.DeleteImage):
|
||||
return True
|
||||
|
||||
|
||||
class CreateImage(project_tables.CreateImage):
|
||||
url = "horizon:infrastructure:images:create"
|
||||
|
||||
|
||||
class UpdateRow(tables.Row):
|
||||
ajax = True
|
||||
|
||||
@ -65,7 +69,6 @@ class ImagesTable(tables.DataTable):
|
||||
name = "images"
|
||||
row_class = UpdateRow
|
||||
verbose_name = _("Provisioning Images")
|
||||
table_actions = (DeleteImage,
|
||||
ImageFilterAction)
|
||||
table_actions = (CreateImage, DeleteImage, ImageFilterAction)
|
||||
row_actions = (EditImage, DeleteImage)
|
||||
template = "horizon/common/_enhanced_data_table.html"
|
||||
|
@ -0,0 +1,14 @@
|
||||
{% extends "horizon/common/_modal_form.html" %}
|
||||
{% load i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
{% block form_id %}create_image_form{% endblock %}
|
||||
{% block form_action %}{% url 'horizon:infrastructure:images:create' %}{% endblock %}
|
||||
|
||||
{% block modal_id %}create_image_modal{% endblock %}
|
||||
{% block modal-header %}{% trans "Create Image" %}{% endblock %}
|
||||
|
||||
{% block modal-body-right %}
|
||||
<h3>{% trans "Description" %}:</h3>
|
||||
<p>{% trans "Modify different properties of an image." %}</p>
|
||||
{% endblock %}
|
@ -8,14 +8,7 @@
|
||||
{% block modal_id %}update_image_modal{% endblock %}
|
||||
{% block modal-header %}{% trans "Update Image" %}{% endblock %}
|
||||
|
||||
{% block modal-body %}
|
||||
<div class="left">
|
||||
<fieldset>
|
||||
{% include "horizon/common/_form_fields.html" %}
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="right">
|
||||
<h3>{% trans "Description" %}:</h3>
|
||||
<p>{% trans "Modify different properties of an image." %}</p>
|
||||
</div>
|
||||
{% block modal-body-right %}
|
||||
<h3>{% trans "Description" %}:</h3>
|
||||
<p>{% trans "Modify different properties of an image." %}</p>
|
||||
{% endblock %}
|
||||
|
12
tuskar_ui/infrastructure/images/templates/images/create.html
Normal file
12
tuskar_ui/infrastructure/images/templates/images/create.html
Normal file
@ -0,0 +1,12 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans "Create Image" %}{% endblock %}
|
||||
|
||||
{% block page_header %}
|
||||
{% include "horizon/common/_page_header.html" with title=_("Create Image") %}
|
||||
{% endblock page_header %}
|
||||
|
||||
{% block main %}
|
||||
{% include 'infrastructure/images/_create.html' %}
|
||||
{% endblock %}
|
@ -22,8 +22,8 @@ from openstack_dashboard.dashboards.project.images.images import forms
|
||||
from tuskar_ui import api
|
||||
from tuskar_ui.test import helpers as test
|
||||
|
||||
INDEX_URL = urlresolvers.reverse(
|
||||
'horizon:infrastructure:images:index')
|
||||
INDEX_URL = urlresolvers.reverse('horizon:infrastructure:images:index')
|
||||
CREATE_URL = 'horizon:infrastructure:images:create'
|
||||
UPDATE_URL = 'horizon:infrastructure:images:update'
|
||||
|
||||
|
||||
@ -48,6 +48,45 @@ class ImagesTest(test.BaseAdminViewTests):
|
||||
|
||||
self.assertTemplateUsed(res, 'infrastructure/images/index.html')
|
||||
|
||||
def test_create_get(self):
|
||||
res = self.client.get(urlresolvers.reverse(CREATE_URL))
|
||||
self.assertTemplateUsed(res, 'infrastructure/images/create.html')
|
||||
|
||||
def test_create_post(self):
|
||||
image = self.images.list()[0]
|
||||
data = {
|
||||
'name': 'Fedora',
|
||||
'description': 'Login with admin/admin',
|
||||
'source_type': 'url',
|
||||
'image_url': 'http://www.test.com/test.iso',
|
||||
'disk_format': 'qcow2',
|
||||
'architecture': 'x86-64',
|
||||
'minimum_disk': 15,
|
||||
'minimum_ram': 512,
|
||||
'is_public': True,
|
||||
'protected': False}
|
||||
|
||||
forms.IMAGE_FORMAT_CHOICES = [('qcow2', 'qcow2')]
|
||||
|
||||
with contextlib.nested(
|
||||
patch('openstack_dashboard.api.glance.image_create',
|
||||
return_value=image),) as (mocked_create,):
|
||||
|
||||
res = self.client.post(
|
||||
urlresolvers.reverse(CREATE_URL), data)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertEqual(res.status_code, 302)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
mocked_create.assert_called_once_with(
|
||||
mock.ANY, name='Fedora', container_format='bare',
|
||||
min_ram=512, disk_format='qcow2', protected=False,
|
||||
is_public=True, min_disk=15,
|
||||
location='http://www.test.com/test.iso',
|
||||
properties={'description': 'Login with admin/admin',
|
||||
'architecture': 'x86-64'})
|
||||
|
||||
def test_update_get(self):
|
||||
image = self.images.list()[0]
|
||||
|
||||
|
@ -19,6 +19,7 @@ from tuskar_ui.infrastructure.images import views
|
||||
urlpatterns = urls.patterns(
|
||||
'',
|
||||
urls.url(r'^$', views.IndexView.as_view(), name='index'),
|
||||
urls.url(r'^create/$', views.CreateView.as_view(), name='create'),
|
||||
urls.url(r'^(?P<image_id>[^/]+)/update/$',
|
||||
views.UpdateView.as_view(), name='update'),
|
||||
)
|
||||
|
@ -85,6 +85,13 @@ class IndexView(infrastructure_views.ItemCountMixin,
|
||||
return filters
|
||||
|
||||
|
||||
class CreateView(views.CreateView):
|
||||
submit_url = "horizon:infrastructure:images:create"
|
||||
template_name = 'infrastructure/images/create.html'
|
||||
success_url = reverse_lazy("horizon:infrastructure:images:index")
|
||||
page_title = _("Create Image")
|
||||
|
||||
|
||||
class UpdateView(views.UpdateView):
|
||||
template_name = 'infrastructure/images/update.html'
|
||||
form_class = forms.UpdateImageForm
|
||||
|
Loading…
x
Reference in New Issue
Block a user