+ vim_catalog = None
+ try:
+ catalogs = vim.vca.get_catalogs()
+ if not validate_uuid4(image_name):
+ vim_catalog = vim.get_catalogid(catalog_name=image_name, catalogs=catalogs)
+ if vim_catalog is None:
+ return None
+ else:
+ vim_catalog = vim.get_catalogid(catalog_name=image_name, catalogs=catalogs)
+ if vim_catalog is None:
+ return None
+
+ vm_uuid = vim.new_vminstance(name=vm_name, image_id=vim_catalog)
+ if vm_uuid is not None and validate_uuid4(vm_uuid):
+ print("Image booted and vm uuid {}".format(vm_uuid))
+ vapp_dict = vim.get_vapp(vdc_name=namespace.vcdvdc, vapp_name=vm_uuid, isuuid=True)
+ if vapp_dict is not None:
+ print_vapp(vapp_dict=vapp_dict)
+ return True
+ except:
+ print("Failed uploaded {} image".format(image_name))
+
+
+def image_action(vim=None, action=None, namespace=None):
+ """ Function present set of action to manipulate with image.
+ - upload image
+ - boot image.
+ - delete image ( not yet done )
+
+ Args:
+ vim - vcloud director connector
+ action - string (upload/boot etc)
+ namespace - contain other attributes image name etc
+
+ Returns:
+ The return nothing
+ """
+
+ if action == 'upload' or namespace.action == 'upload':
+ upload_image(vim=vim, image_file=namespace.image)
+ elif action == 'boot' or namespace.action == 'boot':
+ boot_image(vim=vim, image_name=namespace.image, vm_name=namespace.vmname)
+ else:
+ return None
+
+
+def vmwarecli(command=None, action=None, namespace=None):
+ logger.debug("Namespace {}".format(namespace))