コード例 #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
ファイル: host_start.py プロジェクト: idiap/KiSC
    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
ファイル: resource_list.py プロジェクト: idiap/KiSC
    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
コード例 #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)

        # 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
コード例 #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
        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
コード例 #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)

        # 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
コード例 #9
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)

        # List cluster hosts/resources
        try:

            # Filter
            # ... exclude
            self._ltFilters_exclude = list()
            for sFilter in self._oArguments.exclude:
                try:
                    (sKey, sValue) = sFilter.split('=', 1)
                    if sKey[-1] == '~':
                        sKey = sKey[:-1]
                        sValue = re.compile(sValue)
                except ValueError:
                    sKey = sFilter
                    sValue = None
                self._ltFilters_exclude.append((sKey, sValue))
            # ... include
            self._ltFilters_include = list()
            for sFilter in self._oArguments.include:
                try:
                    (sKey, sValue) = sFilter.split('=', 1)
                    if sKey[-1] == '~':
                        sKey = sKey[:-1]
                        sValue = re.compile(sValue)
                except ValueError:
                    sKey = sFilter
                    sValue = None
                self._ltFilters_include.append((sKey, sValue))

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

            # List IDs
            if self._oArguments.what == 'hosts':
                if not len(self._ltFilters_include) and not len(
                        self._ltFilters_exclude):
                    sys.stdout.write(
                        '\n'.join(sorted(oClusterConfig.getHostsIDs())) + '\n')
                else:
                    for sHost_id in sorted(oClusterConfig.getHostsIDs()):
                        if self._match(
                                oClusterConfig.getHost(sHost_id).config()):
                            sys.stdout.write('%s\n' % sHost_id)
            elif self._oArguments.what == 'resources':
                if not len(self._ltFilters_include) and not len(
                        self._ltFilters_exclude):
                    sys.stdout.write('\n'.join(
                        sorted(
                            oClusterConfig.getResourcesIDs(
                                self._oArguments.bootstrap))) + '\n')
                else:
                    for sResource_id in sorted(
                            oClusterConfig.getResourcesIDs(
                                self._oArguments.bootstrap)):
                        if self._match(
                                oClusterConfig.getResource(
                                    sResource_id).config()):
                            sys.stdout.write('%s\n' % sResource_id)

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

        # Done
        return 0
コード例 #10
0
ファイル: cluster_status.py プロジェクト: idiap/KiSC
    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