Esempio n. 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))
Esempio n. 2
0
    def delete(self):
        ''' return True/False, command output '''

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

        if self.backup_path:
            return toolutils.safe_subprocess(["cp", self.backup_path, self._path])
Esempio n. 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])
Esempio n. 5
0
    def downAdapter(self, if_name):
        ''' return True/False, command output. Use ifdown. '''

        return toolutils.safe_subprocess(["ifconfig", if_name, 'down'])
Esempio n. 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])
Esempio n. 7
0
    def upAdapter(self, if_name):
        ''' return True/False, command output. Use ifconfig. '''

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

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

        if self.backup_path:
            return toolutils.safe_subprocess(["rm", self._path])
Esempio n. 10
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])
Esempio n. 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])
Esempio n. 12
0
    def backup(self):
        """ return True/False, command output """

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

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

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