Sandro Bonazzola has uploaded a new change for review.

Change subject: vdsm: use vdscli instead of vdsClient
......................................................................

vdsm: use vdscli instead of vdsClient

Code refactor dropping vdsClient usage in favor of
vdscli API.

The refactor allow to achieve a better error handling
and to have more control on what's going on.

Change-Id: I0f17abcc4ec83a69832bdb5a986136831504da2c
Bug-Url: https://bugzilla.redhat.com/1144334
Bug-Url: https://bugzilla.redhat.com/1101553
Bug-Url: https://bugzilla.redhat.com/1142098
Related-To: https://bugzilla.redhat.com/1005923
Related-To: https://bugzilla.redhat.com/1150427
Signed-off-by: Sandro Bonazzola <sbona...@redhat.com>
---
M src/ovirt_hosted_engine_setup/constants.py
M src/ovirt_hosted_engine_setup/mixins.py
M src/ovirt_hosted_engine_setup/tasks.py
M src/plugins/ovirt-hosted-engine-setup/ha/ha_services.py
M src/plugins/ovirt-hosted-engine-setup/network/bridge.py
M src/plugins/ovirt-hosted-engine-setup/storage/iscsi.py
M src/plugins/ovirt-hosted-engine-setup/storage/storage.py
M src/plugins/ovirt-hosted-engine-setup/system/vdsmenv.py
M src/plugins/ovirt-hosted-engine-setup/vm/boot_disk.py
M src/plugins/ovirt-hosted-engine-setup/vm/configurevm.py
M src/plugins/ovirt-hosted-engine-setup/vm/image.py
M src/plugins/ovirt-hosted-engine-setup/vm/runvm.py
12 files changed, 265 insertions(+), 169 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup 
refs/changes/96/33996/1

diff --git a/src/ovirt_hosted_engine_setup/constants.py 
b/src/ovirt_hosted_engine_setup/constants.py
index 5b28df7..0d32301 100644
--- a/src/ovirt_hosted_engine_setup/constants.py
+++ b/src/ovirt_hosted_engine_setup/constants.py
@@ -275,6 +275,7 @@
     HA_NOTIF_SMTP_PORT = 'smtp-port'
     HA_NOTIF_SMTP_SOURCE_EMAIL = 'source-email'
     HA_NOTIF_SMTP_DEST_EMAILS = 'destination-emails'
+    BLANK_UUID = '00000000-0000-0000-0000-000000000000'
 
 
 @util.export
diff --git a/src/ovirt_hosted_engine_setup/mixins.py 
b/src/ovirt_hosted_engine_setup/mixins.py
index ad2029b..c235655 100644
--- a/src/ovirt_hosted_engine_setup/mixins.py
+++ b/src/ovirt_hosted_engine_setup/mixins.py
@@ -1,6 +1,6 @@
 #
 # ovirt-hosted-engine-setup -- ovirt hosted engine setup
-# Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2013-2014 Red Hat, Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -36,18 +36,11 @@
     Hosted engine VM manipulation features for otopi Plugin objects
     """
 
+    POWER_MAX_TRIES = 10
+    POWER_DELAY = 1
     TICKET_MAX_TRIES = 10
     TICKET_DELAY = 1
     POWEROFF_CHECK_INTERVALL = 1
-
-    @property
-    def _vdscommand(self):
-        if not hasattr(self, '_vdscommand_val'):
-            self._vdscommand_val = [self.command.get('vdsClient')]
-            if self.environment[ohostedcons.VDSMEnv.USE_SSL]:
-                self._vdscommand_val.append('-s')
-            self._vdscommand_val.append('localhost')
-        return self._vdscommand_val
 
     def _generateTempVncPassword(self):
         self.logger.info(
@@ -61,18 +54,20 @@
     def _generateUserMessage(self, console_type):
         displayPort = 5900
         displaySecurePort = 5901
-        serv = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
+        cli = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
         try:
-            stats = serv.s.getVmStats(
+            stats = cli.getVmStats(
                 self.environment[ohostedcons.VMEnv.VM_UUID]
             )
             self.logger.debug(stats)
-            if not stats['status']['code'] == 0:
+            if stats['status']['code'] != 0:
                 self.logger.error(stats['status']['message'])
             else:
                 statsList = stats['statsList'][0]
-                displaySecurePort = statsList['displaySecurePort']
-                displayPort = statsList['displayPort']
+                displaySecurePort = statsList.get(
+                    'displaySecurePort', displaySecurePort
+                )
+                displayPort = statsList.get('displayPort', displayPort)
         except Exception:
             self.logger.debug(
                 'Error getting VM stats',
@@ -132,34 +127,170 @@
                 time.sleep(self.POWEROFF_CHECK_INTERVALL)
 
         self.logger.info(_('Creating VM'))
-        cmd = self._vdscommand + [
-            'create',
-            ohostedcons.FileLocations.ENGINE_VM_CONF,
-        ]
-        self.execute(
-            cmd,
-            raiseOnError=True
-        )
+        # TODO: check if we can move this to configurevm.py
+        # and get rid of the template.
+        conf = {
+            'vmId': self.environment[ohostedcons.VMEnv.VM_UUID],
+            'memSize': self.environment[ohostedcons.VMEnv.MEM_SIZE_MB],
+            'display': self.environment[ohostedcons.VMEnv.CONSOLE_TYPE],
+            'emulatedMachine': self.environment[
+                ohostedcons.VMEnv.EMULATED_MACHINE
+            ],
+            'cpuType': self.environment[
+                ohostedcons.VDSMEnv.VDSM_CPU
+            ].replace('model_', ''),
+            'spiceSecureChannels': (
+                'smain,sdisplay,sinputs,scursor,splayback,'
+                'srecord,ssmartcard,susbredir'
+            ),
+            'vmName': ohostedcons.Const.HOSTED_ENGINE_VM_NAME,
+            'smp': self.environment[ohostedcons.VMEnv.VCPUS],
+            'devices': [
+                {
+                    'device': 'scsi',
+                    'model': 'virtio-scsi',
+                    'type': 'controller'
+                },
+                {
+                    'device': 'console',
+                    'specParams': {},
+                    'type': 'console',
+                    'deviceId': self.environment[
+                        ohostedcons.VMEnv.CONSOLE_UUID
+                    ],
+                    'alias': 'console0'
+                },
+            ],
+        }
+        cdrom = {
+            'index': '2',
+            'iface': 'ide',
+            'address': {
+                'controller': '0',
+                'target': '0',
+                'unit': '0',
+                'bus': '1',
+                'type': 'drive'
+            },
+            'specParams': {},
+            'readonly': 'true',
+            'deviceId': self.environment[ohostedcons.VMEnv.CDROM_UUID],
+            'path': (
+                self.environment[ohostedcons.VMEnv.CDROM]
+                if self.environment[
+                    ohostedcons.VMEnv.CDROM
+                ] is not None
+                else ''
+            ),
+            'device': 'cdrom',
+            'shared': 'false',
+            'type': 'disk',
+        }
+        if self.environment[ohostedcons.VMEnv.BOOT] == 'cdrom':
+            cdrom['bootOrder'] = '1'
+        conf['devices'].append(cdrom)
+        disk = {
+            'index': '0',
+            'iface': 'virtio',
+            'format': 'raw',
+            'poolID': ohostedcons.Const.BLANK_UUID,
+            'volumeID': self.environment[ohostedcons.StorageEnv.VOL_UUID],
+            'imageID': self.environment[ohostedcons.StorageEnv.IMG_UUID],
+            'specParams': {},
+            'readonly': 'false',
+            'domainID': self.environment[ohostedcons.StorageEnv.SD_UUID],
+            'optional': 'false',
+            'deviceId': self.environment[ohostedcons.StorageEnv.IMG_UUID],
+            'address': {
+                'bus': '0x00',
+                'slot': '0x06',
+                'domain': '0x0000',
+                'type': 'pci',
+                'function': '0x0'
+            },
+            'device': 'disk',
+            'shared': 'exclusive',
+            'propagateErrors': 'off',
+            'type': 'disk',
+        }
+        if self.environment[ohostedcons.VMEnv.BOOT] == 'disk':
+            disk['bootOrder'] = '1'
+        conf['devices'].append(disk)
+        nic = {
+            'nicModel': 'pv',
+            'macAddr': self.environment[ohostedcons.VMEnv.MAC_ADDR],
+            'linkActive': 'true',
+            'network': self.environment[ohostedcons.NetworkEnv.BRIDGE_NAME],
+            'filter': 'vdsm-no-mac-spoofing',
+            'specParams': {},
+            'deviceId': self.environment[ohostedcons.VMEnv.NIC_UUID],
+            'address': {
+                'bus': '0x00',
+                'slot': '0x03',
+                'domain': '0x0000',
+                'type': 'pci',
+                'function': '0x0'
+            },
+            'device': 'bridge',
+            'type': 'interface',
+        }
+        if self.environment[ohostedcons.VMEnv.BOOT] == 'pxe':
+            nic['bootOrder'] = '1'
+        conf['devices'].append(nic)
+
+        cli = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
+        status = cli.create(conf)
+        self.logger.debug(status)
+        if status['status']['code'] != 0:
+            raise RuntimeError(
+                _(
+                    'Cannot create the VM: {message}'
+                ).format(
+                    message=status['status']['message']
+                )
+            )
+        # Now it's in WaitForLaunch, need to be on powering up
+        powering = False
+        tries = self.POWER_MAX_TRIES
+        while not powering and tries > 0:
+            tries -= 1
+            stats = cli.getVmStats(
+                self.environment[ohostedcons.VMEnv.VM_UUID]
+            )
+            self.logger.debug(stats)
+            if stats['status']['code'] != 0:
+                raise RuntimeError(stats['status']['message'])
+            else:
+                statsList = stats['statsList'][0]
+                if statsList['status'] in ('Powering up', 'Up'):
+                    powering = True
+                elif statsList['status'] == 'Down':
+                    # VM creation failure
+                    tries = 0
+                else:
+                    time.sleep(self.POWER_DELAY)
+        if not powering:
+            raise RuntimeError(
+                _(
+                    'The VM is not powering up: please check VDSM logs'
+                )
+            )
+
         password_set = False
         tries = self.TICKET_MAX_TRIES
         while not password_set and tries > 0:
             tries -= 1
-            try:
-                cmd = self._vdscommand + [
-                    'setVmTicket',
-                    self.environment[ohostedcons.VMEnv.VM_UUID],
-                    self.environment[ohostedcons.VMEnv.VM_PASSWD],
-                    self.environment[
-                        ohostedcons.VMEnv.VM_PASSWD_VALIDITY_SECS
-                    ],
-                ]
-                self.execute(
-                    cmd,
-                    raiseOnError=True
-                )
+            status = cli.setVmTicket(
+                self.environment[ohostedcons.VMEnv.VM_UUID],
+                self.environment[ohostedcons.VMEnv.VM_PASSWD],
+                self.environment[
+                    ohostedcons.VMEnv.VM_PASSWD_VALIDITY_SECS
+                ],
+            )
+            self.logger.debug(status)
+            if status['status']['code'] == 0:
                 password_set = True
-            except RuntimeError as e:
-                self.logger.debug(str(e))
+            else:
                 time.sleep(self.TICKET_DELAY)
         if not password_set:
             raise RuntimeError(
@@ -218,11 +349,9 @@
             )
 
     def _destroy_vm(self):
-        cmd = self._vdscommand + [
-            'destroy',
-            self.environment[ohostedcons.VMEnv.VM_UUID]
-        ]
-        self.execute(cmd, raiseOnError=True)
+        cli = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
+        res = cli.destroy(self.environment[ohostedcons.VMEnv.VM_UUID])
+        self.logger.info(res)
 
     def _wait_vm_destroyed(self):
         waiter = tasks.VMDownWaiter(self.environment)
diff --git a/src/ovirt_hosted_engine_setup/tasks.py 
b/src/ovirt_hosted_engine_setup/tasks.py
index b988b73..1005f00 100644
--- a/src/ovirt_hosted_engine_setup/tasks.py
+++ b/src/ovirt_hosted_engine_setup/tasks.py
@@ -42,11 +42,11 @@
         self.environment = environment
 
     def wait(self):
-        serv = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
+        cli = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
         wait = True
         while wait:
             self.logger.debug('Waiting for existing tasks to complete')
-            statuses = serv.s.getAllTasksStatuses()
+            statuses = cli.getAllTasksStatuses()
             code = statuses['status']['code']
             message = statuses['status']['message']
             if code != 0:
@@ -63,7 +63,7 @@
                 if tasksStatuses[taskID]['taskState'] != 'finished':
                     all_completed = False
                 else:
-                    serv.clearTask([taskID])
+                    cli.clearTask(taskID)
             if all_completed:
                 wait = False
             else:
@@ -83,13 +83,13 @@
         self.environment = environment
 
     def wait(self):
-        serv = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
+        cli = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
         down = False
         destroyed = False
         while not down:
             time.sleep(self.POLLING_INTERVAL)
             self.logger.debug('Waiting for VM down')
-            response = serv.s.getVmStats(
+            response = cli.getVmStats(
                 self.environment[ohostedcons.VMEnv.VM_UUID]
             )
             code = response['status']['code']
@@ -120,12 +120,12 @@
         self.environment = environment
 
     def wait(self, sdUUID):
-        serv = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
+        cli = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
         acquired = False
         while not acquired:
             time.sleep(self.POLLING_INTERVAL)
             self.logger.debug('Waiting for domain monitor')
-            response = serv.s.getVdsStats()
+            response = cli.getVdsStats()
             self.logger.debug(response)
             if response['status']['code'] != 0:
                 self.logger.debug(response['status']['message'])
diff --git a/src/plugins/ovirt-hosted-engine-setup/ha/ha_services.py 
b/src/plugins/ovirt-hosted-engine-setup/ha/ha_services.py
index ce3f9b4..06e87f7 100644
--- a/src/plugins/ovirt-hosted-engine-setup/ha/ha_services.py
+++ b/src/plugins/ovirt-hosted-engine-setup/ha/ha_services.py
@@ -102,18 +102,17 @@
             waiter = tasks.VMDownWaiter(self.environment)
             if not waiter.wait():
                 # The VM is down but not destroyed
-                vdscommand = [self.command.get('vdsClient')]
-                if self.environment[ohostedcons.VDSMEnv.USE_SSL]:
-                    vdscommand.append('-s')
-                vdscommand += [
-                    'localhost',
-                    'destroy',
-                    self.environment[ohostedcons.VMEnv.VM_UUID],
-                ]
-                self.execute(
-                    vdscommand,
-                    raiseOnError=True
+                status, msg = self.environment[
+                    ohostedcons.VDSMEnv.VDS_CLI
+                ].destroy(
+                    self.environment[ohostedcons.VMEnv.VM_UUID]
                 )
+                self.logger.debug(msg)
+                if status != 0:
+                    self.logger.error(
+                        _('Cannot destroy the Hosted Engine VM')
+                    )
+
         self.logger.info(_('Enabling and starting HA services'))
         for service in (
             ohostedcons.Const.HA_AGENT_SERVICE,
@@ -128,4 +127,5 @@
                 state=True,
             )
 
+
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/plugins/ovirt-hosted-engine-setup/network/bridge.py 
b/src/plugins/ovirt-hosted-engine-setup/network/bridge.py
index b62d21f..dc49488 100644
--- a/src/plugins/ovirt-hosted-engine-setup/network/bridge.py
+++ b/src/plugins/ovirt-hosted-engine-setup/network/bridge.py
@@ -83,8 +83,6 @@
                 )
             )
             self._enabled = False
-        else:
-            self.command.detect('vdsClient')
 
     @plugin.event(
         stage=plugin.Stages.STAGE_CUSTOMIZATION,
diff --git a/src/plugins/ovirt-hosted-engine-setup/storage/iscsi.py 
b/src/plugins/ovirt-hosted-engine-setup/storage/iscsi.py
index 8903a56..15ec573 100644
--- a/src/plugins/ovirt-hosted-engine-setup/storage/iscsi.py
+++ b/src/plugins/ovirt-hosted-engine-setup/storage/iscsi.py
@@ -52,11 +52,7 @@
     def __init__(self, context):
         super(Plugin, self).__init__(context=context)
         self._interactive = False
-        self.serv = None
-        self.vdsClient = util.loadModule(
-            path=ohostedcons.FileLocations.VDS_CLIENT_DIR,
-            name='vdsClient'
-        )
+        self.cli = None
 
     def _customize_ip_address(self):
         valid = False
@@ -229,7 +225,7 @@
         return str(lun)
 
     def _iscsi_discovery(self, address, port, user, password):
-        targets = self.serv.s.discoverSendTargets(
+        targets = self.cli.discoverSendTargets(
             {
                 'connection': address,
                 'port': port,
@@ -246,7 +242,7 @@
         retry = self._MAXRETRY
         iscsi_lun_list = []
         for _try in range(0, retry):
-            devices = self.serv.s.getDeviceList(
+            devices = self.cli.getDeviceList(
                 ohostedcons.VDSMConstants.ISCSI_DOMAIN
             )
             self.logger.debug(devices)
@@ -267,9 +263,9 @@
                 password,
             )
             self.logger.info('Connecting to the storage server')
-            res = self.serv.s.connectStorageServer(
+            res = self.cli.connectStorageServer(
                 ohostedcons.VDSMConstants.ISCSI_DOMAIN,
-                self.vdsClient.BLANK_UUID,
+                ohostedcons.Const.BLANK_UUID,
                 [
                     {
                         'connection': ip,
@@ -278,7 +274,7 @@
                         'user': user,
                         'password': password,
                         'port': port,
-                        'id': self.vdsClient.BLANK_UUID,
+                        'id': ohostedcons.Const.BLANK_UUID,
                     }
                 ]
             )
@@ -410,7 +406,7 @@
         ),
     )
     def _customization(self):
-        self.serv = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
+        self.cli = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
         valid_access = False
         valid_lun = False
         address = None
@@ -490,7 +486,7 @@
         if self.environment[ohostedcons.StorageEnv.VG_UUID] is None:
             # If we don't have a volume group we must create it
             self.logger.info(_('Creating Volume Group'))
-            dom = self.serv.s.createVG(
+            dom = self.cli.createVG(
                 self.environment[ohostedcons.StorageEnv.SD_UUID],
                 [
                     iscsi_device['GUID'],
@@ -504,7 +500,7 @@
                 ohostedcons.StorageEnv.VG_UUID
             ] = dom['uuid']
 
-        vginfo = self.serv.s.getVGInfo(
+        vginfo = self.cli.getVGInfo(
             self.environment[ohostedcons.StorageEnv.VG_UUID]
         )
         self.logger.debug(vginfo)
diff --git a/src/plugins/ovirt-hosted-engine-setup/storage/storage.py 
b/src/plugins/ovirt-hosted-engine-setup/storage/storage.py
index 89c1b9f..2ec7b18 100644
--- a/src/plugins/ovirt-hosted-engine-setup/storage/storage.py
+++ b/src/plugins/ovirt-hosted-engine-setup/storage/storage.py
@@ -61,11 +61,7 @@
 
     def __init__(self, context):
         super(Plugin, self).__init__(context=context)
-        self.vdsClient = util.loadModule(
-            path=ohostedcons.FileLocations.VDS_CLIENT_DIR,
-            name='vdsClient'
-        )
-        self.serv = None
+        self.cli = None
         self.waiter = None
         self.storageType = None
         self.protocol_version = None
@@ -284,7 +280,7 @@
             ohostedcons.VDSMConstants.ISCSI_DOMAIN,
         ):
             if self.environment[ohostedcons.StorageEnv.VG_UUID] is not None:
-                vginfo = self.serv.s.getVGInfo(
+                vginfo = self.cli.getVGInfo(
                     self.environment[ohostedcons.StorageEnv.VG_UUID]
                 )
                 if vginfo['status']['code'] != 0:
@@ -370,10 +366,10 @@
 
     def _getStorageDomainsList(self, spUUID=None):
         if not spUUID:
-            spUUID = self.vdsClient.BLANK_UUID
+            spUUID = ohostedcons.Const.BLANK_UUID
         self.logger.debug('getStorageDomainsList')
         domains = []
-        response = self.serv.s.getStorageDomainsList(spUUID)
+        response = self.cli.getStorageDomainsList(spUUID)
         self.logger.debug(response)
         if response['status']['code'] == 0:
             for entry in response['domlist']:
@@ -383,7 +379,7 @@
     def _getStorageDomainInfo(self, sdUUID):
         self.logger.debug('getStorageDomainInfo')
         info = {}
-        response = self.serv.s.getStorageDomainInfo(sdUUID)
+        response = self.cli.getStorageDomainInfo(sdUUID)
         self.logger.debug(response)
         if response['status']['code'] == 0:
             for key, respinfo in response['info'].iteritems():
@@ -393,7 +389,7 @@
     def _getStoragePoolInfo(self, spUUID):
         self.logger.debug('getStoragePoolInfo')
         info = {}
-        response = self.serv.s.getStoragePoolInfo(spUUID)
+        response = self.cli.getStoragePoolInfo(spUUID)
         self.logger.debug(response)
         if response['status']['code'] == 0:
             for key in response['info'].keys():
@@ -401,13 +397,13 @@
         return info
 
     def _storageServerConnection(self, disconnect=False):
-        method = self.serv.s.connectStorageServer
+        method = self.cli.connectStorageServer
         debug_msg = 'connectStorageServer'
         if disconnect:
-            method = self.serv.s.disconnectStorageServer
+            method = self.cli.disconnectStorageServer
             debug_msg = 'disconnectStorageServer'
         self.logger.debug(debug_msg)
-        spUUID = self.vdsClient.BLANK_UUID
+        spUUID = ohostedcons.Const.BLANK_UUID
         conList = None
         if self.storageType in (
             ohostedcons.VDSMConstants.NFS_DOMAIN,
@@ -495,19 +491,19 @@
             raise RuntimeError(_('Invalid Storage Type'))
         domainType = ohostedcons.VDSMConstants.DATA_DOMAIN
         version = 3
-        status, message = self.serv.createStorageDomain(args=[
+        status = self.cli.createStorageDomain(
             self.storageType,
             sdUUID,
             domainName,
             typeSpecificArgs,
             domainType,
             version
-        ])
-        if status != 0:
-            raise RuntimeError(message)
-        self.logger.debug(self.serv.s.repoStats())
+        )
+        if status['status']['code'] != 0:
+            raise RuntimeError(status['status']['message'])
+        self.logger.debug(self.cli.repoStats())
         self.logger.debug(
-            self.serv.s.getStorageDomainStats(sdUUID)
+            self.cli.getStorageDomainStats(sdUUID)
         )
 
     def _createStoragePool(self):
@@ -519,22 +515,23 @@
             ohostedcons.StorageEnv.STORAGE_DATACENTER_NAME
         ]
         masterDom = sdUUID
-        domList = sdUUID  # str: domain,domain,...
+        domList = [sdUUID]
         mVer = 1
-        status, message = self.serv.createStoragePool(args=[
+        status = self.cli.createStoragePool(
             poolType,
             spUUID,
             poolName,
             masterDom,
             domList,
             mVer
-        ])
-        if status != 0:
-            raise RuntimeError(message)
+        )
+        self.logger.debug(status)
+        if status['status']['code'] != 0:
+            raise RuntimeError(status['status']['message'])
 
     def _startMonitoringDomain(self):
         self.logger.debug('_startMonitoringDomain')
-        status = self.serv.s.startMonitoringDomain(
+        status = self.cli.startMonitoringDomain(
             self.environment[ohostedcons.StorageEnv.SD_UUID],
             self.environment[ohostedcons.StorageEnv.HOST_ID]
         )
@@ -547,7 +544,7 @@
 
     def _stopMonitoringDomain(self):
         self.logger.debug('_stopMonitoringDomain')
-        status = self.serv.s.stopMonitoringDomain(
+        status = self.cli.stopMonitoringDomain(
             self.environment[ohostedcons.StorageEnv.SD_UUID],
             self.environment[ohostedcons.StorageEnv.HOST_ID]
         )
@@ -562,7 +559,7 @@
         scsi_key = spUUID
         master = sdUUID
         master_ver = 1
-        method = self.serv.connectStoragePool
+        method = self.cli.connectStoragePool
         method_args = [
             spUUID,
             ID,
@@ -570,7 +567,7 @@
         ]
         debug_msg = 'connectStoragePool'
         if disconnect:
-            method = self.serv.disconnectStoragePool
+            method = self.cli.disconnectStoragePool
             debug_msg = 'disconnectStoragePool'
         else:
             method_args += [
@@ -578,9 +575,9 @@
                 master_ver,
             ]
         self.logger.debug(debug_msg)
-        status, message = method(args=method_args)
-        if status != 0:
-            raise RuntimeError(message)
+        status = method(*method_args)
+        if status['status']['code'] != 0:
+            raise RuntimeError(status['status']['message'])
         self._connected = not disconnect
 
     def _spmStart(self):
@@ -592,7 +589,7 @@
         scsiFencing = 'false'
         maxHostID = ohostedcons.Const.MAX_HOST_ID
         version = 3
-        status, status_uuid = self.serv.spmStart(args=[
+        status = self.cli.spmStart(
             spUUID,
             prevID,
             prevLVER,
@@ -600,43 +597,41 @@
             scsiFencing,
             maxHostID,
             version
-        ])
-        if status != 0:
-            raise RuntimeError(status_uuid)
-        self.logger.debug(status_uuid)
+        )
+        self.logger.debug(status)
+        if status['status']['code'] != 0:
+            raise RuntimeError(status['status']['message'])
 
     def _spmStop(self):
         self.logger.debug('spmStop')
         spUUID = self.environment[ohostedcons.StorageEnv.SP_UUID]
-        status, status_uuid = self.serv.spmStop(
-            args=[
-                spUUID,
-            ],
+        status = self.cli.spmStop(
+            spUUID,
         )
-        if status != 0:
-            raise RuntimeError(status_uuid)
-        self.logger.debug(status_uuid)
+        self.logger.debug(status)
+        if status['status']['code'] != 0:
+            raise RuntimeError(status['status']['message'])
 
     def _activateStorageDomain(self):
         self.logger.debug('activateStorageDomain')
         sdUUID = self.environment[ohostedcons.StorageEnv.SD_UUID]
         spUUID = self.environment[ohostedcons.StorageEnv.SP_UUID]
-        status, message = self.serv.activateStorageDomain(args=[
+        status = self.cli.activateStorageDomain(
             sdUUID,
             spUUID
-        ])
-        if status != 0:
-            raise RuntimeError(message)
+        )
+        if status['status']['code'] != 0:
+            raise RuntimeError(status['status']['message'])
         self.waiter.wait()
-        self.logger.debug(self.serv.s.getSpmStatus(spUUID))
-        info = self.serv.s.getStoragePoolInfo(spUUID)
+        self.logger.debug(self.cli.getSpmStatus(spUUID))
+        info = self.cli.getStoragePoolInfo(spUUID)
         self.logger.debug(info)
-        self.logger.debug(self.serv.s.repoStats())
+        self.logger.debug(self.cli.repoStats())
 
     def _check_existing_pools(self):
         self.logger.debug('_check_existing_pools')
         self.logger.debug('getConnectedStoragePoolsList')
-        pools = self.serv.s.getConnectedStoragePoolsList()
+        pools = self.cli.getConnectedStoragePoolsList()
         self.logger.debug(pools)
         if pools['status']['code'] != 0:
             raise RuntimeError(pools['status']['message'])
@@ -815,7 +810,7 @@
                 'During customization use CTRL-D to abort.'
             )
         )
-        self.serv = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
+        self.cli = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
         self._check_existing_pools()
         domain_type = self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE]
         if domain_type is None:
@@ -889,7 +884,7 @@
     )
     def _misc(self):
         self.waiter = tasks.TaskWaiter(self.environment)
-        self.serv = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
+        self.cli = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
         self._check_existing_pools()
         if self.storageType in (
             ohostedcons.VDSMConstants.NFS_DOMAIN,
@@ -905,7 +900,7 @@
         elif self.storageType in (
             ohostedcons.VDSMConstants.ISCSI_DOMAIN,
         ):
-            devices = self.serv.s.getDeviceList(
+            devices = self.cli.getDeviceList(
                 ohostedcons.VDSMConstants.ISCSI_DOMAIN
             )
             self.logger.debug(devices)
diff --git a/src/plugins/ovirt-hosted-engine-setup/system/vdsmenv.py 
b/src/plugins/ovirt-hosted-engine-setup/system/vdsmenv.py
index 60cbd91..c0178f8 100644
--- a/src/plugins/ovirt-hosted-engine-setup/system/vdsmenv.py
+++ b/src/plugins/ovirt-hosted-engine-setup/system/vdsmenv.py
@@ -50,32 +50,14 @@
         super(Plugin, self).__init__(context=context)
 
     def _connect(self):
-        vdsClient = util.loadModule(
-            path=ohostedcons.FileLocations.VDS_CLIENT_DIR,
-            name='vdsClient'
-        )
-        serv = None
-        if vdsClient._glusterEnabled:
-            serv = vdsClient.ge.GlusterService()
-        else:
-            serv = vdsClient.service()
-        serv.useSSL = self.environment[ohostedcons.VDSMEnv.USE_SSL]
-        if hasattr(vdscli, 'cannonizeAddrPort'):
-            server, serverPort = vdscli.cannonizeAddrPort(
-                'localhost'
-            ).split(':', 1)
-            serv.do_connect(server, serverPort)
-        else:
-            hostPort = vdscli.cannonizeHostPort('localhost')
-            serv.do_connect(hostPort)
-
-        self.environment[ohostedcons.VDSMEnv.VDS_CLI] = serv
+        cli = vdscli.connect()
+        self.environment[ohostedcons.VDSMEnv.VDS_CLI] = cli
         vdsmReady = False
         retry = 0
         while not vdsmReady and retry < self.MAX_RETRY:
             retry += 1
             try:
-                hwinfo = serv.s.getVdsHardwareInfo()
+                hwinfo = cli.getVdsHardwareInfo()
                 self.logger.debug(str(hwinfo))
                 if hwinfo['status']['code'] == 0:
                     vdsmReady = True
diff --git a/src/plugins/ovirt-hosted-engine-setup/vm/boot_disk.py 
b/src/plugins/ovirt-hosted-engine-setup/vm/boot_disk.py
index b40af8d..f514df1 100644
--- a/src/plugins/ovirt-hosted-engine-setup/vm/boot_disk.py
+++ b/src/plugins/ovirt-hosted-engine-setup/vm/boot_disk.py
@@ -115,8 +115,8 @@
         info = json.decoder.JSONDecoder().decode('\n'.join(stdout))
         source_size = int(info['virtual-size'])
 
-        serv = self._parent.environment[ohostedcons.VDSMEnv.VDS_CLI]
-        size = serv.s.getVolumeSize(
+        cli = self._parent.environment[ohostedcons.VDSMEnv.VDS_CLI]
+        size = cli.getVolumeSize(
             self._parent.environment[ohostedcons.StorageEnv.SD_UUID],
             self._parent.environment[ohostedcons.StorageEnv.SP_UUID],
             self._parent.environment[ohostedcons.StorageEnv.IMG_UUID],
diff --git a/src/plugins/ovirt-hosted-engine-setup/vm/configurevm.py 
b/src/plugins/ovirt-hosted-engine-setup/vm/configurevm.py
index e65095e..9208f80 100644
--- a/src/plugins/ovirt-hosted-engine-setup/vm/configurevm.py
+++ b/src/plugins/ovirt-hosted-engine-setup/vm/configurevm.py
@@ -1,6 +1,6 @@
 #
 # ovirt-hosted-engine-setup -- ovirt hosted engine setup
-# Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2013-2014 Red Hat, Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -55,10 +55,6 @@
 
     def __init__(self, context):
         super(Plugin, self).__init__(context=context)
-        self.vdsClient = util.loadModule(
-            path=ohostedcons.FileLocations.VDS_CLIENT_DIR,
-            name='vdsClient'
-        )
 
     @plugin.event(
         stage=plugin.Stages.STAGE_INIT,
@@ -95,8 +91,8 @@
         name=ohostedcons.Stages.VDSMD_LATE_SETUP_READY,
     )
     def _late_setup(self):
-        serv = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
-        response = serv.s.list()
+        cli = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
+        response = cli.list()
         if response['status']['code'] == 0:
             self.logger.debug(response['vmList'])
             if response['vmList']:
@@ -180,7 +176,7 @@
     def _misc(self):
         self.logger.info(_('Configuring VM'))
         subst = {
-            '@SP_UUID@': self.vdsClient.BLANK_UUID,
+            '@SP_UUID@': ohostedcons.Const.BLANK_UUID,
             '@SD_UUID@': self.environment[
                 ohostedcons.StorageEnv.SD_UUID
             ],
diff --git a/src/plugins/ovirt-hosted-engine-setup/vm/image.py 
b/src/plugins/ovirt-hosted-engine-setup/vm/image.py
index dba5863..af4dc8b 100644
--- a/src/plugins/ovirt-hosted-engine-setup/vm/image.py
+++ b/src/plugins/ovirt-hosted-engine-setup/vm/image.py
@@ -158,7 +158,7 @@
         spUUID = self.environment[ohostedcons.StorageEnv.SP_UUID]
         imgUUID = self.environment[ohostedcons.StorageEnv.IMG_UUID]
         volUUID = self.environment[ohostedcons.StorageEnv.VOL_UUID]
-        serv = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
+        cli = self.environment[ohostedcons.VDSMEnv.VDS_CLI]
         self.logger.info(_('Creating VM Image'))
         self.logger.debug('createVolume')
         volFormat = ohostedcons.VolumeFormat.RAW_FORMAT
@@ -170,7 +170,7 @@
             preallocate = ohostedcons.VolumeTypes.PREALLOCATED_VOL
 
         diskType = 2
-        status, message = serv.createVolume([
+        status = cli.createVolume(
             sdUUID,
             spUUID,
             imgUUID,
@@ -180,21 +180,22 @@
             diskType,
             volUUID,
             self.environment[ohostedcons.StorageEnv.IMAGE_DESC],
-        ])
-        if status == 0:
+        )
+        self.logger.debug(status)
+        if status['status']['code'] == 0:
             self.logger.debug(
                 (
                     'Created volume {newUUID}, request was:\n'
                     '- image: {imgUUID}\n'
                     '- volume: {volUUID}'
                 ).format(
-                    newUUID=message,
+                    newUUID=status['status']['message'],
                     imgUUID=imgUUID,
                     volUUID=volUUID,
                 )
             )
         else:
-            raise RuntimeError(message)
+            raise RuntimeError(status['status']['message'])
         waiter = tasks.TaskWaiter(self.environment)
         waiter.wait()
 
diff --git a/src/plugins/ovirt-hosted-engine-setup/vm/runvm.py 
b/src/plugins/ovirt-hosted-engine-setup/vm/runvm.py
index 243dc6f..e31da2b 100644
--- a/src/plugins/ovirt-hosted-engine-setup/vm/runvm.py
+++ b/src/plugins/ovirt-hosted-engine-setup/vm/runvm.py
@@ -70,8 +70,6 @@
         stage=plugin.Stages.STAGE_SETUP,
     )
     def _setup(self):
-        # Can't use python api here, it will call sys.exit
-        self.command.detect('vdsClient')
         self.command.detect('remote-viewer')
 
     @plugin.event(


-- 
To view, visit http://gerrit.ovirt.org/33996
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0f17abcc4ec83a69832bdb5a986136831504da2c
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-hosted-engine-setup
Gerrit-Branch: master
Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to