This example shows how you can retrieve the product catalog, list the associated products, add, update, and delete products associations. The example is based on the discovery_sample.py sample.
Note: For a complete and up-to-date version of the sample code, see the
vsphere-automation-sdk-python VMware repository at GitHub.
... # Create a stub configuration stub_config = StubConfigurationFactory.new_std_configuration(connector) self.product_client = ProductCatalog(stub_config) self.associated_products_client = AssociatedProducts(stub_config) def run(self): # Product catalog product_catalog = self.product_client.list() print("Product catalog list: \n", product_catalog) # Associated products associated_products = self.associated_products_client.list() print("Associated products list : \n", associated_products) # Add product spec = {'product_name': 'VMware Identity Manager', 'version': '3.3', 'deployments': '3'} add_associated_product = self.associated_products_client.create(spec) print('Added new product. \n', add_associated_product) associated_products = self.associated_products_client.list() print("Associated products after adding the product: \n", associated_products) # Update product update_spec = {'deployments': '9'} update_associated_product = self.associated_products_client.update(add_associated_product, update_spec) associated_products = self.associated_products_client.list() print("Associated products after updating the product: \n", associated_products) # Delete product delete_associated_product = self.associated_products_client.delete(add_associated_product) associated_products = self.associated_products_client.list() print("Associated products after deleting the product: \n{0}", associated_products) ...