netinfo: fix getMaxMtu generator handling

getMaxMtu was changed to use iterables instead of just lists.
The check for if and a generator is always True regardless of
it generating any elements. Thus, max could fail.

This fixes a regression introduced by:
http://gerrit.ovirt.org/15355

Change-Id: I94a58ab6a3303099105987fd230680586f6a3cce
Signed-off-by: Antoni S. Puimedon <asegurap@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/15903
Reviewed-by: Giuseppe Vallarelli <gvallare@redhat.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Tested-by: Dan Kenigsberg <danken@redhat.com>
Don't depend on storage module

There is no real need for hooking module to depend on the storage
module, except for the execCmd which is being delegated to
utils.execCmd, so importing the execCmd directly from utils instead.

Change-Id: Ib36940cda2a07e2898e26e6e7de4d4f3b1292e8f
Signed-off-by: Mike Kolesnik <mkolesni@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/16003
Reviewed-by: Giuseppe Vallarelli <gvallare@redhat.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Tested-by: Dan Kenigsberg <danken@redhat.com>
configNetwork: fix handleBondings regression

during the rebase destroy was not updated to its new name of
destroyOnRemoval. This patch fixes that.

Patch Set 2:
- Added a functional test to catch this sort of problem in the
  future.
Patch Set 3:
- Fixed arguments.

Patch Set 4:
- Added extra tests.

Patch Set 5:
- Improvement on the tests.

Patch Set 6:
- Fixed pep8.

Patch Set 7:
- simplified pinger.

Patch Set 8:
- Cleaned the pinger implementation.

Change-Id: I19dc94938be094bfe990301aab49a1ddc01e72fc
Signed-off-by: Antoni S. Puimedon <asegurap@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/15902
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
netinfo: get an interface using one of IP addresses assigned to it

We record the server's IP address for each XMLRPC request, preventing
manually parsing the routes files.
This patch also fix an error that when connected from localhost(using
tools like vdsClient) through the loopback interface, vdsm would report
the interface associated with the default gateway as the used interface,
instead of the expected result 'lo', because the routing table doesn't
contain any information for the device 'lo'.

Change-Id: I239f92c527524e5651f51712841c3eafcf659e53
Signed-off-by: huntxu <mhuntxu@gmail.com>
Reviewed-on: http://gerrit.ovirt.org/11519
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Tested-by: Dan Kenigsberg <danken@redhat.com>
functional test: boot VM with network interface device

Change-Id: I18c350074ce2b9712c468899075e5e2e22ee2550
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
Reviewed-on: http://gerrit.ovirt.org/15633
Reviewed-by: Giuseppe Vallarelli <gvallare@redhat.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Fix bridgeless net regression

The commit:
Ie8bb5fd9fc6ad69cf120d62264d73490b65b82d7
http://gerrit.ovirt.org/#/c/11356/4/

That commit introduced a bug that prevents the user from configuring
a bridgeless network with dhcp. That is so because after the change,
if ipaddr is None, which is the most usual case when configuring a
network for dhcp, bootproto will be overriden by what was on the
original config file (quite probably None).

Change-Id: I2881791f7b2b23cdcea25b73d3eb44de2d2addc8
Signed-off-by: Antoni S. Puimedon <asegurap@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/16086
Reviewed-by: Mark Wu <wudxw@linux.vnet.ibm.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Multiple Gateways[1/2]: add sourceRouting module

http://www.ovirt.org/Features/Multiple_Gateways

Patch Set 3:
* Trivial fixes after comments from initial review

Patch Set 4:
* Use newly implemented iproute2 binary wrapper

Patch Set 5 - 8:
* Rebased changes from ipwrapper.py
* Structural changes to allow introducing a configurator

Patch Set 9:
* Configure now checks if the gateway received
  is 0.0.0.0. If so, nothing has to be done.

Patch Set 11:
* Squashed with next patch in series
* Added a configurator to SourceRoute
* Moved SourceRoute add/del routes/rules to Ifcfg configurator
  and Iproute2 configurator.
* configure and remove now check that the requested interface
  is 'tracked' by VDSM. That is, it was created by us
  and not an interface configured manually by the admin.
* SourceRoute no longer needs or knows if it's Static or not.

Patch Set 12:
* Added sourceRoute.py and netconf/iproute2.py to make
  and spec files

Patch Set 13:
* Use a argparse to deal with command line arguments

Patch Set 14:
* Dropped WIP tag and changed name to reflect that it is a partial
  state of the feature.

Patch Set 15:
* Rebase

Patch Set 16:
* Reflect the changes of method names in the previous patch.

Patch Set 18:
* Fix deleting network without routes and rules.

Patch Set 19:
* Fix ipaddr -> ip.

Patch Set 21:
* Fix 'static' -> 'none'.

