Пример #1
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=''))
    def create_subscription_new(self, pub_lib_id, sub_lib_name):
        # Create a new subscription. Such subscription is created on the published
        # library, and can be later used for a push-sync
        #
        # spec
        #   +--subscribed_library
        #        +--target: CREATE_NEW
        #        +--subscribed_library: DO NOT SPECIFY as this is new
        #        +--new_subscribed_library
        #            +--name, description, automatic_sync_enabled, on_demand
        #        +--location: LOCAL/REMOTE
        #        +--subscribed_library_vcenter: (VcenterInfo) DO NOT SPECIFY for location=LOCAL
        #        +--placement:
        #             +--Resource pool and folder for the VM
        #             +--network for the VM

        client_token = str(uuid.uuid4())
        spec = Subscriptions.CreateSpec()
        subscribed_library = Subscriptions.CreateSpecSubscribedLibrary()
        subscribed_library.location = Subscriptions.Location.LOCAL

        subscribed_library.target = \
            Subscriptions.CreateSpecSubscribedLibrary.Target.CREATE_NEW
        new_subscribed_library = Subscriptions.CreateSpecNewSubscribedLibrary()
        new_subscribed_library.name = sub_lib_name
        new_subscribed_library.description = "Sample subscribed library"

        backing = StorageBacking(StorageBacking.Type.DATASTORE,
                                 self.datastore_id)
        new_subscribed_library.storage_backings = [backing]

        new_subscribed_library.automatic_sync_enabled = False
        # 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
        new_subscribed_library.on_demand = False
        subscribed_library.new_subscribed_library = new_subscribed_library

        placement = Subscriptions.CreateSpecPlacement()
        placement.resource_pool = self.resource_pool_id
        placement.folder = self.folder_id

        # Setting network to null implies that the subscription will use the
        # same network as the source VM
        # Warning - this may lead to failure if the same network is not
        # available to the subscriber
        placement.network = None

        subscribed_library.placement = placement
        spec.subscribed_library = subscribed_library

        subscription_id = self.client.subscriptions.create(
            pub_lib_id, spec, client_token)
        print("Subscription created, id: {0}".format(subscription_id))
        return subscription_id
    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_storage_backings(self, service_manager, datastore_name):
        """
        :param service_manager:
        :param datastore_name: name of the datastore providing storage
        :return: the storage backing array
        """

        # Find the datastore by the given datastore name
        datastore_id = get_datastore_id(service_manager=service_manager,
                                        datastore_name=datastore_name)
        assert datastore_id is not None

        # If provided datastore is not of type vmfs, substitute the type
        # StorageBacking.Type.DATASTORE with StorageBacking.Type.OTHER
        # Build the specification for the library to be created
        storage_backings = [StorageBacking(type=StorageBacking.Type.DATASTORE,
                                           datastore_id=datastore_id)]
        return storage_backings
Пример #5
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)
Пример #6
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)
Пример #7
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)