diff options
Diffstat (limited to 'snaps/domain/network.py')
-rw-r--r-- | snaps/domain/network.py | 83 |
1 files changed, 77 insertions, 6 deletions
diff --git a/snaps/domain/network.py b/snaps/domain/network.py index 9cc1dd1..3d5e4af 100644 --- a/snaps/domain/network.py +++ b/snaps/domain/network.py @@ -22,19 +22,33 @@ class Network: def __init__(self, **kwargs): """ Constructor + :param name: the network's name + :param id: the network's ID + :param project_id: the associated project ID + :param admin_state_up: T/F - network is up when True + :param shared: T/F - network can be shared amongst other project's + :param external: T/F - network is deemed to be external + :param type: vlan, vxlan, flat, etc. + :param subnets: list of Subnet objects """ self.name = kwargs.get('name') self.id = kwargs.get('id') + self.project_id = kwargs.get('project_id') self.admin_state_up = kwargs.get('admin_state_up') self.shared = kwargs.get('shared') self.external = kwargs.get('router:external', kwargs.get('external')) self.type = kwargs.get('provider:network_type', kwargs.get('type')) + self.subnets = kwargs.get('subnets', list()) + self.mtu = kwargs.get('mtu') def __eq__(self, other): return (self.name == other.name and self.id == other.id and + self.project_id == other.project_id and self.admin_state_up == other.admin_state_up and self.shared == other.shared and - self.external == other.external and self.type == other.type) + self.external == other.external and + self.subnets == other.subnets and + self.mtu == other.mtu) class Subnet: @@ -45,9 +59,25 @@ class Subnet: def __init__(self, **kwargs): """ Constructor + :param name: the network's name + :param id: the subnet's ID + :param project_id: the associated project ID + :param network_id: the network's ID + :param cidr: the CIDR + :param ip_version: the IP version + :param gateway_ip: the IP of the gateway + :param enable_dhcp: T/F if DHCP is enabled + :param dns_nameservers: list of DNS server IPs + :param host_routes: routes as returned in a dict by Neutron + :param ipv6_ra_mode: IPv6 RA Mode + :param ipv6_address_mode: IPv6 Address Mode + :param start: start IP address pool + :param end: end IP address pool """ self.name = kwargs.get('name') self.id = kwargs.get('id') + self.project_id = kwargs.get('project_id') + self.network_id = kwargs.get('network_id') self.cidr = kwargs.get('cidr') self.ip_version = kwargs.get('ip_version') self.gateway_ip = kwargs.get('gateway_ip') @@ -71,6 +101,8 @@ class Subnet: def __eq__(self, other): return (self.name == other.name and self.id == other.id and + self.project_id == other.project_id and + self.network_id == other.network_id and self.cidr == other.cidr and self.ip_version == other.ip_version and self.gateway_ip == other.gateway_ip and @@ -134,20 +166,45 @@ class Router: Constructor :param name: the router's name :param id: the router's id + :param status: the router's status + :param tenant_id: the router's project/tenant ID + :param admin_state_up: Router is up when True + :param external_gateway_info: dict() for populating external_network_id + and external_fixed_ips + external_network_id: ID of the external network to route + in dict under key 'external_fixed_ips' + external_fixed_ips: List IP addresses associated with the + external_network_id found in dict under + key 'network_id' + :param port_subnets: list of tuples where #1 is the Port domain object + and #2 is a list of associated Subnet domain + objects """ self.name = kwargs.get('name') self.id = kwargs.get('id') self.status = kwargs.get('status') self.tenant_id = kwargs.get('tenant_id') self.admin_state_up = kwargs.get('admin_state_up') - self.external_gateway_info = kwargs.get('external_gateway_info') + self.port_subnets = kwargs.get('port_subnets') + + if (kwargs.get('external_gateway_info') and + isinstance(kwargs.get('external_gateway_info'), dict)): + gateway_info = kwargs.get('external_gateway_info') + + self.external_network_id = gateway_info.get('network_id') + self.external_fixed_ips = gateway_info.get('external_fixed_ips') + else: + self.external_fixed_ips = kwargs.get('external_fixed_ips', None) + self.external_network_id = kwargs.get('external_network_id', None) def __eq__(self, other): return (self.name == other.name and self.id == other.id and self.status == other.status and self.tenant_id == other.tenant_id and self.admin_state_up == other.admin_state_up and - self.external_gateway_info == other.external_gateway_info) + self.external_network_id == other.external_network_id and + self.external_fixed_ips == other.external_fixed_ips and + self.port_subnets == other.port_subnets) class InterfaceRouter: @@ -178,15 +235,29 @@ class SecurityGroup: Constructor :param name: the security group's name :param id: the security group's id + :param description: the security group's description + :param project_id: the security group's project_id + :param rules: list of SecurityGroupRule objects associated to this """ self.name = kwargs.get('name') self.id = kwargs.get('id') self.description = kwargs.get('description') self.project_id = kwargs.get('project_id', kwargs.get('tenant_id')) + self.rules = list() + if kwargs.get('rules') and isinstance(kwargs.get('rules'), list): + for rule in kwargs.get('rules'): + if isinstance(rule, SecurityGroupRule): + self.rules.append(rule) + else: + self.rules.append(SecurityGroupRule(**rule)) + def __eq__(self, other): - return (self.name == other.name and self.id == other.id and - self.project_id == other.project_id) + return (self.name == other.name and + self.id == other.id and + self.description == other.description and + self.project_id == other.project_id and + self.rules == other.rules) class SecurityGroupRule: @@ -198,7 +269,7 @@ class SecurityGroupRule: """ Constructor :param id: the security group rule's id - :param sec_grp_id: the ID of the associated security group + :param security_group_id: the ID of the associated security group :param description: the security group rule's description :param direction: the security group rule's direction :param ethertype: the security group rule's ethertype |