Antoni Segura Puimedon has uploaded a new change for review.
Change subject: vdsmcli: Add a contrib command line client alternative ......................................................................
vdsmcli: Add a contrib command line client alternative
This command line client is built by hand for the convenience of developers and requires the click library: pip install click
It easily supports commands and subcommands. For example:
vdsmcli network
is a command and 'show' and 'add' are its subcommands.
Examples:
toniel602 ~ # vdsmcli network show -k nics -k networks ============================================= Nics eth6 eth5 eth4 eth3 eth2 eth1
============================================= Networks foo
or toniel602 ~ # vdsmcli --verbode --pprint network show -k networks ============================================= Networks =============== foo =============== {'addr': '', 'bootproto4': 'none', 'bridged': False, 'gateway': '', 'iface': 'bond42', 'interface': 'bond42', 'ipv6addrs': ['2620:52:0:223c:201:a4ff:feac:8796/64', 'fe80::201:a4ff:feac:8796/64'], 'ipv6gateway': 'fe80:52:0:223c::3fe', 'mtu': '1500', 'netmask': ''}
addition toniel602 ~ # ./cvdsm.py -v -p network add foo --bridgeless --nic eth4 --nic eth5 --bond bond42 Networks: {u'foo': {'bonding': u'bond42', 'bridged': False}} Bonds: {u'bond42': {'nics': (u'eth4', u'eth5')}} Succeeded. Done
One could extend it with a vm command so that it was easy to do:
vdsmcli vm hotplug 34f5f608-91ed-48d1-af31-c3a3d788678e nic --mac 00:11:22:33:44:55 --model virtio
Change-Id: Ie5574b2b34f0b7b2174e9da0c4487f812ff20f5b Signed-off-by: Antoni S. Puimedon asegurap@redhat.com --- A contrib/vdsmcli.py 1 file changed, 113 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/52/28152/1
diff --git a/contrib/vdsmcli.py b/contrib/vdsmcli.py new file mode 100644 index 0000000..2255201 --- /dev/null +++ b/contrib/vdsmcli.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python2 +# Copyright 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# +"""This is a command line client for vdsm.""" + +from pprint import pformat + +import click + +from vdsm import netinfo, vdscli + +_NET_DEVICE_TYPES = ('networks', 'bridges', 'vlans', 'bondings', 'nics') + + +class Options(object): + def __init__(self, verbose=None, pprint=None): + self.verbose = verbose + self.pprint = pprint + + +@click.group() +@click.option('-v', '--verbose', is_flag=True) +@click.option('-p', '--pprint', is_flag=True) +@click.pass_context +def cli(ctx, verbose, pprint): + ctx.obj = Options(verbose, pprint) + + +@cli.group() +@click.pass_obj +def network(options): + """Network actions and information displaying.""" + pass + + +@network.command(help='Configure network') +@click.pass_obj +@click.option('--bridged/--bridgeless', default=True) +@click.option('--vlan', default=None, type=click.INT) +@click.option('--bond', default=None) +@click.option('--bond-opts', default=None) +@click.option('--nic', multiple=True) +@click.argument('name') +@click.argument('extra_attributes', required=False, nargs=-1) +def add(options, bridged, vlan, bond, bond_opts, nic, name, extra_attributes): + conn = vdscli.connect() + networks = {name: {'bridged': bridged}} + if vlan: + networks[name]['vlan'] = vlan + if len(nic) == 1: + networks[name]['nic'] = nic[0] + if bond: + networks[name]['bonding'] = bond + bonds = {bond: {'nics': nic}} + if bond_opts: + bonds[bond]['options'] = bond_opts + else: + bonds = {} + + for key, value in (elem.split('=') for elem in extra_attributes): + networks[name][key] = value + + if options.verbose: + click.echo('Networks: %s' % (pformat(networks) if options.pprint else + networs)) + click.echo('Bonds: %s' % (pformat(bonds) if options.pprint else bonds)) + result = conn.setupNetworks(networks, bonds, {'connectivityCheck': False}) + code = result['status']['code'] + message = result['status']['message'] + click.echo('%s. %s' % ('Succeeded' if code == 0 else 'Failed', message)) + + +@network.command(help='show network and net device information') +@click.pass_obj +@click.option('--kind', '-k', multiple=True, type=click.Choice( + _NET_DEVICE_TYPES)) +def show(options, kind): + if not kind: + kind = ('networks',) + conn = vdscli.connect() + info = netinfo.NetInfo(conn.getVdsCapabilities()['info']) + for k in kind: + click.echo('') + click.echo('=' * 45, nl=False) + click.echo(' ' + k[0].upper() + k[1:]) + for name, attrs in getattr(info, k).iteritems(): + if options.verbose: + click.echo('=' * 15) + click.echo(name) + if options.verbose: + click.echo('=' * 15) + click.echo(pformat(attrs) if options.pprint else attrs) + click.echo('') + + +if __name__ == '__main__': + cli()
oVirt Jenkins CI Server has posted comments on this change.
Change subject: vdsmcli: Add a contrib command line client alternative ......................................................................
Patch Set 1:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/8565/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit/9499/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/9353/ : SUCCESS
Francesco Romani has posted comments on this change.
Change subject: vdsmcli: Add a contrib command line client alternative ......................................................................
Patch Set 1: Code-Review+1
very cool! I don't know how much this is far-fetched, but I'd like to automaticcally build options, commands etc. from the schema (I volunteer for that!)
Nir Soffer has posted comments on this change.
Change subject: vdsmcli: Add a contrib command line client alternative ......................................................................
Patch Set 1: Code-Review+1
Cool! too many decorators for my taste, but great addition to contrib.
Dan Kenigsberg has posted comments on this change.
Change subject: vdsmcli: Add a contrib command line client alternative ......................................................................
Patch Set 1: Code-Review+2
I'd prefer something that parses the schema, but we can take it in, and see if it turns out helpful.
Jenkins CI RO has posted comments on this change.
Change subject: vdsmcli: Add a contrib command line client alternative ......................................................................
Patch Set 1:
Abandoned due to no activity - please restore if still relevant
Jenkins CI RO has abandoned this change.
Change subject: vdsmcli: Add a contrib command line client alternative ......................................................................
Abandoned
Abandoned due to no activity - please restore if still relevant
automation@ovirt.org has posted comments on this change.
Change subject: vdsmcli: Add a contrib command line client alternative ......................................................................
Patch Set 1:
* Update tracker::IGNORE, no Bug-Url found
vdsm-patches@lists.fedorahosted.org