+ self.logger.debug("Logging in to a vcd {} as user {}".format(self.org,
+ self.user))
+ client = Client(self.url, verify_ssl_certs=False)
+ client.set_credentials(BasicLoginCredentials(self.user, self.org, self.password))
+ except Exception:
+ raise Exception("Can't connect to a vCloud director org: "
+ "{} as user: {}".format(self.org, self.user))
+
+ return client
+
+ def get_catalog_id_from_path(self, catalog_name=None, path=None, progress=False):
+ """
+ Args
+ catalog - catalog name to be created
+ path: - valid path to OVF file.
+ progress - boolean progress bar show progress bar.
+
+ Return: if image uploaded correct method will provide image catalog UUID.
+ """
+ if not path:
+ raise Exception("Image path can't be None.")
+
+ if not os.path.isfile(path):
+ raise Exception("Can't read file. File not found.")
+
+ if not os.access(path, os.R_OK):
+ raise Exception("Can't read file. Check file permission to read.")
+
+ self.logger.debug("get_catalog_id_from_path() client requesting {} ".format(path))
+
+ _, filename = os.path.split(path)
+ _, file_extension = os.path.splitext(path)
+ if file_extension != '.ovf':
+ self.logger.debug("Wrong file extension {} connector support only OVF container.".format(file_extension))
+ raise Exception("Wrong container. vCloud director supports only OVF.")
+
+ self.logger.debug("File name {} Catalog Name {} file path {} ".format(filename,
+ catalog_name,
+ path))
+ try:
+ client = self.connect()
+ if not client:
+ raise Exception("Failed to connect vCD")
+ org = Org(client, resource=client.get_org())
+ catalogs = org.list_catalogs()
+ except Exception as exp:
+ self.logger.debug("Failed get catalogs() with Exception {} ".format(exp))
+ raise Exception("Failed get catalogs() with Exception {} ".format(exp))
+
+ if len(catalogs) == 0:
+ self.logger.info("Creating a new catalog entry {} in vcloud director".format(catalog_name))
+ result = org.create_catalog(catalog_name, catalog_name)
+ if result is None:
+ raise Exception("Failed to create new catalog {} ".format(catalog_name))
+ result = self.upload_ovf(org=org, catalog_name=catalog_name, image_name=filename.split(".")[0],
+ media_file_name=path, description='medial_file_name', progress=progress)