python-rrmngmnt


Namepython-rrmngmnt JSON
Version 0.1.32 PyPI version JSON
download
home_pagehttps://github.com/rhevm-qe-automation/python-rrmngmnt
SummaryTool to manage remote systems and services
upload_time2023-06-06 05:27:04
maintainer
docs_urlhttps://pythonhosted.org/python-rrmngmnt/
authorLukas Bednar
requires_python
licenseGPLv2
keywords remote resource service
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            python-rrmngmnt
===============

Remote Resources MaNaGeMeNT

Intro
-----

This 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.

.. code:: python

    from rrmngmnt import Host, RootUser

    h = Host("10.11.12.13")
    h.users.append(RootUser('123456'))

    exec = h.executor()
    # Run with sudo
    exec = h.executor(sudo=True)

    print exec.run_cmd(['echo', 'Hello World'])

Using SSH key for authentication

.. code:: python

    from rrmngmnt import Host, UserWithPKey

    h = 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)

.. code:: python

    from rrmngmnt import Host, UserWithPKey, RemoteExecutorFactory

    h = 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:: python

    proxy_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'])

Features
--------

List of provided interfaces to manage resources on machine, and
examples.

Filesystem
~~~~~~~~~~

Basic file operations, you can find there subset of python 'os' module
related to files.

.. code:: python

    print h.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.

.. code:: python

    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.

.. code:: python

    h1.fs.transfer(
        "/path/to/file/on/h1",
        h2, "/path/to/file/on/h2/or/target/dir",
    )

You can also mount devices.

.. code:: python

    with h.fs.mount_point(
        '//example.com/share', opts='ro,guest',
        fstype='cifs', target='/mnt/netdisk'
    ) as mp:
        h.fs.listdir(mp.target) # list mounted directory
        mp.remount('rw,sync,guest') # remount with different options
        h.fs.touch('%s/new_file' % mp.target) # touch file

Firewall
~~~~~~~~

Allows to manage firewall configurarion. Check which firewall service is
running on host (firewalld/iptables) and make configure this service.

.. code:: python

    h.firewall.is_active('iptables')
    h.firewall.chain('OUTPUT').list_rules()
    h.firewall.chain('OUTPUT').add_rule('1.1.1.1', 'DROP')


Network
~~~~~~~

It allows to manage network configuration.

.. code:: python

    print h.network.hostname
    h.network.hostname = "my.machine.org"
    print h.network.all_interfaces()
    print h.network.list_bridges()

Package Management
~~~~~~~~~~~~~~~~~~

It encapsulates various package managements. It is able to determine
which package management to use. You can still specify package management
explicitly.


Implemented managements:

-  APT
-  YUM
-  DNF
-  RPM

.. code:: python

    # install htop package using implicit management
    h.package_management.install('htop')
    # remove htop package using rpm explicitly
    h.package_management('rpm').remove('htop')

System Services
~~~~~~~~~~~~~~~

You can toggle system services, it encapsulates various service managements.
It is able to determine which service management to use in most cases.


Implemented managements:

-  Systemd
-  SysVinit
-  InitCtl

.. code:: python

    if h.service('httpd').status():
        h.service('httpd').stop()
    if h.service('httpd').is_enabled():
        h.service('httpd').disable()

Operating System Info
~~~~~~~~~~~~~~~~~~~~~

Host provide ``os`` attribute which allows obtain basic operating
system info.
Note that ``os.release_info`` depends on systemd init system.

.. code:: python

    print h.os.distribution
    # Distribution(distname='Fedora', version='23', id='Twenty Three')

    print h.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',
    #  ...
    # }

    print h.os.release_str
    # Fedora release 23 (Twenty Three)

Storage Management
~~~~~~~~~~~~~~~~~~

It is in PROGRESS state. Planed are NFS & LVM services.

Power Management
~~~~~~~~~~~~~~~~

Give you possibility to control host power state, you can restart,
poweron, poweroff host and get host power status.


Implemented managements:

-  SSH
-  IPMI

.. code:: python

    ipmi_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 ipmitool
    h.power_manager.restart()

Requires
--------

-  paramiko
-  netaddr
-  six

Install
-------

.. code:: sh

    python setup.py devop

Test
----

