def add_ring_vir_link(self, ringnum1, sw_name1, ringnum2, sw_name2): ringnum1 = as_oneof(ringnum1, self.rings.keys(), valname='ringnum1', containername='ring numbers') ringnum2 = as_oneof(ringnum2, self.rings.keys(), valname='ringnum2', containername='ring numbers') sw_name1 = as_oneof(sw_name1, self.switches.keys(), valname='sw_name1', containername='switch names') sw_name2 = as_oneof(sw_name2, self.switches.keys(), valname='sw_name2', containername='switch names') ring1 = self.rings[ringnum1] if not any(s.name == sw_name1 for s in ring1.get_nodes()): raise ValueError('no switch named "{}" exists in ring {}'.format( sw_name1, ringnum1)) ring2 = self.rings[ringnum2] if not any(s.name == sw_name2 for s in ring2.get_nodes()): raise ValueError('no switch named "{}" exists in ring {}'.format( sw_name2, ringnum2)) port_cfg = RingPorts.ring_to_ring_vir() self.__add_switch_link(sw_name1, port_cfg, sw_name2, port_cfg)
def add_host_connection(self, src_h_name, dest_h_name): src_h_name = as_oneof(src_h_name, self.hosts.keys(), valname='src_h_name', containername='host names') dest_h_name = as_oneof(dest_h_name, self.hosts.keys(), valname='dest_h_name', containername='host names') if src_h_name != dest_h_name: src_conns = self.host_connections.setdefault(src_h_name, []) if dest_h_name not in src_conns: src_conns.append(dest_h_name)
def add_vir_collector_link(self, c_name, c_portnum, sw_name, sw_portnum): c_name = as_oneof(c_name, self.collectors.keys(), valname='c_name', containername='collector names') sw_name = as_oneof(sw_name, self.switches.keys(), valname='sw_name', containername='switch names') c_portnum = as_int(c_portnum, minim=0, name='c_portnum') sw_portnum = as_int(sw_portnum, minim=0, name='sw_portnum') c_port_cfg = NodeUtils.get_generic_vir_port_cfg(c_portnum) sw_port_cfg = NodeUtils.get_switch_to_collector_vir_port_cfg( sw_portnum) self.__add_collector_link(c_name, c_port_cfg, sw_name, sw_port_cfg)
def add_vir_switch_link(self, sw_name1, sw_portnum1, sw_name2, sw_portnum2): sw_name1 = as_oneof(sw_name1, self.switches.keys(), valname='sw_name1', containername='switch names') sw_name2 = as_oneof(sw_name2, self.switches.keys(), valname='sw_name2', containername='switch names') sw_portnum1 = as_int(sw_portnum1, minim=0, name='sw_portnum1') sw_portnum2 = as_int(sw_portnum2, minim=0, name='sw_portnum2') port_cfg1 = NodeUtils.get_generic_vir_port_cfg(sw_portnum1) port_cfg2 = NodeUtils.get_generic_vir_port_cfg(sw_portnum2) self.__add_switch_link(sw_name1, port_cfg1, sw_name2, port_cfg2)
def add_vir_host_link(self, h_name, h_portnum, h_port_ip, sw_name, sw_portnum): h_name = as_oneof(h_name, self.hosts.keys(), valname='h_name', containername='host names') sw_name = as_oneof(sw_name, self.switches.keys(), valname='sw_name', containername='switch names') h_portnum = as_int(h_portnum, minim=0, name='h_portnum') h_port_ip = as_str(h_port_ip, name='h_port_ip') sw_portnum = as_int(sw_portnum, minim=0, name='sw_portnum') h_port_cfg = NodeUtils.get_host_vir_port_cfg(h_portnum, h_port_ip) sw_port_cfg = NodeUtils.get_generic_vir_port_cfg(sw_portnum) self.__add_host_link(h_name, h_port_cfg, sw_name, sw_port_cfg)
def add_ring_remote_vir_host(self, h_name, user, server, h_portnum, h_port_ip, ringnum, sw_name, **params): h_name = some(h_name, name='h_name') h_portnum = as_int(h_portnum, minim=0, name='h_portnum') h_port_ip = as_str(h_port_ip, name='h_port_ip') ringnum = as_oneof(ringnum, self.rings.keys(), valname='ringnum', containername='ring numbers') sw_name = as_oneof(sw_name, self.switches.keys(), valname='sw_name', containername='switch names') ring = self.rings[ringnum] if not any(s.name == sw_name for s in ring.get_nodes()): raise ValueError('no switch named "{}" exists in ring {}'.format( sw_name, ringnum)) self.__add_remote_vir_host(h_name, user, server, **params) h_port_cfg = NodeUtils.get_host_vir_port_cfg(h_portnum, h_port_ip) sw_port_cfg = RingPorts.ring_to_host_vir() self.__add_host_link(h_name, h_port_cfg, sw_name, sw_port_cfg)
def add_phy_host_link(self, h_name, h_portname, h_portnum, h_port_ip, h_port_mac, sw_name, sw_portname, sw_portnum): h_name = as_oneof(h_name, self.hosts.keys(), valname='h_name', containername='host names') sw_name = as_oneof(sw_name, self.switches.keys(), valname='sw_name', containername='switch names') h_portname = as_str(h_portname, name='h_portname') h_portnum = as_int(h_portnum, minim=0, name='h_portnum') h_port_ip = as_str(h_port_ip, name='h_port_ip') h_port_mac = as_str(h_port_mac, name='h_port_mac') if is_some(h_port_mac) else None sw_portname = as_str(sw_portname, name='sw_portname') sw_portnum = as_int(sw_portnum, minim=0, name='sw_portnum') h_port_cfg = NodeUtils.get_host_phy_port_cfg(h_portname, h_portnum, h_port_ip, h_port_mac) sw_port_cfg = NodeUtils.get_generic_phy_port_cfg( sw_portname, sw_portnum) self.__add_host_link(h_name, h_port_cfg, sw_name, sw_port_cfg)
def add_ring_remote_vir_collector(self, c_name, user, server, varanus_home, cid, ringnum, **params): c_name = as_str(c_name, name='c_name') cid = as_int(cid, name='cid') ringnum = as_oneof(ringnum, self.rings.keys(), valname='ringnum', containername='ring numbers') ring = self.rings[ringnum] self.__add_remote_collector(c_name, user, server, varanus_home, cid, **params) c_port_num = 1 sw_port_cfg = RingPorts.ring_to_collector_vir() for sw in ring.get_nodes(): c_port_cfg = NodeUtils.get_generic_vir_port_cfg(c_port_num) self.__add_collector_link(c_name, c_port_cfg, sw.name, sw_port_cfg) c_port_num += 1
def add_ring_local_vir_collector(self, c_name, cid, ringnum, **params): varanus_home = self.local_varanus_home if not is_some(varanus_home): raise RuntimeError( 'VARANUS home is not defined, cannot add collector') c_name = as_str(c_name, name='c_name') cid = as_int(cid, name='cid') ringnum = as_oneof(ringnum, self.rings.keys(), valname='ringnum', containername='ring numbers') ring = self.rings[ringnum] self.__add_local_collector(c_name, varanus_home, cid, **params) c_port_num = 1 sw_port_cfg = RingPorts.ring_to_collector_vir() for sw in ring.get_nodes(): c_port_cfg = NodeUtils.get_generic_vir_port_cfg(c_port_num) self.__add_collector_link(c_name, c_port_cfg, sw.name, sw_port_cfg) c_port_num += 1
def as_valid_portnum(port, self): if isinstance(port, PortConfig): as_the(port.node, self) return port.num else: return as_oneof(as_int(port), self.ports)