Change in vdsm[master]: getExternalVmList

shavivi at redhat.com shavivi at redhat.com
Wed Sep 24 07:12:23 UTC 2014


Shahar Havivi has uploaded a new change for review.

Change subject: getExternalVmList
......................................................................

getExternalVmList

Change-Id: I7dcfb860626a844d1d08590274b508519a33f4a3
Signed-off-by: Shahar Havivi <shaharh at redhat.com>
---
M client/vdsClient.py
M lib/vdsm/define.py
M vdsm.spec.in
M vdsm/API.py
M vdsm/Makefile.am
M vdsm/rpc/BindingXMLRPC.py
M vdsm/rpc/Bridge.py
M vdsm/rpc/vdsmapi-schema.json
A vdsm/v2v.py
9 files changed, 182 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/09/33309/1

diff --git a/client/vdsClient.py b/client/vdsClient.py
index dafca9e..de0055b 100644
--- a/client/vdsClient.py
+++ b/client/vdsClient.py
@@ -1889,6 +1889,20 @@
 
         return status['status']['code'], status['status']['message']
 
+    def getExternalVMList(self, args):
+        if len(args) != 3:
+            raise ValueError('Wrong number of arguments')
+        uri, username, password = args
+        status = self.s.getExternalVMList(uri, username, password)
+        if status['status']['code'] == 0:
+            vmList = status['vmList']
+            for vm in vmList:
+                for key in vm.keys():
+                    print key + ': ' + str(vm[key])
+
+        return status['status']['code'], status['status']['message']
+
+
 if __name__ == '__main__':
     if _glusterEnabled:
         serv = ge.GlusterService()
@@ -2727,6 +2741,11 @@
                 '<vmId> <vcpuLimit>',
                 'set SLA parameter for a VM'
             )),
+        'externalVMList': (
+            serv.getExternalVMList, (
+                '<uri> <username> <password>',
+                'get VMs from external hypervisor'
+            )),
     }
     if _glusterEnabled:
         commands.update(ge.getGlusterCmdDict(serv))
diff --git a/lib/vdsm/define.py b/lib/vdsm/define.py
index 34f423a..0b4c77f 100644
--- a/lib/vdsm/define.py
+++ b/lib/vdsm/define.py
@@ -147,6 +147,9 @@
     'updateIoTuneErr': {'status': {
         'code': 64,
         'message': 'Failed to update ioTune values'}},
+    'externalErr': {'status': {
+        'code': 65,
+        'message': 'Failed to connect to external hypervisor'}},
     'recovery': {'status': {
         'code': 99,
         'message': 'Recovering from crash or Initializing'}},
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 8438df7..cbab18d 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -956,6 +956,7 @@
 %{_datadir}/%{vdsm_name}/protocoldetector.py*
 %{_datadir}/%{vdsm_name}/supervdsm.py*
 %{_datadir}/%{vdsm_name}/supervdsmServer
+%{_datadir}/%{vdsm_name}/v2v.py*
 %{_datadir}/%{vdsm_name}/vdsm
 %{_datadir}/%{vdsm_name}/vdsm-restore-net-config
 %{_datadir}/%{vdsm_name}/vdsm-store-net-config
diff --git a/vdsm/API.py b/vdsm/API.py
index 9c47b5f..6d13b19 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -52,6 +52,7 @@
 from vdsm.config import config
 import hooks
 from caps import PAGE_SIZE_BYTES
+import v2v
 
 import supervdsm
 
@@ -1377,6 +1378,17 @@
                            for v in self._cif.vmContainer.values()
                            if not vmSet or v.id in vmSet]}
 
+    def getExternalVMList(self, uri, username, password):
+        "return information about the not-KVM virtual machines"
+        vms = v2v.getExternalVMList(uri, username, password)
+        if vms is None:
+            return errCode['externalErr']
+        return {'status': doneCode, 'vmList': vms}
+
+    def convertVmFromExternalSystem(self, uri, username, password,
+                                    vmProperties, jobId):
+        return {'status': doneCode}
+
     # Networking-related functions
     def setupNetworks(self, networks, bondings, options):
         """Add a new network to this vds, replacing an old one."""