.. code:: sh

    tox




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rhevm-qe-automation/python-rrmngmnt",
    "name": "python-rrmngmnt",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/python-rrmngmnt/",
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "remote,resource,service",
    "author": "Lukas Bednar",
    "author_email": "lukyn17@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/45/60/571982c7af8f5453b86d332041d58076642d26089ea1481ce54e8f7f1305/python-rrmngmnt-0.1.32.zip",
    "platform": null,
    "description": "python-rrmngmnt\n===============\n\nRemote Resources MaNaGeMeNT\n\nIntro\n-----\n\nThis tool helps you manage remote machines and services running on that.\nIt is targeted to Linux based machines. All is done via SSH connection,\nthat means SSH server must be running there already.\n\n.. code:: python\n\n    from rrmngmnt import Host, RootUser\n\n    h = Host(\"10.11.12.13\")\n    h.users.append(RootUser('123456'))\n\n    exec = h.executor()\n    # Run with sudo\n    exec = h.executor(sudo=True)\n\n    print exec.run_cmd(['echo', 'Hello World'])\n\nUsing SSH key for authentication\n\n.. code:: python\n\n    from rrmngmnt import Host, UserWithPKey\n\n    h = Host(\"10.11.12.13\")\n    user = UserWithPKey('user', '/path/to/pkey'))\n\n    h.executor(user).run_cmd(['echo', 'Use pkey for auth instead of password'])\n\nUsing SSH key with disabled algorithms on paramiko SSHClient connect (Used when connecting to machines using old SSH)\n\n.. code:: python\n\n    from rrmngmnt import Host, UserWithPKey, RemoteExecutorFactory\n\n    h = Host(\"10.11.12.13\")\n    h.executor_factory = RemoteExecutorFactory(disabled_algorithms=dict(pubkeys=['rsa-sha2-256', 'rsa-sha2-512'])\n    user = UserWithPKey('user', '/path/to/pkey'))\n\n    h.executor(user).run_cmd(['echo', 'Use pkey and disabled algorithms for old openSSH connection'])\n\nUsing with SSH ProxyCommand\n.. code:: python\n\n    proxy_command = 'some proxy command'\n    h = Host(hostname=\"hostname\")\n    host.executor_factory = ssh.RemoteExecutorFactory(sock=proxy_command)\n    h.executor(user).run_cmd(['echo', 'Use SSH with ProxyCommand'])\n\nFeatures\n--------\n\nList of provided interfaces to manage resources on machine, and\nexamples.\n\nFilesystem\n~~~~~~~~~~\n\nBasic file operations, you can find there subset of python 'os' module\nrelated to files.\n\n.. code:: python\n\n    print h.fs.exists(\"/path/to/file\")\n    h.fs.chown(\"/path/to/file\", \"root\", \"root\")\n    h.fs.chmod(\"/path/to/file\", \"644\")\n    h.fs.unlink(\"/path/to/file\")\n\nIn additional there are methods to fetch / put file from / to remote system\nto / from local system.\n\n.. code:: python\n\n    h.fs.get(\"/path/to/remote/file\", \"/path/to/local/file/or/target/dir\")\n    h.fs.put(\"/path/to/local/file\", \"/path/to/remote/file/or/target/dir\")\n\nThere is one special method which allows transfer file between hosts.\n\n.. code:: python\n\n    h1.fs.transfer(\n        \"/path/to/file/on/h1\",\n        h2, \"/path/to/file/on/h2/or/target/dir\",\n    )\n\nYou can also mount devices.\n\n.. code:: python\n\n    with h.fs.mount_point(\n        '//example.com/share', opts='ro,guest',\n        fstype='cifs', target='/mnt/netdisk'\n    ) as mp:\n        h.fs.listdir(mp.target) # list mounted directory\n        mp.remount('rw,sync,guest') # remount with different options\n        h.fs.touch('%s/new_file' % mp.target) # touch file\n\nFirewall\n~~~~~~~~\n\nAllows to manage firewall configurarion. Check which firewall service is\nrunning on host (firewalld/iptables) and make configure this service.\n\n.. code:: python\n\n    h.firewall.is_active('iptables')\n    h.firewall.chain('OUTPUT').list_rules()\n    h.firewall.chain('OUTPUT').add_rule('1.1.1.1', 'DROP')\n\n\nNetwork\n~~~~~~~\n\nIt allows to manage network configuration.\n\n.. code:: python\n\n    print h.network.hostname\n    h.network.hostname = \"my.machine.org\"\n    print h.network.all_interfaces()\n    print h.network.list_bridges()\n\nPackage Management\n~~~~~~~~~~~~~~~~~~\n\nIt encapsulates various package managements. It is able to determine\nwhich package management to use. You can still specify package management\nexplicitly.\n\n\nImplemented managements:\n\n-  APT\n-  YUM\n-  DNF\n-  RPM\n\n.. code:: python\n\n    # install htop package using implicit management\n    h.package_management.install('htop')\n    # remove htop package using rpm explicitly\n    h.package_management('rpm').remove('htop')\n\nSystem Services\n~~~~~~~~~~~~~~~\n\nYou can toggle system services, it encapsulates various service managements.\nIt is able to determine which service management to use in most cases.\n\n\nImplemented managements:\n\n-  Systemd\n-  SysVinit\n-  InitCtl\n\n.. code:: python\n\n    if h.service('httpd').status():\n        h.service('httpd').stop()\n    if h.service('httpd').is_enabled():\n        h.service('httpd').disable()\n\nOperating System Info\n~~~~~~~~~~~~~~~~~~~~~\n\nHost provide ``os`` attribute which allows obtain basic operating\nsystem info.\nNote that ``os.release_info`` depends on systemd init system.\n\n.. code:: python\n\n    print h.os.distribution\n    # Distribution(distname='Fedora', version='23', id='Twenty Three')\n\n    print h.os.release_info\n    # {'HOME_URL': 'https://fedoraproject.org/',\n    #  'ID': 'fedora',\n    #  'NAME': 'Fedora',\n    #  'PRETTY_NAME': 'Fedora 23 (Workstation Edition)',\n    #  'VARIANT': 'Workstation Edition',\n    #  'VARIANT_ID': 'workstation',\n    #  'VERSION': '23 (Workstation Edition)',\n    #  'VERSION_ID': '23',\n    #  ...\n    # }\n\n    print h.os.release_str\n    # Fedora release 23 (Twenty Three)\n\nStorage Management\n~~~~~~~~~~~~~~~~~~\n\nIt is in PROGRESS state. Planed are NFS & LVM services.\n\nPower Management\n~~~~~~~~~~~~~~~~\n\nGive you possibility to control host power state, you can restart,\npoweron, poweroff host and get host power status.\n\n\nImplemented managements:\n\n-  SSH\n-  IPMI\n\n.. code:: python\n\n    ipmi_user = User(pm_user, pm_password)\n    ipmi_params = {\n        'pm_if_type': 'lan',\n        'pm_address': 'test-mgmt.testdomain',\n        'user': ipmi_user\n    }\n    h.add_power_manager(\n        power_manager.IPMI_TYPE, **ipmi_params\n    )\n    # restart host via ipmitool\n    h.power_manager.restart()\n\nRequires\n--------\n\n-  paramiko\n-  netaddr\n-  six\n\nInstall\n-------\n\n.. code:: sh\n\n    python setup.py devop\n\nTest\n----\n\n.. code:: sh\n\n    tox\n\n\n\n",
    "bugtrack_url": null,
    "license": "GPLv2",
    "summary": "Tool to manage remote systems and services",
    "version": "0.1.32",
    "project_urls": {
        "Homepage": "https://github.com/rhevm-qe-automation/python-rrmngmnt"
    },
    "split_keywords": [
        "remote",
        "resource",
        "service"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4560571982c7af8f5453b86d332041d58076642d26089ea1481ce54e8f7f1305",
                "md5": "9863b09e2c2867f71366a8e8a9805cc1",
                "sha256": "0953f9e9e3911d4a310282513261ed7572fbc269f78c8e3d0680f84ba9955526"
            },
            "downloads": -1,
            "filename": "python-rrmngmnt-0.1.32.zip",
            "has_sig": false,
            "md5_digest": "9863b09e2c2867f71366a8e8a9805cc1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 84778,
            "upload_time": "2023-06-06T05:27:04",
            "upload_time_iso_8601": "2023-06-06T05:27:04.071581Z",
            "url": "https://files.pythonhosted.org/packages/45/60/571982c7af8f5453b86d332041d58076642d26089ea1481ce54e8f7f1305/python-rrmngmnt-0.1.32.zip",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-06 05:27:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rhevm-qe-automation",
    "github_project": "python-rrmngmnt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "python-rrmngmnt"
}
        
Elapsed time: 0.10401s