def _up(self, ifaceobj): """ Up the PPP connection """ provider = ifaceobj.get_attr_value_first('provider') old_config = None old_provider = None try: ppp_file = os.path.join('/etc/ppp/peers', provider) if not os.path.isfile(ppp_file): self.log_warn('Invalid ppp provider file does not exist') return # Load state data saved_ifaceobjs = statemanager.statemanager_api.get_ifaceobjs( ifaceobj.name) if saved_ifaceobjs: old_provider = saved_ifaceobjs[0].get_attr_value_first( 'provider') old_config = saved_ifaceobjs[0].get_attr_value_first( 'provider_file') config = hashlib.sha256(open(ppp_file, 'rb').read()).hexdigest() # Always save the current config files hash ifaceobj.update_config('provider_file', config) if not self.cache.link_exists(ifaceobj.name): try: # This fails if not running utils.exec_user_command( '/bin/ps ax | /bin/grep pppd | /bin/grep -v grep | /bin/grep ' + provider) except Exception: utils.exec_commandl(['/usr/bin/pon', provider], stdout=None, stderr=None) if old_config and old_config != config: # Restart on config change utils.exec_commandl(['/usr/bin/poff', provider], stdout=None, stderr=None) utils.exec_commandl(['/usr/bin/pon', provider], stdout=None, stderr=None) elif old_provider and old_provider != provider: # Restart on provider change utils.exec_commandl(['/usr/bin/poff', old_provider], stdout=None, stderr=None) utils.exec_commandl(['/usr/bin/pon', provider], stdout=None, stderr=None) except Exception as e: self.log_warn(str(e))
def _down(self, ifaceobj): """ Down the PPP connection """ try: provider = ifaceobj.get_attr_value_first('provider') # This fails if not running utils.exec_user_command( '/bin/ps ax | /bin/grep pppd | /bin/grep -v grep | /bin/grep ' + provider) utils.exec_commandl(['/usr/bin/poff', provider], stdout=None, stderr=None) except Exception as e: self.log_warn(str(e))
def _run_command(self, ifaceobj, op): cmd_list = ifaceobj.get_attr_value(op) if cmd_list: os.environ['IFACE'] = ifaceobj.name if ifaceobj.name else '' os.environ['LOGICAL'] = ifaceobj.name if ifaceobj.name else '' os.environ['METHOD'] = ifaceobj.addr_method if ifaceobj.addr_method else '' os.environ['ADDRFAM'] = ','.join(ifaceobj.addr_family) if ifaceobj.addr_family else '' for cmd in cmd_list: try: utils.exec_user_command(cmd) except Exception, e: if not self.ignore_error(str(e)): self.logger.warn('%s: %s %s' % (ifaceobj.name, op, str(e).strip('\n'))) pass
def _run_command(self, ifaceobj, op): cmd_list = ifaceobj.get_attr_value(op) if cmd_list: os.environ['IFACE'] = ifaceobj.name if ifaceobj.name else '' os.environ['LOGICAL'] = ifaceobj.name if ifaceobj.name else '' os.environ[ 'METHOD'] = ifaceobj.addr_method if ifaceobj.addr_method else '' os.environ['ADDRFAM'] = ','.join( ifaceobj.addr_family) if ifaceobj.addr_family else '' for cmd in cmd_list: try: utils.exec_user_command(cmd) except Exception, e: if not self.ignore_error(str(e)): self.logger.warn( '%s: %s %s' % (ifaceobj.name, op, str(e).strip('\n'))) pass
def _ovs_vsctl(self, ifaceobj, cmdlist): if cmdlist: os.environ['IFACE'] = ifaceobj.name if ifaceobj.name else '' os.environ['LOGICAL'] = ifaceobj.name if ifaceobj.name else '' os.environ['METHOD'] = ifaceobj.addr_method if ifaceobj.addr_method else '' os.environ['ADDRFAM'] = ','.join(ifaceobj.addr_family) if ifaceobj.addr_family else '' finalcmd = "/usr/bin/ovs-vsctl" for cmd in cmdlist: finalcmd = finalcmd + " -- " + cmd try: self.logger.debug ("Running %s" % (finalcmd)) utils.exec_user_command(finalcmd) except subprocess.CalledProcessError as c: raise Exception ("Command \"%s failed: %s" % (finalcmd, c.output)) except Exception as e: raise Exception ("%s" % e)
def _run_command(self, ifaceobj, op): cmd_list = ifaceobj.get_attr_value(op) if cmd_list: env = dict(os.environ) env.update({ 'LOGICAL': ifaceobj.name if ifaceobj.name else '', 'METHOD': ifaceobj.addr_method if ifaceobj.addr_method else '', 'ADDRFAM': ','.join(ifaceobj.addr_family) if ifaceobj.addr_family else '' }) env.update(ifaceobj.get_env()) for cmd in cmd_list: try: utils.exec_user_command(cmd, env=env) except Exception as e: if not self.ignore_error(str(e)): self.logger.warning( '%s: %s %s' % (ifaceobj.name, op, str(e).strip('\n'))) pass