Пример #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 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
Пример #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)

        # 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
Пример #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)

        # 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
Пример #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()

            # 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
Пример #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)

        # 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
Пример #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)

        # Show cluster configuration
        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

            # Show config
            if self._oArguments.host:
                oHost = oClusterConfig.getHost(self._oArguments.host)
                sys.stdout.write(oHost.toString())
            elif self._oArguments.resource:
                oResource = oClusterConfig.getResource(
                    self._oArguments.resource, self._oArguments.bootstrap)
                sys.stdout.write(oResource.toString())
            else:
                sys.stdout.write(oClusterConfig.toString())

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

        # Done
        return 0
Пример #8
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)

        # Show cluster configuration
        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)

            # Loop through hosts/resources
            if self._oArguments.what == 'hosts':
                if self._oArguments.host:
                    lsHosts_ids = [self._oArguments.host]
                else:
                    lsHosts_ids = sorted(oClusterConfig.getHostsIDs())
                for sHost_id in lsHosts_ids:
                    oClusterHost = KiscCluster_host(oClusterConfig, sHost_id)
                    oClusterHost.VERBOSE(self._oArguments.verbose)
                    iStatus = oClusterHost.status(False)
                    asResources_ids = oClusterHost.host().getResourcesIDs()
                    if self._oArguments.resource is None or self._oArguments.resource in asResources_ids:
                        sResources_ids = ','.join(asResources_ids)
                        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))
            elif self._oArguments.what == 'resources':
                if self._oArguments.resource:
                    lsResources_ids = [self._oArguments.resource]
                else:
                    lsResources_ids = sorted(oClusterConfig.getResourcesIDs())
                for sResource_id in lsResources_ids:
                    oClusterResource = KiscCluster_resource(
                        oClusterConfig, None, sResource_id, False)
                    oClusterResource.VERBOSE(self._oArguments.verbose)
                    iStatus = oClusterResource.status(False)
                    asHosts_ids = oClusterResource.resource().getHostsIDs()
                    if self._oArguments.host is None or self._oArguments.host in asHosts_ids:
                        sHosts_ids = ','.join(asHosts_ids)
                        if not len(sHosts_ids): sHosts_ids = '-'
                        sys.stdout.write(
                            '%s %s %s\n' %
                            (sResource_id, KiscRuntime.STATUS_MESSAGE[iStatus],
                             sHosts_ids))

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

        # Done
        return 0