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))
def run(self): ie = self.prepare_endpoint(InfraEndpoint(), "infra") node = self.find_node(ie, self.hostname) if self.full is not None: req = ChangeNodeCredentialsRequest() req.nodeId = node._id req.renewRestrictedAccessCredentials = False ac = AccessCredentials() if self.user is None or self.password is None: raise Exception("Options --user, --password must be specified") ac.authType = AccessCredentials_AuthType.PASSWORD ac.username = self.user ac.password = self.password ac.hostname = self.hostname req.fullAccessCredentials = ac resp = ie.changeNodeCredentials(req) if resp.status != EndpointResponseStatus.OK: raise Exception("! Error changing node %s credentials: %s" % (self.hostname, resp.message)) print("Full access credentials have been changed at %s" % self.hostname) elif self.restricted is not None: req = ChangeNodeCredentialsRequest() req.nodeId = node._id if self.generate: req.renewRestrictedAccessCredentials = True else: raise Exception("Use option --generate to renew restricted access credentials") if self.user is not None or self.password is not None : raise Exception("Options --user, --password are not accepted for restricted access") resp = ie.changeNodeCredentials(req) if resp.status != EndpointResponseStatus.OK: raise Exception("! Error changing node %s credentials: %s" % (self.hostname, resp.message)) print("Restricted access credentials have been regenerated at %s" % self.hostname) else: raise Exception("Invalid combination of options")
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))
def run(self): ie = self.prepare_endpoint(InfraEndpoint(), "infra") node = self.find_node(ie, self.hostname) if self.validate is not None and self.add is None and self.remove is None: return self._validate_storage_access(ie, node) elif self.add is not None: if self.type is None: print("! --type option must be specified for --add") req = self.setup_request(FindStorageRequest()) req.storageId = self.storageid response = ie.findStorage(req) if response.status != EndpointResponseStatus.OK: print("! Error retrieving stroage '%s'" % self.storageid) return storage = response.storage if storage is None: print("! Storage '%s' doesn't exist" % self.storageid) return if self.type.lower() == 'local': sa = LocalStorageAccess() sa.type = 'local' sa.storageId = self.storageid if self.usedefault is not None: if storage.defaultLocalAccess is not None: sa.path = storage.defaultLocalAccess.path else: raise Exception("Default local access has not been specified in storage '%s'" % self.storageid ) else: if self.path is None: raise Exception("Option --path has to be specified") sa.path = self.path self.add_or_replace_storage_access(ie, node, sa) elif self.type.lower() == 'remote': sa = RemoteStorageAccess() sa.type = 'remote' sa.accessType = self.accesstype sa.storageId = self.storageid if self.usedefault is not None: if storage.defaultRemoteStorageAccess is not None: sa.accessType = storage.defaultRemoteStorageAccess.accessType sa.accessCredentials = storage.defaultRemoteStorageAccess.accessCredentials else: raise Exception("Default remote access has not been specified in storage '%s'" % self.storageid ) else: if self.accesstype not in validStorageAccessTypes: raise Exception("Option --accesstype %s has to be supplied, or --usedefault" % validStorageAccessTypes) if self.path is None: raise Exception("Option --path has to be specified, or --usedefault") ac = AccessCredentials() if self.path is None or self.user is None or self.password is None: raise Exception("Options --path, --user, --password must be specified for remote storage access") ac.authType = AccessCredentials_AuthType.PASSWORD ac.path = self.path ac.username = self.user ac.password = self.password ac.hostname = self.host ac.port = determine_default_port() if self.port is None else self.port sa.accessCredentials = ac self.add_or_replace_storage_access(ie, node, sa) elif self.remove is not None: for item in node.storageAccess: if item.storageId != self.storageid: newStorageAccess.append(item) node.storageAccess = newStorageAccess self.update_node(ie, node) print("Access to storage %s has been removed from node %s" % (self.storageid, self.hostname))