def create_subscribed_library(self, pub_lib_url, sub_lib_name): # Build the subscription information using the publish URL of the published # library sub_info = SubscriptionInfo() sub_info.authentication_method = SubscriptionInfo.AuthenticationMethod.NONE # on_demand = False for library and item level publish # on_demand = True for only item level publish, the library level # publish will only sync the item metadata sub_info.on_demand = False sub_info.automatic_sync_enabled = True sub_info.subscription_url = pub_lib_url # Build the specification for the subscribed library sub_spec = LibraryModel() sub_spec.name = sub_lib_name sub_spec.type = sub_spec.LibraryType.SUBSCRIBED sub_spec.subscription_info = sub_info sub_spec.storage_backings = self.storage_backings sub_lib_id = self.client.subscribed_library_service.create( create_spec=sub_spec, client_token=generate_random_uuid()) self.sub_libs_to_clean.append(sub_lib_id) print("Subscribed library created, id: {0}".format(sub_lib_id)) sub_lib = self.client.subscribed_library_service.get(sub_lib_id) return sub_lib
def mountContentLibrary(self, contentLibraryName=None, datastoreName=None, subscriptionURL=None, sslThumbprint=None): if contentLibraryName is None: contentLibraryName = self.org.config['WorkshopConfig'][ 'ContentLibraryName'] if datastoreName is None: datastoreName = self.org.config['WorkshopConfig']['Datastore'] if subscriptionURL is None: subscriptionURL = self.org.config['WorkshopConfig'][ 'ContentLibraryURL'] if sslThumbprint is None: sslThumbprint = self.org.config['WorkshopConfig']['sslThumbprint'] print(' {} mounting content library: {} {} {}'.format( self.sddc.sddc.name, contentLibraryName, datastoreName, subscriptionURL)) datastore = self.getDatastore(datastoreName)._moId storageBackings = [] storageBacking = StorageBacking(type=StorageBacking.Type.DATASTORE, datastore_id=datastore) storageBackings.append(storageBacking) createSpec = LibraryModel() createSpec.name = contentLibraryName createSpec.description = "Subscribed library backed by VC datastore" createSpec.type = createSpec.LibraryType.SUBSCRIBED createSpec.storage_backings = storageBackings createSpec.subscription_info = SubscriptionInfo( authentication_method=SubscriptionInfo.AuthenticationMethod( 'NONE'), automatic_sync_enabled=True, on_demand=True, ssl_thumbprint=sslThumbprint, subscription_url=subscriptionURL) return self.subscribed_library_stub.create(createSpec)
def create_subcribed_library(self, storage_backings, pub_lib_url): # Build the subscription information using the publish URL of the published # library. The username must be 'vcsp'. sub_info = SubscriptionInfo() sub_info.authentication_method = SubscriptionInfo.AuthenticationMethod.BASIC sub_info.user_name = self.VCSP_USERNAME sub_info.password = self.DEMO_PASSWORD sub_info.on_demand = False sub_info.automatic_sync_enabled = True sub_info.subscription_url = pub_lib_url # Build the specification for the subscribed library sub_spec = LibraryModel() sub_spec.name = self.sub_lib_name sub_spec.type = sub_spec.LibraryType.SUBSCRIBED sub_spec.subscription_info = sub_info sub_spec.storage_backings = storage_backings self.sub_lib_id = self.client.subscribed_library_service.create( create_spec=sub_spec, client_token=generate_random_uuid()) sub_lib = self.client.subscribed_library_service.get(self.sub_lib_id) return sub_lib, sub_spec
def state_create_library(self): # Fail if no datastore is specified if not self.datastore_name: self.module.fail_json( msg="datastore_name must be specified for create operations") # Find the datastore by the given datastore name datastore_id = self.pyv.find_datastore_by_name( datastore_name=self.datastore_name) if not datastore_id: self.module.fail_json(msg="Failed to find the datastore %s" % self.datastore_name) self.datastore_id = datastore_id._moId # Build the storage backing for the library to be created storage_backings = [] storage_backing = StorageBacking(type=StorageBacking.Type.DATASTORE, datastore_id=self.datastore_id) storage_backings.append(storage_backing) # Build the specification for the library to be created create_spec = LibraryModel() create_spec.name = self.library_name create_spec.description = self.library_description self.library_types = { 'local': create_spec.LibraryType.LOCAL, 'subscribed': create_spec.LibraryType.SUBSCRIBED } create_spec.type = self.library_types[self.library_type] create_spec.storage_backings = storage_backings # Build subscribed specification if self.library_type == "subscribed": subscription_info = self.set_subscription_spec() subscription_info.authentication_method = SubscriptionInfo.AuthenticationMethod.NONE create_spec.subscription_info = subscription_info self.create_update(spec=create_spec)
def state_update_library(self): """ Update Content Library """ self.fail_when_duplicated() changed = False library_id = self.local_libraries[self.library_name]['lib_id'] library_update_spec = LibraryModel() # Ensure library types are consistent existing_library_type = self.local_libraries[ self.library_name]['lib_type'].lower() if existing_library_type != self.library_type: self.module.fail_json( msg="Library [%s] is of type %s, cannot be changed to %s" % (self.library_name, existing_library_type, self.library_type)) # Compare changeable subscribed attributes if self.library_type == "subscribed": existing_subscription_url = self.local_libraries[ self.library_name]['lib_sub_url'] sub_url_changed = (existing_subscription_url != self.subscription_url) existing_on_demand = self.local_libraries[ self.library_name]['lib_sub_on_demand'] sub_on_demand_changed = (existing_on_demand != self.update_on_demand) sub_ssl_thumbprint_changed = False if "https:" in self.subscription_url and self.ssl_thumbprint: existing_ssl_thumbprint = self.local_libraries[ self.library_name]['lib_sub_ssl_thumbprint'] sub_ssl_thumbprint_changed = (existing_ssl_thumbprint != self.ssl_thumbprint) if sub_url_changed or sub_on_demand_changed or sub_ssl_thumbprint_changed: subscription_info = self.set_subscription_spec() library_update_spec.subscription_info = subscription_info changed = True # Compare description library_desc = self.local_libraries[ self.library_name]['lib_description'] desired_lib_desc = self.params.get('library_description') if library_desc != desired_lib_desc: library_update_spec.description = desired_lib_desc changed = True if changed: library_update_spec.name = self.library_name self.create_update(spec=library_update_spec, library_id=library_id, update=True) content_library_info = dict(msg="Content Library %s is unchanged." % self.library_name, library_id=library_id) self.module.exit_json(changed=False, content_library_info=dict( msg=content_library_info, library_id=library_id))