diff options
author | 2015-10-05 16:23:54 -0700 | |
---|---|---|
committer | 2015-10-12 18:07:52 +0000 | |
commit | 20c9887e8bb7a31be0c8414d0f240bd8bc831688 (patch) | |
tree | fb5b5718bbe2c57ecf8b7bf4dd6f1200411fcf01 /os_net_config/objects.py | |
parent | d01acefc15cebcfc5b7d808d3ed4f41cbaf8d74d (diff) |
Fix kwarg assignment in objects.py
This change modifies the kwargs in the object instantiation to
use immutable default assignments. This is for object safety,
since a mutable object will not point to a new memory address
on modification. In Python, lists and dicts should not be used
as default assignments for kwargs.
Change-Id: I73993df12ca317161ba32e02a98a5f40ef8904f3
Diffstat (limited to 'os_net_config/objects.py')
-rw-r--r-- | os_net_config/objects.py | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/os_net_config/objects.py b/os_net_config/objects.py index ad42ce2..a8869ef 100644 --- a/os_net_config/objects.py +++ b/os_net_config/objects.py @@ -132,10 +132,13 @@ class Address(object): class _BaseOpts(object): """Base abstraction for logical port options.""" - def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=[], - routes=[], mtu=1500, primary=False, nic_mapping=None, + def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None, + routes=None, mtu=1500, primary=False, nic_mapping=None, persist_mapping=False, defroute=True, dhclient_args=None, - dns_servers=[]): + dns_servers=None): + addresses = addresses or [] + routes = routes or [] + dns_servers = dns_servers or [] numbered_nic_names = _numbered_nics(nic_mapping) self.hwaddr = None self.hwname = None @@ -231,10 +234,13 @@ class _BaseOpts(object): class Interface(_BaseOpts): """Base class for network interfaces.""" - def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=[], - routes=[], mtu=1500, primary=False, nic_mapping=None, + def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None, + routes=None, mtu=1500, primary=False, nic_mapping=None, persist_mapping=False, defroute=True, dhclient_args=None, - dns_servers=[]): + dns_servers=None): + addresses = addresses or [] + routes = routes or [] + dns_servers = dns_servers or [] super(Interface, self).__init__(name, use_dhcp, use_dhcpv6, addresses, routes, mtu, primary, nic_mapping, persist_mapping, defroute, @@ -255,9 +261,12 @@ class Vlan(_BaseOpts): """ def __init__(self, device, vlan_id, use_dhcp=False, use_dhcpv6=False, - addresses=[], routes=[], mtu=1500, primary=False, + addresses=None, routes=None, mtu=1500, primary=False, nic_mapping=None, persist_mapping=False, defroute=True, - dhclient_args=None, dns_servers=[]): + dhclient_args=None, dns_servers=None): + addresses = addresses or [] + routes = routes or [] + dns_servers = dns_servers or [] name = 'vlan%i' % vlan_id super(Vlan, self).__init__(name, use_dhcp, use_dhcpv6, addresses, routes, mtu, primary, nic_mapping, @@ -283,10 +292,15 @@ class Vlan(_BaseOpts): class OvsBridge(_BaseOpts): """Base class for OVS bridges.""" - def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=[], - routes=[], mtu=1500, members=[], ovs_options=None, - ovs_extra=[], nic_mapping=None, persist_mapping=False, - defroute=True, dhclient_args=None, dns_servers=[]): + def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None, + routes=None, mtu=1500, members=None, ovs_options=None, + ovs_extra=None, nic_mapping=None, persist_mapping=False, + defroute=True, dhclient_args=None, dns_servers=None): + addresses = addresses or [] + routes = routes or [] + members = members or [] + ovs_extra = ovs_extra or [] + dns_servers = dns_servers or [] super(OvsBridge, self).__init__(name, use_dhcp, use_dhcpv6, addresses, routes, mtu, False, nic_mapping, persist_mapping, defroute, @@ -448,11 +462,16 @@ class LinuxBond(_BaseOpts): class OvsBond(_BaseOpts): """Base class for OVS bonds.""" - def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=[], - routes=[], mtu=1500, primary=False, members=[], - ovs_options=None, ovs_extra=[], nic_mapping=None, + def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None, + routes=None, mtu=1500, primary=False, members=None, + ovs_options=None, ovs_extra=None, nic_mapping=None, persist_mapping=False, defroute=True, dhclient_args=None, - dns_servers=[]): + dns_servers=None): + addresses = addresses or [] + routes = routes or [] + members = members or [] + ovs_extra = ovs_extra or [] + dns_servers = dns_servers or [] super(OvsBond, self).__init__(name, use_dhcp, use_dhcpv6, addresses, routes, mtu, primary, nic_mapping, persist_mapping, defroute, dhclient_args, |