Пример #1
0
    def execute(self, _sCommand=None, _lArguments=None):
        """
        Execute the command

        @param str  _sCommand    Command name
        @param list _lArguments  Command arguments

        @return int  0 on success, non-zero in case of failure
        """

        # Arguments
        self._initArgumentParser(_sCommand)
        self._initArguments(_lArguments)

        # Stop the resource
        try:
            # Bootstrap ?
            if self._oArguments.bootstrap and not self._oArguments.force:
                raise RuntimeError(
                    'Can not stop bootstrap (host startup) resource without \'--force\' flag'
                )

            # Load config
            oClusterConfig = KiscCluster_config(self._oArguments.config)
            lsErrors = oClusterConfig.load()
            if lsErrors:
                if self._oArguments.verbose >= KiscRuntime.VERBOSE_DEBUG:
                    for sError in lsErrors:
                        sys.stderr.write('%s\n' % sError)
                else:
                    sys.stderr.write('%s\n' % lsErrors[-1])
                return 255
            oClusterConfig.VERBOSE(self._oArguments.verbose)

            # Retrieve host
            sHost_id = oClusterConfig.getHostByHostname().id()

            # Retrieve resource
            sResource_id = self._oArguments.resource
            oClusterResource = KiscCluster_resource(oClusterConfig, sHost_id,
                                                    sResource_id,
                                                    self._oArguments.bootstrap)
            oClusterResource.VERBOSE(self._oArguments.verbose)

            # Stop resource
            lsErrors = oClusterResource.stop(self._oArguments.force)
            if lsErrors:
                if self._oArguments.verbose >= KiscRuntime.VERBOSE_DEBUG:
                    for sError in lsErrors:
                        sys.stderr.write('%s\n' % sError)
                else:
                    sys.stderr.write('%s\n' % lsErrors[-1])
                return 255

        except (OSError, RuntimeError) as e:
            sys.stderr.write('%s\n' % str(e))
            return 255

        # Done
        return 0
Пример #2
0
    def execute(self, _sCommand=None, _lArguments=None):
        """
        Execute the command

        @param str  _sCommand    Command name
        @param list _lArguments  Command arguments

        @return int  0 on success, non-zero in case of failure
        """

        # Arguments
        self._initArgumentParser(_sCommand)
        self._initArguments(_lArguments)

        # Query host status
        iStatus = KiscRuntime.STATUS_UNKNOWN
        try:
            # Load config
            oClusterConfig = KiscCluster_config(self._oArguments.config)
            lsErrors = oClusterConfig.load()
            if lsErrors:
                if self._oArguments.verbose >= KiscRuntime.VERBOSE_DEBUG:
                    for sError in lsErrors:
                        sys.stderr.write('%s\n' % sError)
                else:
                    sys.stderr.write('%s\n' % lsErrors[-1])
                return 255
            oClusterConfig.VERBOSE(self._oArguments.verbose)

            # Retrieve host
            if self._oArguments.host:
                sHost_id = self._oArguments.host
            else:
                sHost_id = oClusterConfig.getHostByHostname().id()
            oClusterHost = KiscCluster_host(oClusterConfig, sHost_id)
            oClusterHost.VERBOSE(self._oArguments.verbose)

            # Query host status
            iStatus = oClusterHost.status(self._oArguments.local)
            if not self._oArguments.silent:
                sResources_ids = ','.join(
                    oClusterHost.host().getResourcesIDs())
                sHostRegistration_id = oClusterHost.host().registerTo()
                if sHostRegistration_id is not None:
                    sResources_ids = '> %s' % sHostRegistration_id
                elif not len(sResources_ids):
                    sResources_ids = '-'
                sys.stdout.write(
                    '%s %s %s\n' %
                    (sHost_id, KiscRuntime.STATUS_MESSAGE[iStatus],
                     sResources_ids))

        except (OSError, RuntimeError) as e:
            sys.stderr.write('%s\n' % str(e))
            return 255

        # Done
        return iStatus
