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(a)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
+
+
+(a)click.group()
+(a)click.option('-v', '--verbose', is_flag=True)
+(a)click.option('-p', '--pprint', is_flag=True)
+(a)click.pass_context
+def cli(ctx, verbose, pprint):
+ ctx.obj = Options(verbose, pprint)
+
+
+(a)cli.group()
+(a)click.pass_obj
+def network(options):
+ """Network actions and information displaying."""
+ pass
+
+
+(a)network.command(help='Configure network')
+(a)click.pass_obj
+(a)click.option('--bridged/--bridgeless', default=True)
+(a)click.option('--vlan', default=None, type=click.INT)
+(a)click.option('--bond', default=None)
+(a)click.option('--bond-opts', default=None)
+(a)click.option('--nic', multiple=True)
+(a)click.argument('name')
+(a)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))
+
+
+(a)network.command(help='show network and net device information')
+(a)click.pass_obj
+(a)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()
--
To view, visit http://gerrit.ovirt.org/28152
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie5574b2b34f0b7b2174e9da0c4487f812ff20f5b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap(a)redhat.com>
Liron Ar has uploaded a new change for review.
Change subject: volume: support multi line metadata values
......................................................................
volume: support multi line metadata values
Currently when creating the metadata dict it's assumed that each value
can be in a single line only while it's not necessarily true.
Change-Id: Ib03152b852294f7b69a8734c2aa1206ea2c1fabe
Signed-off-by: Liron Aravot <laravot(a)redhat.com>
---
M vdsm/storage/blockVolume.py
M vdsm/storage/volume.py
2 files changed, 12 insertions(+), 5 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/93/28493/1
diff --git a/vdsm/storage/blockVolume.py b/vdsm/storage/blockVolume.py
index d448e00..d7cf020 100644
--- a/vdsm/storage/blockVolume.py
+++ b/vdsm/storage/blockVolume.py
@@ -580,7 +580,6 @@
self.log.error(e, exc_info=True)
raise se.VolumeMetadataReadError("%s: %s" % (metaId, e))
-
def setMetadata(self, meta, metaId=None):
"""
Set the meta data hash as the new meta data of the Volume
diff --git a/vdsm/storage/volume.py b/vdsm/storage/volume.py
index aed932e..bfc1ff1 100644
--- a/vdsm/storage/volume.py
+++ b/vdsm/storage/volume.py
@@ -814,19 +814,27 @@
"""
pass
-
def metadata2dict(self, meta):
out = {}
+ key = None
+ value = None
+
+ def put(key, value):
+ out[key.strip()] = "\n".join(value).strip()
+
for l in meta:
if l.startswith("EOF"):
- return out
+ break
if l.find("=") < 0:
+ value.append(l)
continue
+ if key:
+ put(key, value)
key, value = l.split("=")
- out[key.strip()] = value.strip()
+ value = [value]
+ put(key, value)
return out
-
def metadata2info(self, meta):
return {
--
To view, visit http://gerrit.ovirt.org/28493
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib03152b852294f7b69a8734c2aa1206ea2c1fabe
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Liron Ar <laravot(a)redhat.com>
Dan Kenigsberg has uploaded a new change for review.
Change subject: xen: libvirtconnection: connect to xen, if it is available
......................................................................
xen: libvirtconnection: connect to xen, if it is available
Change-Id: I6cc6474b012d900fe3c5e1dab7a1e3e815ae01c3
Signed-off-by: Dan Kenigsberg <danken(a)redhat.com>
---
M lib/vdsm/libvirtconnection.py
1 file changed, 6 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/50/28350/1
diff --git a/lib/vdsm/libvirtconnection.py b/lib/vdsm/libvirtconnection.py
index b1332db..983287f 100644
--- a/lib/vdsm/libvirtconnection.py
+++ b/lib/vdsm/libvirtconnection.py
@@ -29,6 +29,7 @@
from . import constants, utils
log = logging.getLogger()
+XEN = os.path.exists('/proc/xen')
class _EventLoop:
@@ -124,7 +125,7 @@
libvirt.VIR_ERR_INTERNAL_ERROR,
libvirt.VIR_ERR_NO_CONNECT,
libvirt.VIR_ERR_INVALID_CONN)
- if edom in EDOMAINS and ecode in ECODES:
+ if not XEN and edom in EDOMAINS and ecode in ECODES:
try:
__connections.get(id(target)).pingLibvirt()
except libvirt.libvirtError as e:
@@ -148,7 +149,10 @@
conn = __connections.get(id(target))
if not conn:
log.debug('trying to connect libvirt')
- conn = _open_qemu_connection()
+ if XEN:
+ conn = libvirt.open('xen:///')
+ else:
+ conn = _open_qemu_connection()
__connections[id(target)] = conn
setattr(conn, 'pingLibvirt', getattr(conn, 'getLibVersion'))
--
To view, visit http://gerrit.ovirt.org/28350
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6cc6474b012d900fe3c5e1dab7a1e3e815ae01c3
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken(a)redhat.com>