Patch Set 22:
- Fix bug when taking down interfaces. The previous version failed to
  remove rules due to the fact that on el6:
      ip route show table xxxxxxxxx
  gives the routes of the xxxxxxxxx table but also of the main table,
  so for example the ovirtmgmt route on a different device and
  different table was being marked for removal from table xxxxxxxxx.
  Since the route wasn't really on the table, netlink returned an
  exception and we never reached the rule removal stage.

Patch Set 23:
- Make the code cleared in the except ValueError.

Patch Set 24:
- Sort import sections alphabetically. Make staticmethods out of
  instance methods without state nor class dependencies.

Patch Set 25:
- Fixed the bootup issues for DHCP and refactored sourceRoute into
  static and dynamic for easier integration in the following patch.

Patch Set 26:
- Addressed review comments about logging and documenting.

Change-Id: I0224d896724b9cdc44215e92f0da0be71fd19038
Signed-off-by: Assaf Muller <amuller@redhat.com>
Signed-off-by: Antoni S. Puimedon <asegurap@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/15207
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Multiple Gateways[2/2]: configNetwork integration

This patch provides the integration of sourceRoute with the
configurator flow.

For static routes, multiple gateways uses the ifcfg configurator
and its configWriter to write:
    /etc/sysconfig/network-scripts/{route,rule}-netname
Those files are taken care of by ifup/ifdown.

For dynamic routes (DHCP) it has a hook in
/etc/dhcp/dhclient.d/sourceRoute.sh that is automatically executed
by dhcpd when it obtains a lease for a device. The hook will call
directly the sourceRoute.py command line UI that will delegate
the actions to the iproute2 configurator. For this hook to work,
selinux needs a few policy updates that have been requested in:

https://bugzilla.redhat.com/show_bug.cgi?id=977856

The selinux-policy changes are needed due to the fact that the python
code in sourceRoute.py is being executed from the dhcp_t context
and not from the usual service, reason for which currently there was
no policy to allow such context to access several parts of the system
via python.