Пример #3
0
    def execute(self, _sCommand=None, _lArguments=None):
        """
        Execute the command

        @param str  _sCommand    Command name
        @param list _lArguments  Command arguments

        @return int  0 on success, non-zero in case of failure
        """

        # Arguments
        self._initArgumentParser(_sCommand)
        self._initArguments(_lArguments)

        # Start the host
        try:
            # Load config
            oClusterConfig = KiscCluster_config(self._oArguments.config)
            lsErrors = oClusterConfig.load()
            if lsErrors:
                if self._oArguments.verbose >= KiscRuntime.VERBOSE_DEBUG:
                    for sError in lsErrors:
                        sys.stderr.write('%s\n' % sError)
                else:
                    sys.stderr.write('%s\n' % lsErrors[-1])
                return 255
            oClusterConfig.VERBOSE(self._oArguments.verbose)

            # Retrieve host
            if self._oArguments.host:
                sHost_id = self._oArguments.host
            else:
                sHost_id = oClusterConfig.getHostByHostname().id()
            oClusterHost = KiscCluster_host(oClusterConfig, sHost_id)
            oClusterHost.VERBOSE(self._oArguments.verbose)

            # Start host
            lsErrors = oClusterHost.start()
            if lsErrors:
                if self._oArguments.verbose >= KiscRuntime.VERBOSE_DEBUG:
                    for sError in lsErrors:
                        sys.stderr.write('%s\n' % sError)
                else:
                    sys.stderr.write('%s\n' % lsErrors[-1])
                return 255

        except (OSError, RuntimeError) as e:
            sys.stderr.write('%s\n' % str(e))
            return 255

        # Done
        return 0
Пример #4
0
    def execute(self, _sCommand=None, _lArguments=None):
        """
        Execute the command

        @param str  _sCommand    Command name
        @param list _lArguments  Command arguments

        @return int  0 on success, non-zero in case of failure
        """

        # Arguments
        self._initArgumentParser(_sCommand)
        self._initArguments(_lArguments)

        # Query resource status
        iStatus = KiscRuntime.STATUS_UNKNOWN
        try:
            # Load config
            oClusterConfig = KiscCluster_config(self._oArguments.config)
            lsErrors = oClusterConfig.load()
            if lsErrors:
                if self._oArguments.verbose >= KiscRuntime.VERBOSE_DEBUG:
                    for sError in lsErrors:
                        sys.stderr.write('%s\n' % sError)
                else:
                    sys.stderr.write('%s\n' % lsErrors[-1])
                return 255
            oClusterConfig.VERBOSE(self._oArguments.verbose)

            # Retrieve host
            sHost_id = oClusterConfig.getHostByHostname().id()

            # Retrieve resource
            sResource_id = self._oArguments.resource
            oClusterResource = KiscCluster_resource(oClusterConfig, sHost_id,
                                                    sResource_id,
                                                    self._oArguments.bootstrap)
            oClusterResource.VERBOSE(self._oArguments.verbose)

            # Query resource status
            iStatus = oClusterResource.status(
                self._oArguments.local and oClusterConfig.isHostResource(
                    sHost_id, sResource_id, self._oArguments.bootstrap))
            sys.stdout.write(oClusterResource.resource().toString(True))

        except (OSError, RuntimeError) as e:
            sys.stderr.write('%s\n' % str(e))
            return 255

        # Done
        return 0
