예제 #1
0
 def _get_network(self, network_id):
     network_dict = self.client.show_network(network_id)['network']
     network = DictModel(network_dict)
     network.external = network_dict.get('router:external')
     obj_subnet = [self._get_subnet(s_id) for s_id in network.subnets]
     network.subnets = obj_subnet
     return network
예제 #2
0
 def _get_network(self, network_id):
     network_dict = self.client.show_network(network_id)['network']
     network = DictModel(network_dict)
     network.external = network_dict.get('router:external')
     obj_subnet = [self._get_subnet(s_id) for s_id in network.subnets]
     network.subnets = obj_subnet
     return network
예제 #3
0
 def _create_port(self, network):
     body = dict(port=dict(
         admin_state_up=True,
         network_id=network.id,
         device_id='%s' % socket.gethostname(),
         device_owner=DEVICE_OWNER_PROBE,
         tenant_id=network.tenant_id,
         fixed_ips=[dict(subnet_id=s.id) for s in network.subnets]))
     port_dict = self.client.create_port(body)['port']
     port = DictModel(port_dict)
     port.network = network
     for fixed_ip in port.fixed_ips:
         fixed_ip.subnet = self._get_subnet(fixed_ip.subnet_id)
     return port
예제 #4
0
 def _create_port(self, network, device_owner):
     body = dict(port=dict(
         admin_state_up=True,
         network_id=network.id,
         device_id='%s' % socket.gethostname(),
         device_owner='%s:probe' % device_owner,
         tenant_id=network.tenant_id,
         fixed_ips=[dict(subnet_id=s.id) for s in network.subnets]))
     port_dict = self.client.create_port(body)['port']
     port = DictModel(port_dict)
     port.network = network
     for fixed_ip in port.fixed_ips:
         fixed_ip.subnet = self._get_subnet(fixed_ip.subnet_id)
     return port
예제 #5
0
 def list_probes(self):
     ports = self.client.list_ports(
         device_owner=[DEVICE_OWNER_NETWORK_PROBE,
                       DEVICE_OWNER_COMPUTE_PROBE])
     info = ports['ports']
     for port in info:
         port['device_name'] = self.driver.get_device_name(DictModel(port))
     return info
예제 #6
0
 def ensure_probe(self, network_id):
     ports = self.client.list_ports(network_id=network_id,
                                    device_id=socket.gethostname(),
                                    device_owner=DEVICE_OWNER_NETWORK_PROBE)
     info = ports.get('ports', [])
     if info:
         return DictModel(info[0])
     else:
         return self.create_probe(network_id)
예제 #7
0
 def exec_command(self, port_id, command=None):
     port = DictModel(self.client.show_port(port_id)['port'])
     ip = ip_lib.IPWrapper(self.root_helper)
     namespace = self._get_namespace(port)
     if self.conf.use_namespaces:
         if not command:
             return "sudo ip netns exec %s" % self._get_namespace(port)
         namespace = ip.ensure_namespace(namespace)
         return namespace.netns.execute(shlex.split(command))
     else:
         return utils.execute(shlex.split(command))
예제 #8
0
 def delete_probe(self, port_id):
     port = DictModel(self.client.show_port(port_id)['port'])
     ip = ip_lib.IPWrapper(self.conf.root_helper)
     namespace = self._get_namespace(port)
     if self.conf.use_namespaces and ip.netns.exists(namespace):
         self.driver.unplug(self.driver.get_device_name(port),
                            namespace=namespace)
         ip.netns.delete(namespace)
     else:
         self.driver.unplug(self.driver.get_device_name(port))
     self.client.delete_port(port.id)
예제 #9
0
 def delete_probe(self, port_id):
     port = DictModel(self.client.show_port(port_id)['port'])
     network = self._get_network(port.network_id)
     bridge = None
     if network.external:
         bridge = self.conf.external_network_bridge
     ip = ip_lib.IPWrapper(self.root_helper)
     namespace = self._get_namespace(port)
     if self.conf.use_namespaces and ip.netns.exists(namespace):
         self.driver.unplug(self.driver.get_device_name(port),
                            bridge=bridge,
                            namespace=namespace)
         try:
             ip.netns.delete(namespace)
         except:
             LOG.warn(_('Failed to delete namespace %s'), namespace)
     else:
         self.driver.unplug(self.driver.get_device_name(port),
                            bridge=bridge)
     self.client.delete_port(port.id)
예제 #10
0
 def _get_network(self, network_id):
     network_dict = self.client.show_network(network_id)['network']
     network = DictModel(network_dict)
     obj_subnet = [self._get_subnet(s_id) for s_id in network.subnets]
     network.subnets = obj_subnet
     return network
예제 #11
0
 def _get_subnet(self, subnet_id):
     subnet_dict = self.client.show_subnet(subnet_id)['subnet']
     return DictModel(subnet_dict)
예제 #12
0
 def _get_network(self, network_id):
     network_dict = self.client.show_network(network_id)['network']
     network = DictModel(network_dict)
     obj_subnet = [self._get_subnet(s_id) for s_id in network.subnets]
     network.subnets = obj_subnet
     return network