示例#1
0
 def manageService(self, services, service_action, pkg_dps, host):
     try:
         for service in services:
             # check if package dependencies are already installed. If not, install them now
             if service_action == 'start' or 'restart':
                 p = Packages()
                 pkgs_to_install = []
                 print("\n\n*** Checking dependencies...")
                 for pkg in pkg_dps:
                     if p.check_if_package_installed(pkg, host):
                         pass
                     else:
                         pkgs_to_install.append(pkg)
                 p.install_package(host, pkgs_to_install)
             if service_action == 'stop':
                 pass
             print("\n\n*** {}ing {} service on {}".format(service_action, service, host))
                 
             cmd = "service {} {}".format(service, service_action)
             c = SshConnection()
             output, error = c.run_command(cmd, host)
             if error == []:
                 for o in output:
                     print(o.strip('\n'))
             else:
                 raise Exception(error[0])
     except Exception as e:
         print(e)
示例#2
0
try:
    c = SshConnection()
    s = Service()
    for host in hosts:
        if commands:
            for command in commands:
                output, error = c.run_command(command, host)
                if error != []:
                    raise Exception(error[0])
                else:
                    print("\n*** Output of '{}' on '{}'".format(command, host))
                for o in output:
                    print(o.strip('\n'))
        elif install_pkgs:
            p = Packages()
            p.install_package(host, install_pkgs)
            s = Service()
            s.manageService(pkg_service_deps, 'restart', service_pkg_deps, host)
        elif uninstall_pkgs:
            p = Packages()
            p.uninstall_package(host, uninstall_pkgs)
        elif upgrade_pkgs:
            p = Packages()
            p.upgrade_package(host, upgrade_pkgs)
        elif file_data and file_metadata:
            f = File()
            f.create_file(host, file_data, file_metadata)
        elif not file_data and file_metadata:
            f = File()
            f.delete_file(host, file_metadata)
        elif services: