Coder Social home page Coder Social logo

beedrones's Introduction

beedrones

beedrones is a project that contains all the base platform client used by the nivola cmp platform. Platform client are developed to simplify interaction with platform api exposed with http(s) protocol and rest or some xml input and output format. Different platforms are integrated in clients, from bind to manage dns key to openstack to manage keystone, nova and neutron api, to vsphere and nsx-v. Some clients are written from scratch using library like requests or httpclient, other use existing python client and wrap it in more simple commands.

The main clients developed are:

Packages

Awx client

Awx client use rest api to manage fundamental entities like inventory, credential, project, job template.

Tested on: Awx 14.1.0

How to use

Connect and login to awx:

from beedrones.awx.client import AwxManager

uri = http://localhost:80/api/v2/
client = AwxManager(uri=uri)
client.authorize(user='admin', pwd='xxx')

Ping engine:

client.ping()

Get inventories:

client.inventory.list()

Create a project with a git credential:

cred = client.credential.add_git('git-cred', 1, 'ansible', 'xxx')
cred_id = cred['id']
client.project.add('prova_prj', scm_type='git', scm_url='https://localhost/project',
                   scm_branch='master', credential=cred_id)

Create and launch a template job:

playbook = 'zabbix-agent.yml'
project = client.project.list(name='prova_prj')[0]['id']
inventory = client.inventory.add('nivola_cmp_stage_inventory, organization)['id']
credential = client.credential.list(name='prova_template_cred')

client.job_template.add('prova_template', 'run', inventory, project, playbook,
                        ask_credential_on_launch=True, ask_variables_on_launch=True, 
                        ask_limit_on_launch=True)
            

limit = 'server.localdomain'
extra_vars = {}
params = {'credentials': [credential[0]['id']], 'extra_vars': extra_vars, 'limit': limit}
job = client.job_template.launch(job_template[0]['id'], **params)                        

Bind client

Bind client use dnspython package to manage dns zones, recorda and record cname.

Tested on: Bind

How to use

Connect to bind:

from beedrones.dns.client import DnsManager

serverdns = {'resolver': ['dns_ip_1', 'dns_ip_2'], 'update': ['up_dns_ip_1', 'up_dns_ip_2']}
key = {'key': 'value'}
client = DnsManager(serverdns, zones=[], dnskey=key)

Query dns zone:

zone = 'localdomain'
client.query_nameservers(zone)
client.query_authority(zone)

Create and query recorda:

zone = 'localdomain'
ip_addr = '10.100.1.2'
host_name = 'test'
client.add_record_A(ip_addr, host_name, zone, ttl=3600)
client.query_record_A(host_name)

Graphite client

Graphite client use rest api to query collected data.

Tested on: Graphite 0.9.16

How to use

Connect and Graphite:

from beedrones.graphite.client import GraphiteManager

host =  'localhost.localdomain'
client = GraphiteManager(host, 'test')

Query metrics:

client.set_search_path('test.vmware.tst-open-graphite')
res = client.get_virtual_node_metrics('vsphere', 'vm-3870', 15)
client.format_metrics('vm-3870', res, 'vsphere')

Guacamole client

Guacamole client is in development.

Tested on:

Openstack client

Openstack client connect to module rest api like keystone, nova, nutron, manila and cinder to manage entities like project, network, server and volume.

Tested on: Openstack Stein

How to use

Connect and login to Openstack:

from beedrones.openstack.client import OpenstackManager

uri = http://localhost:5000/v3
client = OpenstackManager(uri=uri, default_region='RegionOne')
client.authorize('admin', 'mypass', project='admin', domain='Default', key=None)

Ping engine:

client.ping()

Get hypervisors:

client.system.compute_hypervisors()

Create and list projects:

client.project.create('prova-project', 'default', False, parent_id=None)
client.project.list()

Create and list servers:

name = 'server-test'
image = client.image.get(name='centos7')['id']
flavor = client.flavor.get(2)['id']
networks = [{'uuid': self.client.network.get(name='net1')['id']}]
res = client.server.create(name, flavor, networks=networks, adminpass='mypass', description='test',
                           image=image, security_groups=['default'])
client.server.list()

Trilio client

Trilio client is in development.

Tested on:

Syncthing client

Syncthing client is in development.

Tested on:

Veeam client

Veeam client is in development.

Tested on:

Libvirt client

Libvirt client use python libvirt to query libvirt deamon on a server where are running some domains.

Tested on: Libvirt 4.5.0

How to use

Connect and login to awx:

from beedrones.virt.manager import VirtManager

host = 'localhost'
user = 'root'
keyfile = '/tmp/id_rsa'
client = VirtManager('virt1', host, user=user, key=keyfile)
client.connect()

Ping engine:

client.ping()

Get domains:

status = 1
server.get_domains(status=status)

vSphere client

Vsphere client is based on pyVmomi. pyVmomi is the Python SDK for the VMware vSphere API that allows you to manage ESX, ESXi, and vCenter. is the Python SDK for the VMware vSphere API that allows you to manage ESX, ESXi, and vCenter. Vsphere client manage vCenter entities like folder, server, dvpg, ... Vsphere client also interact with nsx api to manage network virtualization entities like dfw, edge, logical switch, ..

Tested on: vSphere vCenter 6.5 and Nsx 6.3.5

How to use

Connect and login to Vsphere:

from beedrones.vsphere.client import VsphereManager

vcenter = {'host': 'localhost', 'port': 443, 'user': 'admin.local', 'pwd': 'mypass', 'verified': False, 'timeout': 5}
nsxmanager = {'host': 'localhost', 'port': 443, 'user': 'admin', 'pwd': 'mypass', 'verified': False, 'timeout': 5}
client = VsphereManager(vcenter, nsxmanager, key=None)
client.authorize('admin', 'mypass', project='admin', domain='Default', key=None)

Ping engine:

client.ping()

Get datacenters, clusters and folders:

client.datacenter.list()
client.cluster.list()
client.folder.list()

Create and list servers:

name = 'server_test'
guest_id = 'windows9Server64Guest'
folder = client.folder.get('group-v3')
datastore = client.datastore.get('datastore-48').name        
resource_pool = client.cluster.resource_pool.get('resgroup-42')
network = client.network.get_network('dvportgroup-66')
task = client.server.create(name, guest_id, resource_pool, datastore, folder, network, memory_mb=2048,
                            cpu=2, core_x_socket=1, disk_size_gb=40, version='vmx-13')
client.server.list()

Zabbix client

Zabbix client use Zabbix api to manage group, host, template, alerts, ...

Tested on: Zabbix 4

How to use

Connect and login to Zabbix:

from beedrones.zabbix.client import ZabbixManager

uri = http://localhostzabbix
client = ZabbixManager(uri=uri)
client.authorize('Admin', 'mypass')

Ping engine:

client.ping()

Get hosts:

client.host.list()

Get alerts:

d = datetime.strptime('21/09/2019', '%d/%m/%Y')
time_from = mktime(d.timetuple())
res = client.alert.list(time_from=time_from)

Installing

Install requirements

First of all you have to install some package and create a python virtual env:

$ sudo apt -y install gcc python-dev sshpass rsync mariadb-client git libldap2-dev libffi-dev libssl-dev libsasl2-dev pkg-config libvirt-dev
$ python3 -m venv /tmp/py3-test-env
$ source /tmp/py3-test-env/bin/activate

Install python packages

Public packages:

$ pip3 install -U git+https://github.com/Nivola/beecell.git
$ pip3 install -U git+https://github.com/Nivola/beedrones.git

Running the tests

Activate virtual env:

$ source /tmp/py3-test-env/bin/activate

Open tests directory /tmp/py3-test-env/lib/python3.x/site-packages/beedrones/tests

Copy file beedrones.yml in your home directory. Open the file and set correctly all the variables.

Test log can be seen as /tmp/test.log

Open test, set internal query and manage options and run:

$ python awx/client.py
$ python dns/client.py
$ python graphite/client.py
$ python dns/openstack.py
$ python dns/trilio.py
$ python dns/vsphere.py
$ python dns/virt.py
$ python dns/zabbix.py

Versioning

We use Semantic Versioning for versioning. (https://semver.org)

Authors and Contributors

See the list of contributors who participated in this project in the file AUTHORS.md contained in each specific project.

Copyright

CSI Piemonte - 2018-2022

Regione Piemonte - 2020-2022

License

See the *LICENSE.txt file for details

beedrones's People

Contributors

sergiotonani avatar gidor avatar filippovallero-csi avatar

Watchers

James Cloos avatar  avatar

Forkers

luca-scanavino

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.