Пример #5
0
    def execute(self, _sCommand=None, _lArguments=None):
        """
        Execute the command

        @param str  _sCommand    Command name
        @param list _lArguments  Command arguments

        @return int  0 on success, non-zero in case of failure
        """

        # Arguments
        self._initArgumentParser(_sCommand)
        self._initArguments(_lArguments)

        # Query resource status
        iStatus = KiscRuntime.STATUS_UNKNOWN
        try:
            # Load config
            oClusterConfig = KiscCluster_config(self._oArguments.config)
            lsErrors = oClusterConfig.load()
            if lsErrors:
                if self._oArguments.verbose >= KiscRuntime.VERBOSE_DEBUG:
                    for sError in lsErrors:
                        sys.stderr.write('%s\n' % sError)
                else:
                    sys.stderr.write('%s\n' % lsErrors[-1])
                return 255
            oClusterConfig.VERBOSE(self._oArguments.verbose)

            # Retrieve host
            sHost_id = oClusterConfig.getHostByHostname().id()
            oClusterHost = KiscCluster_host(oClusterConfig, sHost_id)
            oClusterHost.VERBOSE(self._oArguments.verbose)

            # Query host status
            iStatus = oClusterHost.status(True)
            if iStatus != KiscRuntime.STATUS_STARTED:
                raise RuntimeError('Host not started')

            # List resources
            for sResource_id in oClusterHost.host().getResourcesIDs(
                    self._oArguments.bootstrap):
                sys.stdout.write('%s\n' % sResource_id)

        except (OSError, RuntimeError) as e:
            sys.stderr.write('%s\n' % str(e))
            return 255

        # Done
        return 0
Пример #6
0
    def execute(self, _sCommand=None, _lArguments=None):
        """
        Execute the command

        @param str  _sCommand    Command name
        @param list _lArguments  Command arguments

        @return int  0 on success, non-zero in case of failure
        """

        # Arguments
        self._initArgumentParser(_sCommand)
        self._initArguments(_lArguments)

        # Display resource help
        try:

            # Resource type
            if self._oArguments.type:
                sType = self._oArguments.resource
            else:
                # Load config
                oClusterConfig = KiscCluster_config(self._oArguments.config)
                lsErrors = oClusterConfig.load()
                if lsErrors:
                    sys.stderr.write('%s\n' % lsErrors[-1])
                    return 255

                # Retrieve host
                sHost_id = oClusterConfig.getHostByHostname().id()

                # Retrieve resource type
                sResource_id = self._oArguments.resource
                oClusterResource = KiscCluster_resource(oClusterConfig, sHost_id, sResource_id, self._oArguments.bootstrap)
                sType = oClusterResource.resource().type()

            # Show resource (type) help
            for sLine in pydoc.render_doc(kiscResourceClass(sType)).splitlines():
                if sLine.find('Method resolution order') >= 0:
                    break
                sys.stdout.write('%s\n' % sLine)
                
        except (OSError, RuntimeError) as e:
            sys.stderr.write('%s\n' % str(e))
            return 255

        # Done
        return 0
Пример #7
0
    def execute(self, _sCommand=None, _lArguments=None):
        """
        Execute the command

        @param str  _sCommand    Command name
        @param list _lArguments  Command arguments

        @return int  0 on success, non-zero in case of failure
        """

        # Arguments
        self._initArgumentParser(_sCommand)
        self._initArguments(_lArguments)

        # Query resource status
        try:
            # Load config
            oClusterConfig = KiscCluster_config(self._oArguments.config)
            oClusterConfig.VERBOSE(self._oArguments.verbose)
            lsErrors = oClusterConfig.load()
            if lsErrors:
                if self._oArguments.verbose >= KiscRuntime.VERBOSE_DEBUG:
                    for sError in lsErrors:
                        sys.stderr.write('%s\n' % sError)
                else:
                    sys.stderr.write('%s\n' % lsErrors[-1])
                return 255
            oClusterConfig.VERBOSE(self._oArguments.verbose)

            # Host
            if self._oArguments.host is not None:
                sHost_id = self._oArguments.host
            else:
                sHost_id = oClusterConfig.getHostByHostname().id()

            # Cache file
            oClusterConfig.resolveFile(self._oArguments.input,
                                       self._oArguments.output, sHost_id,
                                       self._oArguments.resource,
                                       self._oArguments.bootstrap)

        except (OSError, RuntimeError) as e:
            sys.stderr.write('%s\n' % str(e))
            return 255

        # Done
        return 0