- def __init__(self, config=None, cidr=None, ip_version=4, name=None, project_name=None, start=None,
- end=None, gateway_ip=None, enable_dhcp=None, dns_nameservers=None, host_routes=None, destination=None,
- nexthop=None, ipv6_ra_mode=None, ipv6_address_mode=None):
- """
- Constructor - all parameters are optional except cidr (subnet mask)
- :param config: Should be a dict object containing the configuration settings using the attribute names below
- as each member's the key and overrides any of the other parameters.
- :param cidr: The CIDR. REQUIRED if config parameter is None
- :param ip_version: The IP version, which is 4 or 6.
- :param name: The subnet name.
- :param project_name: The name of the project who owns the network. Only administrative users can specify a
- project ID other than their own. You cannot change this value through authorization
- policies.
- :param start: The start address for the allocation pools.
- :param end: The end address for the allocation pools.
- :param gateway_ip: The gateway IP address.
- :param enable_dhcp: Set to true if DHCP is enabled and false if DHCP is disabled.
- :param dns_nameservers: A list of DNS name servers for the subnet. Specify each name server as an IP address
- and separate multiple entries with a space. For example [8.8.8.7 8.8.8.8].
- :param host_routes: A list of host route dictionaries for the subnet. For example:
- "host_routes":[
- {
- "destination":"0.0.0.0/0",
- "nexthop":"123.456.78.9"
- },
- {
- "destination":"192.168.0.0/24",
- "nexthop":"192.168.0.1"
- }
- ]
- :param destination: The destination for static route
- :param nexthop: The next hop for the destination.
- :param ipv6_ra_mode: A valid value is dhcpv6-stateful, dhcpv6-stateless, or slaac.
- :param ipv6_address_mode: A valid value is dhcpv6-stateful, dhcpv6-stateless, or slaac.
- :raise: Exception when config does not have or cidr values are None
- """
- if not dns_nameservers:
- dns_nameservers = ['8.8.8.8']
-
- if config:
- self.cidr = config['cidr']
- if config.get('ip_version'):
- self.ip_version = config['ip_version']
- else:
- self.ip_version = ip_version
-
- # Optional attributes that can be set after instantiation
- self.name = config.get('name')
- self.project_name = config.get('project_name')
- self.start = config.get('start')
- self.end = config.get('end')
- self.gateway_ip = config.get('gateway_ip')
- self.enable_dhcp = config.get('enable_dhcp')
-
- if config.get('dns_nameservers'):
- self.dns_nameservers = config.get('dns_nameservers')
- else:
- self.dns_nameservers = dns_nameservers
-
- self.host_routes = config.get('host_routes')
- self.destination = config.get('destination')
- self.nexthop = config.get('nexthop')
- self.ipv6_ra_mode = config.get('ipv6_ra_mode')
- self.ipv6_address_mode = config.get('ipv6_address_mode')
- else:
- # Required attributes
- self.cidr = cidr
- self.ip_version = ip_version
-
- # Optional attributes that can be set after instantiation
- self.name = name
- self.project_name = project_name
- self.start = start
- self.end = end
- self.gateway_ip = gateway_ip
- self.enable_dhcp = enable_dhcp
- self.dns_nameservers = dns_nameservers
- self.host_routes = host_routes
- self.destination = destination
- self.nexthop = nexthop
- self.ipv6_ra_mode = ipv6_ra_mode
- self.ipv6_address_mode = ipv6_address_mode