X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=RO-VIM-vmware%2Fosm_rovim_vmware%2Fvimconn_vmware.py;h=a9bd0ff07267639c9be5fe06aaf39116c9b99665;hb=refs%2Fchanges%2F82%2F12482%2F2;hp=a3c25ca019000ee2183aaf43652d61fc1767f7c0;hpb=80135b928ab442c38898750b4751480205b4affc;p=osm%2FRO.git
diff --git a/RO-VIM-vmware/osm_rovim_vmware/vimconn_vmware.py b/RO-VIM-vmware/osm_rovim_vmware/vimconn_vmware.py
index a3c25ca0..a9bd0ff0 100644
--- a/RO-VIM-vmware/osm_rovim_vmware/vimconn_vmware.py
+++ b/RO-VIM-vmware/osm_rovim_vmware/vimconn_vmware.py
@@ -25,26 +25,13 @@
vimconn_vmware implementation an Abstract class in order to interact with VMware vCloud Director.
"""
-from lxml import etree as lxmlElementTree
-from osm_ro_plugin import vimconn
-from progressbar import Percentage, Bar, ETA, FileTransferSpeed, ProgressBar
-from pyVim.connect import SmartConnect, Disconnect
-from pyVmomi import vim, vmodl # @UnresolvedImport
-from pyvcloud.vcd.client import BasicLoginCredentials, Client
-from pyvcloud.vcd.org import Org
-from pyvcloud.vcd.vapp import VApp
-from pyvcloud.vcd.vdc import VDC
-from xml.etree import ElementTree as XmlElementTree
-from xml.sax.saxutils import escape
import atexit
import hashlib
import json
import logging
-import netaddr
import os
import random
import re
-import requests
import shutil
import socket
import ssl
@@ -54,6 +41,20 @@ import tempfile
import time
import traceback
import uuid
+from xml.etree import ElementTree as XmlElementTree
+from xml.sax.saxutils import escape
+
+from lxml import etree as lxmlElementTree
+import netaddr
+from osm_ro_plugin import vimconn
+from progressbar import Bar, ETA, FileTransferSpeed, Percentage, ProgressBar
+from pyvcloud.vcd.client import BasicLoginCredentials, Client
+from pyvcloud.vcd.org import Org
+from pyvcloud.vcd.vapp import VApp
+from pyvcloud.vcd.vdc import VDC
+from pyVim.connect import Disconnect, SmartConnect
+from pyVmomi import vim, vmodl # @UnresolvedImport
+import requests
import yaml
# global variable for vcd connector type
@@ -1906,6 +1907,7 @@ class vimconnector(vimconn.VimConnector):
start=False,
image_id=None,
flavor_id=None,
+ affinity_group_list=[],
net_list=[],
cloud_config=None,
disk_list=None,
@@ -3486,18 +3488,16 @@ class vimconnector(vimconn.VimConnector):
return vm_dict
- def delete_vminstance(self, vm__vim_uuid, created_items=None):
+ def delete_vminstance(self, vm_id, created_items=None, volumes_to_hold=None):
"""Method poweroff and remove VM instance from vcloud director network.
Args:
- vm__vim_uuid: VM UUID
+ vm_id: VM UUID
Returns:
Returns the instance identifier
"""
- self.logger.debug(
- "Client requesting delete vm instance {} ".format(vm__vim_uuid)
- )
+ self.logger.debug("Client requesting delete vm instance {} ".format(vm_id))
_, vdc = self.get_vdc_details()
vdc_obj = VDC(self.client, href=vdc.get("href"))
@@ -3514,24 +3514,22 @@ class vimconnector(vimconn.VimConnector):
)
try:
- vapp_name = self.get_namebyvappid(vm__vim_uuid)
+ vapp_name = self.get_namebyvappid(vm_id)
if vapp_name is None:
self.logger.debug(
"delete_vminstance(): Failed to get vm by given {} vm uuid".format(
- vm__vim_uuid
+ vm_id
)
)
return (
-1,
"delete_vminstance(): Failed to get vm by given {} vm uuid".format(
- vm__vim_uuid
+ vm_id
),
)
- self.logger.info(
- "Deleting vApp {} and UUID {}".format(vapp_name, vm__vim_uuid)
- )
+ self.logger.info("Deleting vApp {} and UUID {}".format(vapp_name, vm_id))
vapp_resource = vdc_obj.get_vapp(vapp_name)
vapp = VApp(self.client, resource=vapp_resource)
@@ -3563,13 +3561,13 @@ class vimconnector(vimconn.VimConnector):
if not powered_off:
self.logger.debug(
"delete_vminstance(): Failed to power off VM instance {} ".format(
- vm__vim_uuid
+ vm_id
)
)
else:
self.logger.info(
"delete_vminstance(): Powered off VM instance {} ".format(
- vm__vim_uuid
+ vm_id
)
)
@@ -3582,14 +3580,14 @@ class vimconnector(vimconn.VimConnector):
if not vapp:
self.logger.debug(
"delete_vminstance(): Failed to get vm by given {} vm uuid".format(
- vm__vim_uuid
+ vm_id
)
)
return (
-1,
"delete_vminstance(): Failed to get vm by given {} vm uuid".format(
- vm__vim_uuid
+ vm_id
),
)
@@ -3612,7 +3610,7 @@ class vimconnector(vimconn.VimConnector):
if not undeployed:
self.logger.debug(
"delete_vminstance(): Failed to undeploy vApp {} ".format(
- vm__vim_uuid
+ vm_id
)
)
@@ -3627,14 +3625,14 @@ class vimconnector(vimconn.VimConnector):
if not vapp:
self.logger.debug(
"delete_vminstance(): Failed to get vm by given {} vm uuid".format(
- vm__vim_uuid
+ vm_id
)
)
return (
-1,
"delete_vminstance(): Failed to get vm by given {} vm uuid".format(
- vm__vim_uuid
+ vm_id
),
)
@@ -3654,16 +3652,14 @@ class vimconnector(vimconn.VimConnector):
if result is None:
self.logger.debug(
- "delete_vminstance(): Failed delete uuid {} ".format(
- vm__vim_uuid
- )
+ "delete_vminstance(): Failed delete uuid {} ".format(vm_id)
)
else:
self.logger.info(
- "Deleted vm instance {} sccessfully".format(vm__vim_uuid)
+ "Deleted vm instance {} successfully".format(vm_id)
)
config_drive_catalog_name, config_drive_catalog_id = (
- "cfg_drv-" + vm__vim_uuid,
+ "cfg_drv-" + vm_id,
None,
)
catalog_list = self.get_image_list()
@@ -3686,12 +3682,12 @@ class vimconnector(vimconn.VimConnector):
)
self.delete_image(config_drive_catalog_id)
- return vm__vim_uuid
+ return vm_id
except Exception:
self.logger.debug(traceback.format_exc())
raise vimconn.VimConnException(
- "delete_vminstance(): Failed delete vm instance {}".format(vm__vim_uuid)
+ "delete_vminstance(): Failed delete vm instance {}".format(vm_id)
)
def refresh_vms_status(self, vm_list):
@@ -3999,17 +3995,15 @@ class vimconnector(vimconn.VimConnector):
exc_info=True,
)
- def action_vminstance(self, vm__vim_uuid=None, action_dict=None, created_items={}):
+ def action_vminstance(self, vm_id=None, action_dict=None, created_items={}):
"""Send and action over a VM instance from VIM
Returns the vm_id if the action was successfully sent to the VIM"""
self.logger.debug(
- "Received action for vm {} and action dict {}".format(
- vm__vim_uuid, action_dict
- )
+ "Received action for vm {} and action dict {}".format(vm_id, action_dict)
)
- if vm__vim_uuid is None or action_dict is None:
+ if vm_id is None or action_dict is None:
raise vimconn.VimConnException("Invalid request. VM id or action is None.")
_, vdc = self.get_vdc_details()
@@ -4020,20 +4014,20 @@ class vimconnector(vimconn.VimConnector):
)
)
- vapp_name = self.get_namebyvappid(vm__vim_uuid)
+ vapp_name = self.get_namebyvappid(vm_id)
if vapp_name is None:
self.logger.debug(
"action_vminstance(): Failed to get vm by given {} vm uuid".format(
- vm__vim_uuid
+ vm_id
)
)
raise vimconn.VimConnException(
- "Failed to get vm by given {} vm uuid".format(vm__vim_uuid)
+ "Failed to get vm by given {} vm uuid".format(vm_id)
)
else:
self.logger.info(
- "Action_vminstance vApp {} and UUID {}".format(vapp_name, vm__vim_uuid)
+ "Action_vminstance vApp {} and UUID {}".format(vapp_name, vm_id)
)
try:
@@ -4045,7 +4039,7 @@ class vimconnector(vimconn.VimConnector):
self.logger.info(
"action_vminstance: Power on vApp: {}".format(vapp_name)
)
- poweron_task = self.power_on_vapp(vm__vim_uuid, vapp_name)
+ poweron_task = self.power_on_vapp(vm_id, vapp_name)
result = self.client.get_task_monitor().wait_for_success(
task=poweron_task
)
@@ -4068,7 +4062,7 @@ class vimconnector(vimconn.VimConnector):
self.instance_actions_result("pause", result, vapp_name)
elif "resume" in action_dict:
self.logger.info("action_vminstance: resume vApp: {}".format(vapp_name))
- poweron_task = self.power_on_vapp(vm__vim_uuid, vapp_name)
+ poweron_task = self.power_on_vapp(vm_id, vapp_name)
result = self.client.get_task_monitor().wait_for_success(
task=poweron_task
)
@@ -4100,7 +4094,7 @@ class vimconnector(vimconn.VimConnector):
)
)
- return vm__vim_uuid
+ return vm_id
except Exception as exp:
self.logger.debug("action_vminstance: Failed with Exception {}".format(exp))
@@ -5456,18 +5450,18 @@ class vimconnector(vimconn.VimConnector):
return None
if add_vdc_rest_url is not None and provider_vdc_ref is not None:
- data = """ {1:s}
- ReservationPool
- MHz20482048
- MB20482048
- 0100
- trueMB20480true
-
- true""".format(
- escape(vdc_name), escape(vdc_name), provider_vdc_ref
- )
+ data = (
+ ' '
+ "{1:s}"
+ "ReservationPool"
+ "MHz20482048"
+ "MB20482048"
+ "0100"
+ "trueMB20480"
+ "true"
+ ''
+ "true"
+ ).format(escape(vdc_name), escape(vdc_name), provider_vdc_ref)
headers[
"Content-Type"
] = "application/vnd.vmware.admin.createVdcParams+xml"
@@ -6229,7 +6223,7 @@ class vimconnector(vimconn.VimConnector):
)
return None
- deviceId = hex(host_pci_dev.deviceId % 2 ** 16).lstrip("0x")
+ deviceId = hex(host_pci_dev.deviceId % 2**16).lstrip("0x")
backing = vim.VirtualPCIPassthroughDeviceBackingInfo(
deviceId=deviceId,
id=host_pci_dev.id,
@@ -7492,13 +7486,10 @@ if [ "$1" = "precustomization" ];then
for device in devices:
if type(device) is vim.vm.device.VirtualDisk:
- if (
- isinstance(
- device.backing,
- vim.vm.device.VirtualDisk.FlatVer2BackingInfo,
- )
- and hasattr(device.backing, "fileName")
- ):
+ if isinstance(
+ device.backing,
+ vim.vm.device.VirtualDisk.FlatVer2BackingInfo,
+ ) and hasattr(device.backing, "fileName"):
disk_info["full_path"] = device.backing.fileName
disk_info["datastore"] = device.backing.datastore
disk_info["capacityKB"] = device.capacityInKB
@@ -8660,3 +8651,23 @@ if [ "$1" = "precustomization" ];then
poweron_task = self.get_task_from_response(response.text)
return poweron_task
+
+ def migrate_instance(self, vm_id, compute_host=None):
+ """
+ Migrate a vdu
+ param:
+ vm_id: ID of an instance
+ compute_host: Host to migrate the vdu to
+ """
+ # TODO: Add support for migration
+ raise vimconn.VimConnNotImplemented("Should have implemented this")
+
+ def resize_instance(self, vm_id, flavor_id=None):
+ """
+ resize a vdu
+ param:
+ vm_id: ID of an instance
+ flavor_id: flavor_id to resize the vdu to
+ """
+ # TODO: Add support for resize
+ raise vimconn.VimConnNotImplemented("Should have implemented this")