Exemple #1
0
    def _check_interfaces(self, interfaces_path):
        """Uses ifup to check interfaces file. If it is not in the
        default place, each interface must be checked one by one.
            Args:
                interfaces_path (string) : the path to interfaces file

            Raises:
                ValueError : if invalid network interfaces
        """
        if interfaces_path == "/etc/network/interfaces":
            ret, output = toolutils.safe_subprocess(["ifup", "-a", "--no-act"])
        else:
            for adapter in self._adapters:
                ret, output = toolutils.safe_subprocess([
                    "ifup", "--no-act",
                    "--interfaces={0}".format(interfaces_path),
                    adapter.attributes["name"]
                ])
                if not ret:
                    break
        if not ret:
            raise ValueError("Invalid network interfaces file "
                             "written to disk, restoring to previous "
                             "one : {0}".format(output))
Exemple #2
0
    def delete(self):
        ''' return True/False, command output '''

        if self.backup_path:
            return toolutils.safe_subprocess(["rm", self._path])
Exemple #3
0
    def restore(self):
        ''' return True/False, command output '''

        if self.backup_path:
            return toolutils.safe_subprocess(["cp", self.backup_path, self._path])
Exemple #4
0
    def controlService(self, action):
        ''' return True/False, command output '''

        if action not in ["start", "stop", "restart"]:
            return False, "Invalid action"
        return toolutils.safe_subprocess(["/etc/init.d/dnsmasq", action])
Exemple #5
0
    def downAdapter(self, if_name):
        ''' return True/False, command output. Use ifdown. '''

        return toolutils.safe_subprocess(["ifconfig", if_name, 'down'])
Exemple #6
0
    def controlService(self, action):
        """ return True/False, command output """

        if action not in ["start", "stop", "restart"]:
            return False, "Invalid action"
        return toolutils.safe_subprocess(["/etc/init.d/dnsmasq", action])
Exemple #7
0
    def upAdapter(self, if_name):
        ''' return True/False, command output. Use ifconfig. '''

        return toolutils.safe_subprocess(["ifconfig", if_name, 'up'])
Exemple #8
0
    def restore(self):
        ''' return True/False, command output '''

        if self.backup_path:
            return toolutils.safe_subprocess(
                ["cp", self.backup_path, self._path])
Exemple #9
0
    def delete(self):
        ''' return True/False, command output '''

        if self.backup_path:
            return toolutils.safe_subprocess(["rm", self._path])
    def _restore_interfaces(self):
        """ return True/False, command output """

        if self._backup_path:
            return toolutils.safe_subprocess(["cp", self._backup_path, self._interfaces_path])
Exemple #11
0
    def _restore_interfaces(self):
        ''' return True/False, command output '''

        if self._backup_path:
            return toolutils.safe_subprocess(
                ["cp", self._backup_path, self._interfaces_path])
Exemple #12
0
    def backup(self):
        """ return True/False, command output """

        if self.backup_path:
            return toolutils.safe_subprocess(["cp", self._path, self.backup_path])
Exemple #13
0
    def downAdapter(self, if_name):
        """ return True/False, command output. Use ifdown. """

        return toolutils.safe_subprocess(["/sbin/ifdown", if_name])
Exemple #14
0
    def downAdapter(self, if_name):
        """ return True/False, command output. Use ifdown. """

        return toolutils.safe_subprocess(["/sbin/ifdown", if_name])