diff --git a/vdsm/Makefile.am b/vdsm/Makefile.am
index 1c42fdf..a2d1111 100644
--- a/vdsm/Makefile.am
+++ b/vdsm/Makefile.am
@@ -41,6 +41,7 @@
 	ppc64HardwareInfo.py \
 	protocoldetector.py \
 	supervdsm.py \
+	v2v.py \
 	vdsmDebugPlugin.py \
 	$(NULL)
 
diff --git a/vdsm/rpc/BindingXMLRPC.py b/vdsm/rpc/BindingXMLRPC.py
index f2dcbdf..2f886cf 100644
--- a/vdsm/rpc/BindingXMLRPC.py
+++ b/vdsm/rpc/BindingXMLRPC.py
@@ -361,6 +361,16 @@
         api = API.Global()
         return api.getVMList(fullStatus, vmList)
 
+    def getExternalVMList(self, uri, username, password):
+        api = API.Global()
+        return api.getExternalVMList(uri, username, password)
+
+    def convertVmFromExternalSystem(self, uri, username, password,
+                                    vmProperties, jobId):
+        api = API.Global()
+        return api.getExternalVMList(uri, username, password,
+                                     vmProperties, jobId)
+
     def vmPause(self, vmId):
         vm = API.VM(vmId)
         return vm.pause()
@@ -1035,7 +1045,8 @@
                 (self.merge, 'merge'),
                 (self.vmUpdateVmPolicy, 'updateVmPolicy'),
                 (self.vmSetIoTune, 'setIoTune'),
-                (self.vmGetIoTunePolicy, 'getIoTunePolicy'))
+                (self.vmGetIoTunePolicy, 'getIoTunePolicy'),
+                (self.getExternalVMList, 'getExternalVMList'))
 
     def getIrsMethods(self):
         return ((self.domainActivate, 'activateStorageDomain'),
diff --git a/vdsm/rpc/Bridge.py b/vdsm/rpc/Bridge.py
index 608e95d..b355dc8 100644
--- a/vdsm/rpc/Bridge.py
+++ b/vdsm/rpc/Bridge.py
@@ -314,6 +314,28 @@
     return API.Global().getVMList(False, vmList)
 
 
+def Host_getExternalVMList_Call(api, args):
+    """
+    Return map of names to status of vm from non-KVM source
+    """
+    uri = args.get('uri', None)
+    username = args.get('username', None)
+    password = args.get('password', None)
+    return API.Global().getExternalVMList(uri, username, password)
+
+
+def Host_convertVmFromExternalSystem(api, args):
+    """
+    """
+    uri = args.get('uri', None)
+    username = args.get('username', None)
+    password = args.get('password', None)
+    vmProperties = args.get('vmProperties', None)
+    jobId = args.get('jobId', None)
+    return API.Global().convertVmFromExternalSystem(uri, username, password,
+                                                    vmProperties, jobId)
+
+
 def Host_getVMFullList_Call(api, args):
     """
     This call is interested in returning full status.
@@ -329,6 +351,13 @@
     return [v['vmId'] for v in ret['vmList']]
 
 
+def Host_getExternalVMList_Ret(ret):
+    """
+    Just return a map of names to status
+    """
+    return ret['vmList']
+
+
 def StoragePool_getInfo_Ret(ret):
     """
     The result contains two data structures which must be merged
diff --git a/vdsm/rpc/vdsmapi-schema.json b/vdsm/rpc/vdsmapi-schema.json
index 426d28e..0dc733a 100644
--- a/vdsm/rpc/vdsmapi-schema.json
+++ b/vdsm/rpc/vdsmapi-schema.json
@@ -3548,6 +3548,70 @@
  'returns': ['UUID']}
 
 ##
