Example #1
0
    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")
Example #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 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))
Example #3
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))
Example #4
0
    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))
Example #5
0
    def run(self):

        ie = self.prepare_endpoint(InfraEndpoint(), "infra")

        # check if this host name is known already to Core application

        req = self.setup_request(FindNodeRequest())
        req.hostname = self.hostname
        response = ie.findNode(req)
        if response.node is not None:
            print("! Node %s already exists and can't be added" % response.node.hostname)
            return

        # probe connection to node

        req = self.setup_request(ProbeConnectRequest())
        req.port = self.port
        req.hostname = self.hostname
        req.user = self.user
        req.password = self.password
        req.type = ProbeConnectRequest_Type.PASSWORD
        response = ie.probeConnectionToRemoteNode(req)

        if response.status != EndpointResponseStatus.OK:
            print("! Error testing connection to remote node %s: %s" % (self.hostname, response.connectStatus))
            return

        # check if this host key is already known to Core application

        req = self.setup_request(FindNodeRequest())
        hostkey = response.hostkey
        req.hostkey = hostkey
        response = ie.findNode(req)
        if response.node is not None:
            print("! Error adding node %s: this host key is already used for %s" % (self.hostname, response.node.hostname))
            return

        m = hashlib.md5()
        m.update(str(req.hostkey.decode("hex")))
        digest = m.digest()

        # show host key to user

        print("Host %s RSA key fingerprint is %s " %(self.hostname, self._delimit(digest.encode("hex"))))
        sys.stdout.write("Are you sure you want to continue connecting (yes/no)? ")

        input = sys.stdin.readline()
        if not (input.startswith('y') or input.startswith('Y')):
            return

        # create node
        req = self.setup_request(CreateNodeRequest())
        n = Node()
        n.hostname = self.hostname
        n.hostkey = hostkey
        n.port = self.port

        ac = AccessCredentials()
        ac.authType = AccessCredentials_AuthType.PASSWORD
        ac.username = self.user
        ac.password = self.password
        ac.port = self.port
        n.fullAccessCredentials = ac

        n.roles = {}
        n.storageAccess = {}
        req.node = n
        
        response = ie.createNode(req)

        if response.status != EndpointResponseStatus.OK:
            print("! Error adding node %s: %s" % (self.hostname, response.message))
            return

        print("Node %s has been created, configuring repository..." % (self.hostname))


        req = self.setup_request(RemoteNodeFunctionRequest())
        req.nodeId = response.nodeId
        req.type = RemoteNodeFunctionType.CONFIGURE_REPOSITORY

        resp = ie.executeRemoteNodeFunction(req)
        if resp.status != EndpointResponseStatus.OK:
            print("! Error configuring repository for node %s : %s " % (self.hostname, resp.message))
            return

        print("Repository configured, creating agent user...")

        req.type = RemoteNodeFunctionType.CREATE_AGENT_USER
        resp = ie.executeRemoteNodeFunction(req)
        if resp.status != EndpointResponseStatus.OK:
            print("! Error creating agent user for node %s: %s " % (self.hostname, resp.message))
            return