Merge "Replace set_id_as_name_if_empty with name_or_id"

This commit is contained in:
Jenkins 2014-12-22 16:14:46 +00:00 committed by Gerrit Code Review
commit 15b9b8d064
28 changed files with 41 additions and 95 deletions

View File

@ -94,7 +94,7 @@ DISPLAY_CHOICES = (
class PortsTable(tables.DataTable):
name = tables.Column("name",
name = tables.Column("name_or_id",
verbose_name=_("Name"),
link="horizon:admin:networks:ports:detail")
fixed_ips = tables.Column(

View File

@ -89,7 +89,7 @@ class UpdateSubnet(proj_tables.SubnetPolicyTargetMixin, tables.LinkAction):
class SubnetsTable(tables.DataTable):
name = tables.Column("name", verbose_name=_("Name"),
name = tables.Column("name_or_id", verbose_name=_("Name"),
link='horizon:admin:networks:subnets:detail')
cidr = tables.Column("cidr", verbose_name=_("CIDR"))
ip_version = tables.Column("ipver_str", verbose_name=_("IP Version"))

View File

@ -91,7 +91,7 @@ DISPLAY_CHOICES = (
class NetworksTable(tables.DataTable):
tenant = tables.Column("tenant_name", verbose_name=_("Project"))
name = tables.Column("name", verbose_name=_("Network Name"),
name = tables.Column("name_or_id", verbose_name=_("Network Name"),
link='horizon:admin:networks:detail')
subnets = tables.Column(project_tables.get_subnets,
verbose_name=_("Subnets Associated"),)

View File

@ -82,8 +82,6 @@ class IndexView(tables.DataTableView):
# Set tenant name
tenant = tenant_dict.get(n.tenant_id, None)
n.tenant_name = getattr(tenant, 'name', None)
# If name is empty use UUID as name
n.set_id_as_name_if_empty()
n.num_agents = self._get_agents_data(n.id)
if self.exception:
@ -113,8 +111,6 @@ class DetailView(tables.MultiTableView):
subnets = []
msg = _('Subnet list can not be retrieved.')
exceptions.handle(self.request, msg)
for s in subnets:
s.set_id_as_name_if_empty()
return subnets
def get_ports_data(self):
@ -125,8 +121,6 @@ class DetailView(tables.MultiTableView):
ports = []
msg = _('Port list can not be retrieved.')
exceptions.handle(self.request, msg)
for p in ports:
p.set_id_as_name_if_empty()
return ports
def get_agents_data(self):

View File

@ -48,7 +48,7 @@ class IndexView(r_views.IndexView, n_views.IndexView):
tenant = tenant_dict.get(r.tenant_id, None)
r.tenant_name = getattr(tenant, 'name', None)
# If name is empty use UUID as name
r.set_id_as_name_if_empty()
r.name = r.name_or_id
# Set external network name
self._set_external_network(r, ext_net_dict)
return routers

View File

@ -63,8 +63,7 @@ class GeneralTab(tabs.Tab):
if getattr(cluster, 'neutron_management_network', None):
net_id = cluster.neutron_management_network
network = neutron.network_get(request, net_id)
network.set_id_as_name_if_empty()
net_name = network.name
net_name = network.name_or_id
else:
net_name = None

View File

@ -23,9 +23,8 @@ def populate_neutron_management_network_choices(self, request, context):
try:
tenant_id = self.request.user.tenant_id
networks = neutron.network_list_for_tenant(request, tenant_id)
for n in networks:
n.set_id_as_name_if_empty()
network_list = [(network.id, network.name) for network in networks]
network_list = [(network.id, network.name_or_id)
for network in networks]
except Exception:
network_list = []
exceptions.handle(request,

View File

@ -152,9 +152,8 @@ class SetNetworkAction(workflows.Action):
try:
tenant_id = self.request.user.tenant_id
networks = api.neutron.network_list_for_tenant(request, tenant_id)
for n in networks:
n.set_id_as_name_if_empty()
network_list = [(network.id, network.name) for network in networks]
network_list = [(network.id, network.name_or_id)
for network in networks]
except Exception:
network_list = []
exceptions.handle(request,

View File

@ -152,8 +152,7 @@ class UpdateFirewall(forms.SelfHandlingForm):
firewall_policy_id_choices = [(policy_id, policy_name)]
for p in policies:
if p.id != policy_id:
p.set_id_as_name_if_empty()
firewall_policy_id_choices.append((p.id, p.name))
firewall_policy_id_choices.append((p.id, p.name_or_id))
self.fields['firewall_policy_id'].choices = firewall_policy_id_choices
@ -191,9 +190,7 @@ class InsertRuleToPolicy(forms.SelfHandlingForm):
tenant_id = self.request.user.tenant_id
try:
all_rules = api.fwaas.rule_list(request, tenant_id=tenant_id)
for r in all_rules:
r.set_id_as_name_if_empty()
all_rules = sorted(all_rules, key=lambda rule: rule.name)
all_rules = sorted(all_rules, key=lambda rule: rule.name_or_id)
available_rules = [r for r in all_rules
if not r.firewall_policy_id]
@ -203,8 +200,8 @@ class InsertRuleToPolicy(forms.SelfHandlingForm):
r_obj = [rule for rule in all_rules if r == rule.id][0]
current_rules.append(r_obj)
available_choices = [(r.id, r.name) for r in available_rules]
current_choices = [(r.id, r.name) for r in current_rules]
available_choices = [(r.id, r.name_or_id) for r in available_rules]
current_choices = [(r.id, r.name_or_id) for r in current_rules]
except Exception as e:
msg = _('Failed to retrieve available rules: %s') % e
@ -252,15 +249,13 @@ class RemoveRuleFromPolicy(forms.SelfHandlingForm):
tenant_id = request.user.tenant_id
try:
all_rules = api.fwaas.rule_list(request, tenant_id=tenant_id)
for r in all_rules:
r.set_id_as_name_if_empty()
current_rules = []
for r in kwargs['initial']['firewall_rules']:
r_obj = [rule for rule in all_rules if r == rule.id][0]
current_rules.append(r_obj)
current_choices = [(r.id, r.name) for r in current_rules]
current_choices = [(r.id, r.name_or_id) for r in current_rules]
except Exception as e:
msg = _('Failed to retrieve current rules in policy %(name)s: '
'%(reason)s') % {'name': self.initial['name'], 'reason': e}

View File

@ -194,7 +194,7 @@ def get_policy_link(datum):
class RulesTable(tables.DataTable):
name = tables.Column("name",
name = tables.Column("name_or_id",
verbose_name=_("Name"),
link="horizon:project:firewalls:ruledetails")
protocol = tables.Column("protocol",
@ -226,7 +226,7 @@ class RulesTable(tables.DataTable):
class PoliciesTable(tables.DataTable):
name = tables.Column("name",
name = tables.Column("name_or_id",
verbose_name=_("Name"),
link="horizon:project:firewalls:policydetails")
firewall_rules = tables.Column(get_rules_name,
@ -243,7 +243,7 @@ class PoliciesTable(tables.DataTable):
class FirewallsTable(tables.DataTable):
name = tables.Column("name",
name = tables.Column("name_or_id",
verbose_name=_("Name"),
link="horizon:project:firewalls:firewalldetails")
firewall_policy_id = tables.Column(get_policy_name,

View File

@ -41,8 +41,6 @@ class RulesTab(tabs.TableTab):
rules = []
exceptions.handle(self.tab_group.request,
_('Unable to retrieve rules list.'))
for r in rules:
r.set_id_as_name_if_empty()
return rules
@ -62,8 +60,6 @@ class PoliciesTab(tabs.TableTab):
policies = []
exceptions.handle(self.tab_group.request,
_('Unable to retrieve policies list.'))
for p in policies:
p.set_id_as_name_if_empty()
return policies
@ -84,9 +80,6 @@ class FirewallsTab(tabs.TableTab):
exceptions.handle(self.tab_group.request,
_('Unable to retrieve firewall list.'))
for f in firewalls:
f.set_id_as_name_if_empty()
return firewalls

View File

@ -128,7 +128,7 @@ class UpdateRuleView(forms.ModalFormView):
obj = self._get_object()
context['page_title'] = _("Edit Rule")
if obj:
context['name'] = obj.name
context['name'] = obj.name_or_id
context['page_title'] = _("Edit Rule "
"%(rule_name)s") % {'rule_name':
obj.name}
@ -139,7 +139,6 @@ class UpdateRuleView(forms.ModalFormView):
rule_id = self.kwargs['rule_id']
try:
rule = api.fwaas.rule_get(self.request, rule_id)
rule.set_id_as_name_if_empty()
return rule
except Exception:
redirect = self.success_url
@ -167,7 +166,7 @@ class UpdatePolicyView(forms.ModalFormView):
obj = self._get_object()
context['page_title'] = _("Edit Policy")
if obj:
context['name'] = obj.name
context['name'] = obj.name_or_id
context['page_title'] = _("Edit Policy %s") % obj.name
return context
@ -176,7 +175,6 @@ class UpdatePolicyView(forms.ModalFormView):
policy_id = self.kwargs['policy_id']
try:
policy = api.fwaas.policy_get(self.request, policy_id)
policy.set_id_as_name_if_empty()
return policy
except Exception:
redirect = self.success_url
@ -211,7 +209,6 @@ class UpdateFirewallView(forms.ModalFormView):
try:
firewall = api.fwaas.firewall_get(self.request,
firewall_id)
firewall.set_id_as_name_if_empty()
return firewall
except Exception:
redirect = self.success_url
@ -236,7 +233,7 @@ class InsertRuleToPolicyView(forms.ModalFormView):
context["policy_id"] = self.kwargs['policy_id']
obj = self._get_object()
if obj:
context['name'] = obj.name
context['name'] = obj.name_or_id
return context
@memoized.memoized_method
@ -244,7 +241,6 @@ class InsertRuleToPolicyView(forms.ModalFormView):
policy_id = self.kwargs['policy_id']
try:
policy = api.fwaas.policy_get(self.request, policy_id)
policy.set_id_as_name_if_empty()
return policy
except Exception:
redirect = self.success_url
@ -270,7 +266,7 @@ class RemoveRuleFromPolicyView(forms.ModalFormView):
context["policy_id"] = self.kwargs['policy_id']
obj = self._get_object()
if obj:
context['name'] = obj.name
context['name'] = obj.name_or_id
return context
@memoized.memoized_method
@ -278,7 +274,6 @@ class RemoveRuleFromPolicyView(forms.ModalFormView):
policy_id = self.kwargs['policy_id']
try:
policy = api.fwaas.policy_get(self.request, policy_id)
policy.set_id_as_name_if_empty()
return policy
except Exception:
redirect = self.success_url

View File

@ -142,11 +142,9 @@ class SelectRulesAction(workflows.Action):
try:
tenant_id = self.request.user.tenant_id
rules = api.fwaas.rule_list(request, tenant_id=tenant_id)
for r in rules:
r.set_id_as_name_if_empty()
rules = sorted(rules,
key=lambda rule: rule.name)
rule_list = [(rule.id, rule.name) for rule in rules
key=lambda rule: rule.name_or_id)
rule_list = [(rule.id, rule.name_or_id) for rule in rules
if not rule.firewall_policy_id]
except Exception as e:
rule_list = []
@ -257,8 +255,7 @@ class AddFirewallAction(workflows.Action):
'error': str(e)})
policies = []
for p in policies:
p.set_id_as_name_if_empty()
firewall_policy_id_choices.append((p.id, p.name))
firewall_policy_id_choices.append((p.id, p.name_or_id))
self.fields['firewall_policy_id'].choices = firewall_policy_id_choices
# only admin can set 'shared' attribute to True
if not request.user.is_superuser:

View File

@ -732,8 +732,7 @@ class SetNetworkAction(workflows.Action):
tenant_id = self.request.user.tenant_id
networks = api.neutron.network_list_for_tenant(request, tenant_id)
for n in networks:
n.set_id_as_name_if_empty()
network_list.append((n.id, n.name))
network_list.append((n.id, n.name_or_id))
sorted(network_list, key=lambda obj: obj[1])
except Exception:
exceptions.handle(request,

View File

@ -266,7 +266,7 @@ class DeletePMAssociationLink(policy.PolicyTargetMixin,
class PoolsTable(tables.DataTable):
name = tables.Column("name",
name = tables.Column("name_or_id",
verbose_name=_("Name"),
link="horizon:project:loadbalancers:pooldetails")
description = tables.Column('description', verbose_name=_("Description"))

View File

@ -38,8 +38,6 @@ class PoolsTab(tabs.TableTab):
pools = []
exceptions.handle(self.tab_group.request,
_('Unable to retrieve pools list.'))
for p in pools:
p.set_id_as_name_if_empty()
return pools
@ -58,8 +56,6 @@ class MembersTab(tabs.TableTab):
members = []
exceptions.handle(self.tab_group.request,
_('Unable to retrieve member list.'))
for m in members:
m.set_id_as_name_if_empty()
return members

View File

@ -58,7 +58,7 @@ DISPLAY_CHOICES = (
class PortsTable(tables.DataTable):
name = tables.Column("name",
name = tables.Column("name_or_id",
verbose_name=_("Name"),
link="horizon:project:networks:ports:detail")
fixed_ips = tables.Column(get_fixed_ips, verbose_name=_("Fixed IPs"))

View File

@ -126,7 +126,7 @@ class UpdateSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
class SubnetsTable(tables.DataTable):
name = tables.Column("name", verbose_name=_("Name"),
name = tables.Column("name_or_id", verbose_name=_("Name"),
link='horizon:project:networks:subnets:detail')
cidr = tables.Column("cidr", verbose_name=_("Network Address"))
ip_version = tables.Column("ipver_str", verbose_name=_("IP Version"))

View File

@ -42,7 +42,6 @@ class CreateView(workflows.WorkflowView):
try:
network_id = self.kwargs["network_id"]
network = api.neutron.network_get(self.request, network_id)
network.set_id_as_name_if_empty()
return network
except Exception:
redirect = reverse('horizon:project:networks:index')
@ -52,7 +51,7 @@ class CreateView(workflows.WorkflowView):
def get_initial(self):
network = self.get_object()
return {"network_id": self.kwargs['network_id'],
"network_name": network.name}
"network_name": network.name_or_id}
class UpdateView(workflows.WorkflowView):

View File

@ -149,7 +149,7 @@ DISPLAY_CHOICES = (
class NetworksTable(tables.DataTable):
name = tables.Column("name",
name = tables.Column("name_or_id",
verbose_name=_("Name"),
link='horizon:project:networks:detail')
subnets = tables.Column(get_subnets,

View File

@ -51,8 +51,6 @@ class IndexView(tables.DataTableView):
networks = []
msg = _('Network list can not be retrieved.')
exceptions.handle(self.request, msg)
for n in networks:
n.set_id_as_name_if_empty()
return networks
@ -106,8 +104,6 @@ class DetailView(tables.MultiTableView):
subnets = []
msg = _('Subnet list can not be retrieved.')
exceptions.handle(self.request, msg)
for s in subnets:
s.set_id_as_name_if_empty()
return subnets
def get_ports_data(self):
@ -118,8 +114,6 @@ class DetailView(tables.MultiTableView):
ports = []
msg = _('Port list can not be retrieved.')
exceptions.handle(self.request, msg)
for p in ports:
p.set_id_as_name_if_empty()
return ports
@memoized.memoized_method

View File

@ -357,9 +357,9 @@ class CreateNetwork(workflows.Workflow):
if api.neutron.is_port_profiles_supported():
params['net_profile_id'] = data['net_profile_id']
network = api.neutron.network_create(request, **params)
network.set_id_as_name_if_empty()
self.context['net_id'] = network.id
msg = _('Network "%s" was successfully created.') % network.name
msg = (_('Network "%s" was successfully created.') %
network.name_or_id)
LOG.debug(msg)
return network
except Exception as e:

View File

@ -85,12 +85,10 @@ class RulesGridTab(tabs.Tab):
ports = self.tab_group.ports
networks = api.neutron.network_list_for_tenant(
self.request, self.request.user.tenant_id)
for n in networks:
n.set_id_as_name_if_empty()
netnamemap = {}
subnetmap = {}
for n in networks:
netnamemap[n['id']] = n['name']
netnamemap[n['id']] = n.name_or_id
for s in n.subnets:
subnetmap[s.id] = {'name': s.name,
'cidr': s.cidr}

View File

@ -97,7 +97,7 @@ DISPLAY_CHOICES = (
class PortsTable(tables.DataTable):
name = tables.Column("name",
name = tables.Column("name_or_id",
verbose_name=_("Name"),
link="horizon:project:networks:ports:detail")
fixed_ips = tables.Column(project_tables.get_fixed_ips,

View File

@ -30,8 +30,6 @@ class InterfacesTab(tabs.TableTab):
def get_interfaces_data(self):
ports = self.tab_group.ports
for p in ports:
p.set_id_as_name_if_empty()
return ports

View File

@ -53,7 +53,7 @@ class IndexView(tables.DataTableView):
ext_net_dict = self._list_external_networks()
for r in routers:
r.set_id_as_name_if_empty()
r.name = r.name_or_id
self._set_external_network(r, ext_net_dict)
return routers
@ -66,9 +66,8 @@ class IndexView(tables.DataTableView):
search_opts = {'router:external': True}
ext_nets = api.neutron.network_list(self.request,
**search_opts)
for ext_net in ext_nets:
ext_net.set_id_as_name_if_empty()
ext_net_dict = SortedDict((n['id'], n.name) for n in ext_nets)
ext_net_dict = SortedDict((n['id'], n.name_or_id)
for n in ext_nets)
except Exception as e:
msg = _('Unable to retrieve a list of external networks "%s".') % e
exceptions.handle(self.request, msg)

View File

@ -227,7 +227,7 @@ class IPSecSiteConnectionsTable(tables.DataTable):
("Error", False),
)
id = tables.Column('id', hidden=True)
name = tables.Column('name', verbose_name=_('Name'),
name = tables.Column('name_or_id', verbose_name=_('Name'),
link="horizon:project:vpn:ipsecsiteconnectiondetails")
vpnservice_name = tables.Column('vpnservice_name',
verbose_name=_('VPN Service'))
@ -257,7 +257,7 @@ class VPNServicesTable(tables.DataTable):
("Error", False),
)
id = tables.Column('id', hidden=True)
name = tables.Column("name", verbose_name=_('Name'),
name = tables.Column("name_or_id", verbose_name=_('Name'),
link="horizon:project:vpn:vpnservicedetails")
description = tables.Column('description', verbose_name=_('Description'))
subnet_name = tables.Column('subnet_name', verbose_name=_('Subnet'))
@ -277,7 +277,7 @@ class VPNServicesTable(tables.DataTable):
class IKEPoliciesTable(tables.DataTable):
id = tables.Column('id', hidden=True)
name = tables.Column("name", verbose_name=_('Name'),
name = tables.Column("name_or_id", verbose_name=_('Name'),
link="horizon:project:vpn:ikepolicydetails")
auth_algorithm = tables.Column('auth_algorithm',
verbose_name=_('Authorization algorithm'))
@ -295,7 +295,7 @@ class IKEPoliciesTable(tables.DataTable):
class IPSecPoliciesTable(tables.DataTable):
id = tables.Column('id', hidden=True)
name = tables.Column("name", verbose_name=_('Name'),
name = tables.Column("name_or_id", verbose_name=_('Name'),
link="horizon:project:vpn:ipsecpolicydetails")
auth_algorithm = tables.Column('auth_algorithm',
verbose_name=_('Authorization algorithm'))

View File

@ -38,8 +38,6 @@ class IPSecSiteConnectionsTab(tabs.TableTab):
exceptions.handle(
self.tab_group.request,
_('Unable to retrieve IPSec Site Connections list.'))
for c in ipsecsiteconnections:
c.set_id_as_name_if_empty()
return ipsecsiteconnections
@ -58,8 +56,6 @@ class VPNServicesTab(tabs.TableTab):
vpnservices = []
exceptions.handle(self.tab_group.request,
_('Unable to retrieve VPN Services list.'))
for s in vpnservices:
s.set_id_as_name_if_empty()
return vpnservices
@ -78,8 +74,6 @@ class IKEPoliciesTab(tabs.TableTab):
ikepolicies = []
exceptions.handle(self.tab_group.request,
_('Unable to retrieve IKE Policies list.'))
for p in ikepolicies:
p.set_id_as_name_if_empty()
return ikepolicies
@ -98,8 +92,6 @@ class IPSecPoliciesTab(tabs.TableTab):
ipsecpolicies = []
exceptions.handle(self.tab_group.request,
_('Unable to retrieve IPSec Policies list.'))
for p in ipsecpolicies:
p.set_id_as_name_if_empty()
return ipsecpolicies