The integration is done at the configureDevice level because it is
the only sensible choice considering that the static file removal
must be done between ifdown and ifup (so that ifdown takes down the
rules and ifup doesn't have them anymore so it does not apply them)
and the fact that configureDevice for nics and bonds must leave the
device up, i.e., they do ifdown and ifup inside the method.

Patch Set 2:
- delNetwork now checks that the bootproto is not dhcp
- In sourceRoute.py: Removed check if the interface has
  a libvirt network on top of it because it was preventing
  DHCP interfaces from going up properly. Will need to think
  of a different fix.

Patch Set 4:
- Fixed the Makefile and spec for dhcp hook installation.

Patch Set 5:
- Fixed the network deletion. It was trying to remove routes for an
  already unexistant network device.

Patch Set 7:
- Fixed dhcp flow by changing when we do libvirt network addition
  and deletion.

Patch Set 8:
- Addressed review comments. Fixed the ifup ifdown flow when using
  the ifcfg configurator (and the iproute2 for dhcp).

Patch Set 9:
- Addressed review comments and squashed:
      http://gerrit.ovirt.org/#/c/16087/1
      I09aec8fa9a2ef2d61609a0a807f4e7130978fbfb
  into this patch.

Change-Id: Id4415c6ec91ac49c56703d59b99d3a21b328015b
Signed-off-by: Assaf Muller <amuller@redhat.com>
Signed-off-by: Antoni S. Puimedon <asegurap@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/15528
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Fix multiple default gateways reporting

Up until now there was just a default gateway per host, defining
default as going towards 0.0.0.0/0. If more than one device
received a default gateway setting, only the latest to be
configured kept its configuration as host default configuration.

Now, thanks to multiple gateways, we have a routing table for each
network, which allows us to have multiple default gateways to
report. The only issue is that /proc/net/route only reports
information for table 254, while we are using several. For this
reason, we change the implementation to use ipwrapper to get the
information from all the tables.

PatchSet 2:
- Fix calling to ipwrapper and added it to lib/vdsm/Makefile.am

PatchSet 3:
- Rebase on top of the fixes of multiple gateways.
- Split Routes fromText into parser and fromText.
- Made source use the new placement and parse method of ipwrapper.

Patch Set 4:
- Rebase the patch.

Change-Id: Iacd6328a938b955a63bbc0d5c0fb9bfcc7de6d44
Signed-off-by: Antoni S. Puimedon <asegurap@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/15890
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Interface changes for getImageDomainsList internal changes.

Complement to I25fe2714e4c4e832230653cebc87d8da0e81028b.

Change-Id: Ib4cbfe95359defb14263ff5566e62e6f01c7d54a
Signed-off-by: Eduardo <ewarszaw@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/16090
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Tested-by: Dan Kenigsberg <danken@redhat.com>
Remove StoragePool.getImageDomainsList().

Avoid code duplication.

Related to BZ#905038.

Change-Id: I225fa7a58e1fabb844cc883938e94df39d2a8ae2
Signed-off-by: Eduardo <ewarszaw@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/12927
Tested-by: Elad Ben Aharon <eladba1990@gmail.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Ignore partially deleted images in getAllImages().

Change-Id: I028dabbf1a0b39177d0c52222cae177f5123442f
Bug-url: https://bugzilla.redhat.com/show_bug.cgi?id=905038
Signed-off-by: Eduardo <ewarszaw@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/12938
Tested-by: Elad Ben Aharon <eladba1990@gmail.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
vm payload: clarify intent of supporting multiple files

With cloud-init integration now using payloads with multiple files,
clarify that this is supported in the payload code.

Change-Id: I3b2a9828eb1fee5bc5c25d5faa90b387473e820e
Bug-Url: https://bugzilla.redhat.com/619761
Signed-off-by: Greg Padgett <gpadgett@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/16073
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Tested-by: Dan Kenigsberg <danken@redhat.com>
alignmentScanTests: Remove text output validation of help

'virt-alignment-scan --help' output has changed in fedora 19.
No need to check the actual output text, but only that we
can run 'help'.

Change-Id: I68c64fa6ce39b61d867fd01cbdcb6c31b4ce0435
Signed-off-by: Yeela Kaplan <ykaplan@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/16098
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Reviewed-by: Douglas Schilling Landgraf <dougsland@redhat.com>
Tested-by: Douglas Schilling Landgraf <dougsland@redhat.com>
Fix potential race of getting caps during addNet

getmtu can return IOError when a libvirt network underlying device
does not exist. This can happen when we get a getVdsCapabilities
request after the libvirt network entry has been added but before
the device has been ifupped.

Change-Id: Idfabbc7799b330412e864dfb6f77748e57f7df85
Signed-off-by: Antoni S. Puimedon <asegurap@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/16122
Reviewed-by: Giuseppe Vallarelli <gvallare@redhat.com>
Reviewed-by: Mark Wu <wudxw@linux.vnet.ibm.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
clientIF: Check disk alignment using virt-alignment-scan

Change-Id: Ia925f5f138948acca623f6379b7b811474a43ffe
Signed-off-by: Yeela Kaplan <ykaplan@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/12003
Reviewed-by: Federico Simoncelli <fsimonce@redhat.com>
XMLRPCServer: make XMLRPCServer able to listen on IPv6 addresses

SimpleXMLRPCServer is derived from SocketServer.TCPServer of which the
default address_family is socket.AF_INET, that makes it could only
listen on IPv4 connections. This patch wraps it and extends its
ability on IPv6 networks.

How to test:

  1. Build and install VDSM RPMs
  2. Edit /etc/vdsm/vdsm.conf, change "addresses/management_ip = ::",
and "vars/jsonrpc_enable = false"(as known to break JSONRPC)
  3. Restart VDSM daemon
  4. "netstat -nlp6t" or "ss -nlp6t" should indicate vdsm XMLRPC server
is listening on "::"
  5. "vdsClient -s '[::1]:54321' getVdsCaps" succeeds

Change-Id: I50ab0ba59ac696da2d992afe453c6d3ceb111e94
Signed-off-by: Petr Sebek <psebek@redhat.com>
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
Signed-off-by: huntxu <mhuntxu@gmail.com>
Reviewed-on: http://gerrit.ovirt.org/11520
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
nit fix for _cleanOldFiles

svdsm.sock will not be in filterd fileType

Change-Id: I8d37c524c1a2ad7aadf36a27f524c378f6a104d3
Signed-off-by: Royce Lv<lvroyce@linux.vnet.ibm.com>
Reviewed-on: http://gerrit.ovirt.org/11128
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Tested-by: Dan Kenigsberg <danken@redhat.com>
vdscli: make __getLocalVdsName more robust

vdscli attempts to guess the name of the local host by reading the
"subject" of its openssl certificate.

On Fedora 19, the order of the subject fields has changed. This patch
makes __getLocalVdsName a bit more robust, and adds a unit test for it.

Change-Id: I56bf79904cdf5d0dfcba773f096df1d3ec1670fe
Signed-off-by: Dan Kenigsberg <danken@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/16059
Reviewed-by: Antoni Segura Puimedon <asegurap@redhat.com>
dumpStorageTable: fixed a unhandled exception when poollist is empty

when poollist is empty then dumpStorageTable was failing with
'IndexError: list index out of range', Also crash dump was reported
in /var/log/messages

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=961816
Change-Id: I98b6bb29720cb21627dc8f1e23dd90126c3bf0b4
Signed-off-by: Aravinda VK <avishwan@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/14886
Reviewed-by: Dan Kenigsberg <danken@redhat.com>