Exemple #1
0
 def __init__(self, request, *args, **kwargs):
     super(Create, self).__init__(request, *args, **kwargs)
     self.neutron_enabled = base.is_service_enabled(request, 'network')
     net_choices = network.network_list(request)
     if self.neutron_enabled:
         self.fields['neutron_net_id'] = forms.ChoiceField(
             choices=[(' ', ' ')] + [(choice.id, choice.name_or_id)
                                     for choice in net_choices],
             label=_("Neutron Net"), widget=forms.Select(
                 attrs={'class': 'switchable', 'data-slug': 'net'}))
         for net in net_choices:
             # For each network create switched choice field with
             # the its subnet choices
             subnet_field_name = 'subnet-choices-%s' % net.id
             subnet_field = forms.ChoiceField(
                 choices=(), label=_("Neutron Subnet"),
                 widget=forms.Select(attrs={
                     'class': 'switched',
                     'data-switch-on': 'net',
                     'data-net-%s' % net.id: _("Neutron Subnet")
                 }))
             self.fields[subnet_field_name] = subnet_field
             subnet_choices = neutron.subnet_list(
                 request, network_id=net.id)
             self.fields[subnet_field_name].choices = [
                 (' ', ' ')] + [(choice.id, choice.name_or_id)
                                for choice in subnet_choices]
     else:
         self.fields['nova_net_id'] = forms.ChoiceField(
             choices=[(' ', ' ')] + [(choice.id, choice.name_or_id)
                                     for choice in net_choices],
             label=_("Nova Net"), widget=forms.Select(
                 attrs={'class': 'switched', 'data-slug': 'net'}))
Exemple #2
0
 def get_share_networks_data(self):
     try:
         share_networks = manila.share_network_list(
             self.request, detailed=True, search_opts={'all_tenants': True})
         if base.is_service_enabled(self.request, 'network'):
             neutron_net_names = dict(
                 (net.id, net.name)
                 for net in neutron.network_list(self.request))
             neutron_subnet_names = dict(
                 (net.id, net.name)
                 for net in neutron.subnet_list(self.request))
             for sn in share_networks:
                 sn.neutron_net = neutron_net_names.get(
                     sn.neutron_net_id) or sn.neutron_net_id or "-"
                 sn.neutron_subnet = neutron_subnet_names.get(
                     sn.neutron_subnet_id) or sn.neutron_subnet_id or "-"
         else:
             nova_net_names = dict([
                 (net.id, net.label)
                 for net in network.network_list(self.request)
             ])
             for sn in share_networks:
                 sn.nova_net = nova_net_names.get(
                     sn.nova_net_id) or sn.nova_net_id or "-"
     except Exception:
         share_networks = []
         exceptions.handle(self.request,
                           _("Unable to retrieve share networks"))
     utils.set_tenant_name_to_objects(self.request, share_networks)
     return share_networks
Exemple #3
0
 def __init__(self, request, *args, **kwargs):
     super(Create, self).__init__(request, *args, **kwargs)
     self.neutron_enabled = base.is_service_enabled(request, 'network')
     net_choices = network.network_list(request)
     if self.neutron_enabled:
         self.fields['neutron_net_id'] = forms.ChoiceField(
             choices=[(' ', ' ')] + [(choice.id, choice.name_or_id)
                                     for choice in net_choices],
             label=_("Neutron Net"),
             widget=forms.Select(attrs={
                 'class': 'switchable',
                 'data-slug': 'net'
             }))
         for net in net_choices:
             # For each network create switched choice field with
             # the its subnet choices
             subnet_field_name = 'subnet-choices-%s' % net.id
             subnet_field = forms.ChoiceField(
                 choices=(),
                 label=_("Neutron Subnet"),
                 widget=forms.Select(
                     attrs={
                         'class': 'switched',
                         'data-switch-on': 'net',
                         'data-net-%s' % net.id: _("Neutron Subnet")
                     }))
             self.fields[subnet_field_name] = subnet_field
             subnet_choices = neutron.subnet_list(request,
                                                  network_id=net.id)
             self.fields[subnet_field_name].choices = [(' ', ' ')] + [
                 (choice.id, choice.name_or_id) for choice in subnet_choices
             ]
Exemple #4
0
 def get_share_networks_data(self):
     try:
         share_networks = manila.share_network_list(
             self.request, detailed=True, search_opts={'all_tenants': True})
         if base.is_service_enabled(self.request, 'network'):
             neutron_net_names = dict((net.id, net.name) for net in
                                      neutron.network_list(self.request))
             neutron_subnet_names = dict((net.id, net.name) for net in
                                         neutron.subnet_list(self.request))
             for sn in share_networks:
                 sn.neutron_net = neutron_net_names.get(
                     sn.neutron_net_id) or sn.neutron_net_id or "-"
                 sn.neutron_subnet = neutron_subnet_names.get(
                     sn.neutron_subnet_id) or sn.neutron_subnet_id or "-"
         else:
             nova_net_names = dict(
                 [(net.id, net.label)
                  for net in network.network_list(self.request)])
             for sn in share_networks:
                 sn.nova_net = nova_net_names.get(
                     sn.nova_net_id) or sn.nova_net_id or "-"
     except Exception:
         share_networks = []
         exceptions.handle(self.request,
                           _("Unable to retrieve share networks"))
     utils.set_project_name_to_objects(self.request, share_networks)
     return share_networks