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
Example #2
0
    def state_create_library(self):
        # 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

        # Create a local content library backed the VC datastore
        library_id = self.content_service.content.LocalLibrary.create(create_spec=create_spec,
                                                                      client_token=str(uuid.uuid4()))
        if library_id:
            self.module.exit_json(
                changed=True,
                content_library_info=dict(
                    msg="Content Library '%s' created." % create_spec.name,
                    library_id=library_id,
                    library_description=self.library_description,
                    library_type=create_spec.type,
                )
            )
        self.module.exit_json(changed=False,
                              content_library_info=dict(msg="Content Library not created. Datastore and library_type required", library_id=''))
Example #3
0
 def create_published_library(self, client_token, cl_name, publish_info, ds_id):
     """Creates publish library back up by vCenter data store (as is)"""
     library_model = LibraryModel()
     library_model.id = client_token
     library_model.name = cl_name
     library_model.description = self.lib_description
     library_model.type = library_model.LibraryType.LOCAL
     library_model.publish_info = publish_info
     storage_backings = []
     storage_backing = StorageBacking(type=StorageBacking.Type.DATASTORE, datastore_id=ds_id)
     storage_backings.append(storage_backing)
     library_model.storage_backings = storage_backings
     library_id = self.local_library_service.create(create_spec=library_model, client_token=client_token)
     library = self.local_library_service.get(library_id)
     return library
    def _execute(self):
        # List of visible content libraries
        visible_cls = self.client.local_library_service.list()
        if len(visible_cls) > 0:
            for visible_cl in visible_cls:
                get_visible_cl = self.client.local_library_service.get(
                    visible_cl)
                print('Visible content library: {0} with id: {1}'.format(
                    get_visible_cl.name, visible_cl))

        # Find the datastore by the given datastore name using property collector
        self.datastore_id = get_datastore_id(
            service_manager=self.servicemanager,
            datastore_name=self.datastore_name)
        assert self.datastore_id is not None
        print('DataStore: {0} ID: {1}'.format(self.datastore_name,
                                              self.datastore_id))

        # 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.lib_name
        create_spec.description = "Local library backed by VC datastore"
        create_spec.type = create_spec.LibraryType.LOCAL
        create_spec.storage_backings = storage_backings

        # Create a local content library backed the VC datastore using vAPIs
        library_id = self.client.local_library_service.create(
            create_spec=create_spec, client_token=generate_random_uuid())
        print('Local library created: ID: {0}'.format(library_id))

        # Retrieve the local content library
        self.local_library = self.client.local_library_service.get(library_id)
        print('Retrieved library: ID: {0}'.format(self.local_library.id))

        # Update the local content library
        update_spec = LibraryModel()
        update_spec.description = "new description"
        self.client.local_library_service.update(library_id, update_spec)
        print('Updated library description')
    def create_published_library(self, pub_lib_name):
        pub_info = PublishInfo()
        pub_info.published = True
        # VMTX sync needs the authentication to be turned off
        pub_info.authentication_method = PublishInfo.AuthenticationMethod.NONE
        pub_spec = LibraryModel()
        pub_spec.name = pub_lib_name
        pub_spec.description = "Sample Published library"
        pub_spec.publish_info = pub_info
        pub_spec.type = pub_spec.LibraryType.LOCAL
        pub_spec.storage_backings = self.storage_backings

        pub_lib_id = self.client.local_library_service.create(
            create_spec=pub_spec, client_token=generate_random_uuid())
        print("Published library created, id: {0}".format(pub_lib_id))

        pub_lib = self.client.library_service.get(pub_lib_id)
        return pub_lib
Example #6
0
    def create_local_library(self, storage_backings, lib_name):
        """
        :param storage_backings: Storage for the library
        :param lib_name: Name of the library
        :return: id of the created library
        """
        create_spec = LibraryModel()
        create_spec.name = lib_name
        create_spec.description = "Local library backed by VC datastore"
        create_spec.type = LibraryModel.LibraryType.LOCAL
        create_spec.storage_backings = storage_backings

        # Create a local content library backed the VC datastore
        library_id = self.client.local_library_service.create(
            create_spec=create_spec, client_token=generate_random_uuid())
        print('Local library created, ID: {0}'.format(library_id))

        return library_id
Example #7
0
    def _execute(self):
        # Find the datastore by the given datastore name using property collector
        self.datastore_id = get_datastore_id(service_manager=self.servicemanager, datastore_name=self.datastore_name)
        assert self.datastore_id is not None
        print('DataStore: {0} ID: {1}'.format(self.datastore_name, self.datastore_id))

        # 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.lib_name
        create_spec.description = "Local library backed by VC datastore"
        create_spec.type = create_spec.LibraryType.LOCAL
        create_spec.storage_backings = storage_backings

        # Create a local content library backed the VC datastore using vAPIs
        library_id = self.client.local_library_service.create(create_spec=create_spec,
                                                              client_token=generate_random_uuid())
        print('Local library created: ID: {0}'.format(library_id))
        self.local_library = self.client.local_library_service.get(library_id)

        # Create a new library item in the content library for uploading the files
        self.library_item_id = self.helper.create_library_item(library_id=self.local_library.id,
                                                               item_name=self.lib_item_name,
                                                               item_description='Sample simple VM template',
                                                               item_type='ovf')
        assert self.library_item_id is not None
        assert self.client.library_item_service.get(self.library_item_id) is not None
        print('Library item created id: {0}'.format(self.library_item_id))

        # Upload a VM template to the CL
        ovf_files_map = self.helper.get_ovf_files_map(ClsApiHelper.SIMPLE_OVF_RELATIVE_DIR)
        self.helper.upload_files(library_item_id=self.library_item_id, files_map=ovf_files_map)
        print('Uploaded ovf and vmdk files to library item {0}'.format(self.library_item_id))

        # Download the library item from the CL
        temp_dir = tempfile.mkdtemp(prefix='simpleVmTemplate-')
        print('Downloading library item {0} to directory {1}'.format(self.library_item_id, temp_dir))
        downloaded_files_map = self.helper.download_files(library_item_id=self.library_item_id, directory=temp_dir)
        assert len(downloaded_files_map) == len(ovf_files_map)
Example #8
0
    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)
Example #9
0
    def create_published_library(self, storage_backings):
        # Build the authenticated publish info.
        # Note: The username will be 'vcsp'.
        pub_info = PublishInfo()
        pub_info.published = True
        pub_info.authentication_method = PublishInfo.AuthenticationMethod.BASIC
        pub_info.password = self.DEMO_PASSWORD

        # Build the specification for the published library to be created
        pub_spec = LibraryModel()
        pub_spec.name = self.pub_lib_name
        pub_spec.description = "Published library backed by VC datastore"
        pub_spec.publish_info = pub_info
        pub_spec.type = pub_spec.LibraryType.LOCAL
        pub_spec.storage_backings = storage_backings

        pub_lib_id = self.client.local_library_service.create(
            create_spec=pub_spec, client_token=generate_random_uuid())

        return pub_lib_id
Example #10
0
    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
Example #11
0
    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)