Example #1
0
def delete_ip_from_interface(fip):
    ip = ip_lib.IPWrapper()
    dev = ip.get_device_by_ip(fip)
    if dev is not None:
        dev.addr.delete(fip)
        return True
    return False
 def __init__(self, vm_uuid, nic_left, nic_right, other_nics=None,
              root_helper='sudo', cfg_file=None, update=False,
              pool_id=None, gw_ip=None, namespace_name=None):
     self.vm_uuid = vm_uuid
     if namespace_name is None:
         self.namespace = self.NETNS_PREFIX + self.vm_uuid
     else:
         self.namespace = namespace_name
     if pool_id:
         self.namespace = self.namespace + ":" + pool_id
     self.nic_left = nic_left
     self.nic_right = nic_right
     self.root_helper = root_helper
     self.nics = other_nics or []
     if self.nic_left:
         self.nic_left['name'] = (self.LEFT_DEV_PREFIX +
                              self.nic_left['uuid'])[:self.DEV_NAME_LEN]
         self.nics.append(self.nic_left)
     if self.nic_right:
         self.nic_right['name'] = (self.RIGH_DEV_PREFIX +
                                   self.nic_right['uuid'])[:self.DEV_NAME_LEN]
         self.nics.append(self.nic_right)
     self.ip_ns = ip_lib.IPWrapper(root_helper=self.root_helper,
                                   namespace=self.namespace)
     self.vrouter_client = ContrailVRouterApi()
     self.cfg_file = cfg_file
     self.update = update
     self.gw_ip = gw_ip
Example #3
0
def add_ip_to_interface(fip):
    ip = ip_lib.IPWrapper()
    devices = ip.get_devices()
    for dev in devices:
        if dev.route.get_gateway() is not None:
            if ip.get_device_by_ip(fip) is None:
                dev.addr.add(fip)
                return True
    return False
Example #4
0
    def enable(self, cmd_callback=None, reload_cfg=False):
        if not self.active:
            if not cmd_callback:
                cmd_callback = self.default_cmd_callback
            cmd = cmd_callback(self.get_pid_file_name())

            ip_wrapper = ip_lib.IPWrapper(namespace=self.namespace)
            ip_wrapper.netns.execute(cmd,
                                     addl_env=self.cmd_addl_env,
                                     run_as_root=self.run_as_root)
        elif reload_cfg:
            self.reload_cfg()
Example #5
0
    def disable(self, sig='9', get_stop_command=None):
        pid = self.pid

        if self.active:
            if get_stop_command:
                cmd = get_stop_command(self.get_pid_file_name())
                ip_wrapper = ip_lib.IPWrapper(namespace=self.namespace)
                ip_wrapper.netns.execute(cmd, addl_env=self.cmd_addl_env)
            else:
                cmd = ['kill', '-%s' % (sig), pid]
                utils.execute(cmd, run_as_root=True)
                # In the case of shutting down, remove the pid file
                if sig == '9':
                    fileutils.delete_if_exists(self.get_pid_file_name())
        elif pid:
            LOG.debug(
                'Process for %(uuid)s pid %(pid)d is stale, ignoring '
                'signal %(signal)s', {
                    'uuid': self.uuid,
                    'pid': pid,
                    'signal': sig
                })
        else:
            LOG.debug('No process started for %s', self.uuid)
Example #6
0
 def _brctl(self, cmd):
     cmd = ['brctl'] + cmd
     ip_wrapper = ip_lib.IPWrapper(self.namespace)
     return ip_wrapper.netns.execute(cmd, run_as_root=True)