Пример #1
0
    def run(self):
        ie = self.prepare_endpoint(InfraEndpoint(), "infra")
        req = self.setup_request(FindStorageRequest())
        req.storageId = self.storageid
        response = ie.findStorage(req)
        if response.storage is None:
            print("! Storage '%s' doesn't exist" % self.storageid)
            return

        req = self.setup_request(UpdateStorageRequest())

        storage = response.storage

        req.storage = storage
        storage._id = self.storageid
        storage.name = self.name

        if self.localpath is not None:
            localAccess = LocalStorageAccess()
            localAccess.path = self.localpath
            localAccess.type = 'local'
            storage.defaultLocalAccess = localAccess

        if self.remotepath is not None:

            if self.remoteaccesstype is None or self.host is None or self.user is None or self.password is None:
                raise Exception("All options for remote access need to be specified")

            if self.remoteaccesstype is not None and self.remoteaccesstype not in validStorageAccessTypes:
                raise Exception("Option --accesstype %s has to be supplied" % validStorageAccessTypes)

            remoteAccess = RemoteStorageAccess()
            remoteAccess.type = 'remote'
            remoteAccess.accessType = self.remoteaccesstype
            ac = AccessCredentials()
            ac.authType = AccessCredentials_AuthType.PASSWORD
            ac.hostname = self.host
            ac.username = self.user
            ac.password = self.password
            ac.path = self.remotepath
            ac.port = self.determine_default_port(self.remoteaccesstype) if self.port is None else self.port

            remoteAccess.accessCredentials = ac
            storage.defaultRemoteStorageAccess = remoteAccess

        resp = ie.updateStorage(req)

        if resp.status != EndpointResponseStatus.OK:
            print("! Error updating storage %s: %s" %(self.storageid, resp.message))

        print("Storage %s has been updated" %(self.storageid))
Пример #2
0
    def run(self):

        ie = self.prepare_endpoint(InfraEndpoint(), "infra")
        req = self.setup_request(FindStorageRequest())
        req.storageId = self.storageid
        response = ie.findStorage(req)
        if response.storage is not None:
            print("! Storage '%s' already exists, remove it before adding again" % self.storageid)
            return

        if self.remoteaccesstype not in validStorageAccessTypes:
            raise Exception("Option --accesstype %s has to be supplied" % validStorageAccessTypes)


        req = self.setup_request(CreateStorageRequest())

        storage = Storage()
        req.storage = storage
        storage._id = self.storageid
        storage.name = self.name

        localAccess = LocalStorageAccess()
        localAccess.path = self.localpath
        localAccess.type = 'local'
        storage.defaultLocalAccess = localAccess

        remoteAccess = RemoteStorageAccess()
        remoteAccess.type = 'remote'
        remoteAccess.accessType = self.remoteaccesstype
        ac = AccessCredentials()
        ac.authType = AccessCredentials_AuthType.PASSWORD
        ac.hostname = self.host
        ac.username = self.user
        ac.password = self.password
        ac.path = self.remotepath
        ac.port = self.determine_default_port(self.remoteaccesstype) if self.port is None else self.port

        remoteAccess.accessCredentials = ac
        storage.defaultRemoteStorageAccess = remoteAccess

        resp = ie.createStorage(req)

        if resp.status != EndpointResponseStatus.OK:
            print("Error creating storage %s: %s" %(self.storageid, resp.message))

        print("Storage %s has been created" %(self.storageid))