summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorank <ank.svu@gmail.com>2015-12-03 08:51:57 +0530
committerank <ank.svu@gmail.com>2015-12-09 20:00:23 +0530
commit276a0fd1ab7c50f9e9829226a83e1c2468387bbb (patch)
treeced51f7c2a1ab6f2648fd48907c0955b879aeffc
parentaefb07dd915098b33f9684fe4e5a2c48759b77e3 (diff)
Support create member with multiple NICs
Added Networking Tab to member create work flow. Deault provider PTG will be shown as selected NIC, additionally user can select other PTGs to to add multiple NICs Change-Id: I3ceadc0f2ca9de6d9be2c4349eba6623a9aa4cd4 Closes-Bug: #1491540
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Sumit Naiksatam <sumitnaiksatam@gmail.com> Code-Review+2: Magesh GV <mageshgv@gmail.com> Workflow+1: Magesh GV <mageshgv@gmail.com> Submitted-by: Jenkins Submitted-at: Thu, 10 Dec 2015 17:05:19 +0000 Reviewed-on: https://review.openstack.org/252727 Project: openstack/group-based-policy-ui Branch: refs/heads/master
-rw-r--r--gbpui/panels/policytargets/templates/policytargets/_update_groups.html48
-rw-r--r--gbpui/panels/policytargets/workflows.py70
2 files changed, 112 insertions, 6 deletions
diff --git a/gbpui/panels/policytargets/templates/policytargets/_update_groups.html b/gbpui/panels/policytargets/templates/policytargets/_update_groups.html
new file mode 100644
index 0000000..cb21648
--- /dev/null
+++ b/gbpui/panels/policytargets/templates/policytargets/_update_groups.html
@@ -0,0 +1,48 @@
1{% load i18n %}
2
3<noscript><h3>{{ step }}</h3></noscript>
4<table class="table-fixed" id="networkListSortContainer">
5 <tbody>
6 <tr>
7 <td class="actions">
8 <label id="selected_network_label">{% trans "Selected groups" %}</label>
9 <ul id="selected_network" class="networklist">
10 </ul>
11 <label>{% trans "Available groups" %}</label>
12 <ul id="available_network" class="networklist">
13 </ul>
14 </td>
15 <td class="help_text">
16 <p>{% blocktrans %}Choose group from Available groups to Selected
17 groups by push button or drag and drop, you may change group order
18 by drag and drop as well. {% endblocktrans %}</p>
19 </td>
20 </tr>
21 </tbody>
22</table>
23
24<table class="table-fixed" id="networkListIdContainer">
25 <tbody>
26 <tr>
27 <td class="actions">
28 <div id="networkListId">
29 {% include "horizon/common/_form_fields.html" %}
30 </div>
31 </td>
32 <td class="help_text">
33 {{ step.get_help_text }}
34 </td>
35 </tr>
36 </tbody>
37</table>
38
39
40<script>
41 if (typeof $ !== 'undefined') {
42 horizon.instances.workflow_init($(".workflow"));
43 } else {
44 addHorizonLoadEvent(function() {
45 horizon.instances.workflow_init($(".workflow"));
46 });
47 }
48</script>
diff --git a/gbpui/panels/policytargets/workflows.py b/gbpui/panels/policytargets/workflows.py
index 3c9e126..d987066 100644
--- a/gbpui/panels/policytargets/workflows.py
+++ b/gbpui/panels/policytargets/workflows.py
@@ -13,6 +13,7 @@
13import logging 13import logging
14 14
15from django.core.urlresolvers import reverse 15from django.core.urlresolvers import reverse
16from django import shortcuts
16from django.utils import html 17from django.utils import html
17from django.utils.text import normalize_newlines # noqa 18from django.utils.text import normalize_newlines # noqa
18from django.utils.translation import ugettext_lazy as _ 19from django.utils.translation import ugettext_lazy as _
@@ -389,6 +390,60 @@ class SetAccessControls(workflows.Step):
389 return context 390 return context
390 391
391 392
393class SetGroupAction(workflows.Action):
394 # To reuse horizon instance launch code related to Networking,
395 # form filed must be 'network' only
396 network = forms.MultipleChoiceField(label=_("Groups"),
397 widget=forms.CheckboxSelectMultiple(),
398 error_messages={
399 'required': _(
400 "At least one group must"
401 " be specified.")},
402 help_text=_("Launch member instance in"
403 " these groups"))
404
405 widget = forms.HiddenInput()
406
407 def __init__(self, request, *args, **kwargs):
408 super(SetGroupAction, self).__init__(request, *args, **kwargs)
409 policy_targetid = self.request.path.split("/")[-2]
410 self.fields['network'].initial = [policy_targetid]
411
412 class Meta(object):
413 name = _("Groups")
414 help_text = _("Select groups for launching the member instance in.")
415
416 def populate_network_choices(self, request, context):
417 try:
418 pt_list = []
419 pts = client.policy_target_list(request,
420 tenant_id=request.user.tenant_id)
421 for pt in pts:
422 pt.set_id_as_name_if_empty()
423 pt_list.append((pt.id, pt.name))
424 return sorted(pt_list, key=lambda obj: obj[1])
425 except Exception:
426 msg = _("Failed to retrieve groups")
427 LOG.error(msg)
428 exceptions.handle(request, msg, redirect=shortcuts.redirect)
429
430
431class SetGroup(workflows.Step):
432 action_class = SetGroupAction
433
434 template_name = "project/policytargets/_update_groups.html"
435 contributes = ("group_id",)
436
437 def contribute(self, data, context):
438 if data:
439 groups = self.workflow.request.POST.getlist("network")
440 groups = [n for n in groups if n != '']
441 if groups:
442 context['group_id'] = groups
443
444 return context
445
446
392class LaunchInstance(workflows.Workflow): 447class LaunchInstance(workflows.Workflow):
393 slug = "create_member" 448 slug = "create_member"
394 name = _("Create Member") 449 name = _("Create Member")
@@ -398,6 +453,7 @@ class LaunchInstance(workflows.Workflow):
398 default_steps = (workflows_create_instance.SelectProjectUser, 453 default_steps = (workflows_create_instance.SelectProjectUser,
399 workflows_create_instance.SetInstanceDetails, 454 workflows_create_instance.SetInstanceDetails,
400 SetAccessControls, 455 SetAccessControls,
456 SetGroup,
401 workflows_create_instance.PostCreationStep, 457 workflows_create_instance.PostCreationStep,
402 workflows_create_instance.SetAdvanced) 458 workflows_create_instance.SetAdvanced)
403 459
@@ -417,7 +473,6 @@ class LaunchInstance(workflows.Workflow):
417 @sensitive_variables('context') 473 @sensitive_variables('context')
418 def handle(self, request, context): 474 def handle(self, request, context):
419 custom_script = context.get('script_data', '') 475 custom_script = context.get('script_data', '')
420
421 dev_mapping_1 = None 476 dev_mapping_1 = None
422 dev_mapping_2 = None 477 dev_mapping_2 = None
423 478
@@ -474,7 +529,6 @@ class LaunchInstance(workflows.Workflow):
474 ] 529 ]
475 avail_zone = context.get('availability_zone', None) 530 avail_zone = context.get('availability_zone', None)
476 try: 531 try:
477 policy_target_id = self.request.path.split("/")[-2]
478 instance_count = int(context['count']) 532 instance_count = int(context['count'])
479 count = 1 533 count = 1
480 while count <= instance_count: 534 while count <= instance_count:
@@ -482,9 +536,12 @@ class LaunchInstance(workflows.Workflow):
482 instance_name = context['name'] 536 instance_name = context['name']
483 else: 537 else:
484 instance_name = context['name'] + str(count) 538 instance_name = context['name'] + str(count)
485 ep = client.pt_create( 539 nics = []
486 request, policy_target_group_id=policy_target_id, 540 for ptg_id in context['group_id']:
487 name=instance_name[:41] + "_gbpui") 541 ep = client.pt_create(
542 request, policy_target_group_id=ptg_id,
543 name=instance_name[:41] + "_gbpui")
544 nics.append({'port-id': ep.port_id})
488 api.nova.server_create(request, 545 api.nova.server_create(request,
489 instance_name, 546 instance_name,
490 image_id, 547 image_id,
@@ -494,7 +551,7 @@ class LaunchInstance(workflows.Workflow):
494 security_groups=None, 551 security_groups=None,
495 block_device_mapping=dev_mapping_1, 552 block_device_mapping=dev_mapping_1,
496 block_device_mapping_v2=dev_mapping_2, 553 block_device_mapping_v2=dev_mapping_2,
497 nics=[{'port-id': ep.port_id}], 554 nics=nics,
498 availability_zone=avail_zone, 555 availability_zone=avail_zone,
499 instance_count=1, 556 instance_count=1,
500 admin_pass=context['admin_pass'], 557 admin_pass=context['admin_pass'],
@@ -507,6 +564,7 @@ class LaunchInstance(workflows.Workflow):
507 msg = error % {'count': count, 'name': instance_name} 564 msg = error % {'count': count, 'name': instance_name}
508 LOG.error(msg) 565 LOG.error(msg)
509 u = "horizon:project:policytargets:policy_targetdetails" 566 u = "horizon:project:policytargets:policy_targetdetails"
567 policy_target_id = self.request.path.split("/")[-2]
510 redirect = reverse(u, kwargs={'policy_target_id': 568 redirect = reverse(u, kwargs={'policy_target_id':
511 policy_target_id}) 569 policy_target_id})
512 exceptions.handle(request, msg, redirect=redirect) 570 exceptions.handle(request, msg, redirect=redirect)