+# @ExternalVmInfo:
+#
+# map of VM names to status
+#
+# @name:  The name of the VM
+# @status:  The VM status
+#
+# Since: 4.17.0
+##
+{'type': 'ExternalVmInfo',
+ 'data': {'name': 'str', 'status': 'str'}}
+
+
+##
+# @Host.getExternalVMList:
+#
+# Get information about the not-KVM virtual machines.
+#
+# @uri: libvirt connection uri
+#
+# @username: libvirt connection user name
+#
+# @password: libvirt connection password
+#
+# Returns:
+# A map of VM names to status
+#
+# Since: 4.17.0
+##
+{'command': {'class': 'Host', 'name': 'getExternalVMList'},
+  'data': {'uri': 'str', 'username': 'str', 'password': 'str'},
+  'returns': ['ExternalVmInfo']}
+
+##
+# @VmProperties:
+#
+# A mapping of Vm properties
+#
+# Since: 4.17.0
+##
+{'map': 'VmProperties',
+ 'key': 'str', 'value': 'str'}
+
+##
+# @Host.convertVmFromExternalSystem:
+#
+# Import non-KVM virtual machine to data domain
+#
+# @uri: libvirt connection uri
+#
+# @username: libvirt connection user name
+#
+# @password: libvirt connection password
+#
+# @vmProperties: vm custom properties
+#
+# @jobId: uuid of the job
+#
+# Since: 4.17.0
+##
+{'command': {'class': 'Host', 'name': 'convertVmFromExternalSystem'},
+  'data': {'uri': 'str', 'username': 'str', 'password': 'str', 'vmProperties': 'VmProperties', 'jobId': 'UUID'}}
+
+##
 # @VMFullInfo:
 #
 # Full information about VM.
diff --git a/vdsm/v2v.py b/vdsm/v2v.py
new file mode 100644
index 0000000..5ef9362
--- /dev/null
+++ b/vdsm/v2v.py
@@ -0,0 +1,41 @@
+import libvirt
+import logging
+
+from virt import vmstatus
+
+vmStatus = {libvirt.VIR_DOMAIN_NOSTATE: 'Unknown',
+            libvirt.VIR_DOMAIN_RUNNING: vmstatus.UP,
+            libvirt.VIR_DOMAIN_BLOCKED: 'Blocked',
+            libvirt.VIR_DOMAIN_PAUSED: vmstatus.PAUSED,
+            libvirt.VIR_DOMAIN_SHUTDOWN: vmstatus.POWERING_DOWN,
+            libvirt.VIR_DOMAIN_SHUTOFF: vmstatus.DOWN,
+            libvirt.VIR_DOMAIN_CRASHED: 'Crushed',
+            libvirt.VIR_DOMAIN_PMSUSPENDED: 'PMSuspend'}
+
+
+def getExternalVMList(uri, username, password):
+    """ return external VMs with its state (up/down...) given uri """
+    def req(credentials, user_data):
+        for cred in credentials:
+            if cred[0] == libvirt.VIR_CRED_AUTHNAME:
+                cred[4] = username
+            elif cred[0] == libvirt.VIR_CRED_PASSPHRASE:
+                cred[4] = password
+        return 0
+
+    auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE],
+            req, None]
+    try:
+        conn = libvirt.openAuth(uri, auth, 0)
+    except libvirt.libvirtError as e:
+        logging.error(
+            'v2v.getExternalVMList: error connection to remove server: %s'
+            % e.message)
+        return None
+
+    ret = []
+    for vm in conn.listAllDomains():
+        params = {'vmName': vm.name(),
+                  'status': vmStatus[vm.state()[0]]}
+        ret.append(params)
+    return ret


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7dcfb860626a844d1d08590274b508519a33f4a3
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Shahar Havivi <shavivi at redhat.com>


More information about the vdsm-patches mailing list