Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 3
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
Ejemplo n.º 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
Ejemplo n.º 5
0
 def _create_port(self, network, device_owner):
     host = self.conf.host
     body = {'port': {'admin_state_up': True,
                      'network_id': network.id,
                      'device_id': '%s' % socket.gethostname(),
                      'device_owner': '%s:probe' % device_owner,
                      'tenant_id': network.tenant_id,
                      'binding:host_id': host,
                      '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
Ejemplo n.º 6
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
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
 def _create_port(self, network, device_owner):
     host = self.conf.host
     body = {
         'port': {
             'admin_state_up': True,
             'network_id': network.id,
             'device_id': '%s' % socket.gethostname(),
             'device_owner': '%s:probe' % device_owner,
             'tenant_id': network.tenant_id,
             'binding:host_id': host,
             '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
Ejemplo n.º 9
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))
Ejemplo n.º 10
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 Exception:
             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)
Ejemplo n.º 11
0
 def _get_subnet(self, subnet_id):
     subnet_dict = self.client.show_subnet(subnet_id)['subnet']
     return DictModel(subnet_dict)