Package: python-rrmngmnt
Remote Resources MaNaGeMeNTIntroThis tool helps you manage remote machines and services running on that.
It is targeted to Linux based machines. All is done via SSH connection,
that means SSH server must be running there already.fromrrmngmntimportHost,RootUserh=Host("10.11.12.13")h.users.append(RootUser('123456'))exec=h.executor()# Run with sudoexec=h.executor(sudo=True)printexec.run_cmd(['echo','Hello World'])Using SSH key for authenticationfromrrmngmntimportHost,UserWithPKeyh=Host("10.11.12.13")user=UserWithPKey('user','/path/to/pkey'))h.executor(user).run_cmd(['echo','Use pkey for auth instead of password'])Using SSH key with disabled algorithms on paramiko SSHClient connect (Used when connecting to machines using old SSH)fromrrmngmntimportHost,UserWithPKey,RemoteExecutorFactoryh=Host("10.11.12.13")h.executor_factory=RemoteExecutorFactory(disabled_algorithms=dict(pubkeys=['rsa-sha2-256','rsa-sha2-512'])user=UserWithPKey('user','/path/to/pkey'))h.executor(user).run_cmd(['echo','Use pkey and disabled algorithms for old openSSH connection'])Using with SSH ProxyCommand
.. code:: pythonproxy_command = ‘some proxy command’
h = Host(hostname=”hostname”)
host.executor_factory = ssh.RemoteExecutorFactory(sock=proxy_command)
h.executor(user).run_cmd([‘echo’, ‘Use SSH with ProxyCommand’])FeaturesList of provided interfaces to manage resources on machine, and
examples.FilesystemBasic file operations, you can find there subset of python ‘os’ module
related to files.printh.fs.exists("/path/to/file")h.fs.chown("/path/to/file","root","root")h.fs.chmod("/path/to/file","644")h.fs.unlink("/path/to/file")In additional there are methods to fetch / put file from / to remote system
to / from local system.h.fs.get("/path/to/remote/file","/path/to/local/file/or/target/dir")h.fs.put("/path/to/local/file","/path/to/remote/file/or/target/dir")There is one special method which allows transfer file between hosts.h1.fs.transfer("/path/to/file/on/h1",h2,"/path/to/file/on/h2/or/target/dir",)You can also mount devices.withh.fs.mount_point('//example.com/share',opts='ro,guest',fstype='cifs',target='/mnt/netdisk')asmp:h.fs.listdir(mp.target)# list mounted directorymp.remount('rw,sync,guest')# remount with different optionsh.fs.touch('%s/new_file'%mp.target)# touch fileFirewallAllows to manage firewall configurarion. Check which firewall service is
running on host (firewalld/iptables) and make configure this service.h.firewall.is_active('iptables')h.firewall.chain('OUTPUT').list_rules()h.firewall.chain('OUTPUT').add_rule('1.1.1.1','DROP')NetworkIt allows to manage network configuration.printh.network.hostnameh.network.hostname="my.machine.org"printh.network.all_interfaces()printh.network.list_bridges()Package ManagementIt encapsulates various package managements. It is able to determine
which package management to use. You can still specify package management
explicitly.Implemented managements:APTYUMDNFRPM# install htop package using implicit managementh.package_management.install('htop')# remove htop package using rpm explicitlyh.package_management('rpm').remove('htop')System ServicesYou can toggle system services, it encapsulates various service managements.
It is able to determine which service management to use in most cases.Implemented managements:SystemdSysVinitInitCtlifh.service('httpd').status():h.service('httpd').stop()ifh.service('httpd').is_enabled():h.service('httpd').disable()Operating System InfoHost provideosattribute which allows obtain basic operating
system info.
Note thatos.release_infodepends on systemd init system.printh.os.distribution# Distribution(distname='Fedora', version='23', id='Twenty Three')printh.os.release_info# {'HOME_URL': 'https://fedoraproject.org/',#  'ID': 'fedora',#  'NAME': 'Fedora',#  'PRETTY_NAME': 'Fedora 23 (Workstation Edition)',#  'VARIANT': 'Workstation Edition',#  'VARIANT_ID': 'workstation',#  'VERSION': '23 (Workstation Edition)',#  'VERSION_ID': '23',#  ...# }printh.os.release_str# Fedora release 23 (Twenty Three)Storage ManagementIt is in PROGRESS state. Planed are NFS & LVM services.Power ManagementGive you possibility to control host power state, you can restart,
poweron, poweroff host and get host power status.Implemented managements:SSHIPMIipmi_user=User(pm_user,pm_password)ipmi_params={'pm_if_type':'lan','pm_address':'test-mgmt.testdomain','user':ipmi_user}h.add_power_manager(power_manager.IPMI_TYPE,**ipmi_params)# restart host via ipmitoolh.power_manager.restart()RequiresparamikonetaddrsixInstallpythonsetup.pydevopTesttox