def manageService(self, service, action):
        """ Manage services running on this machine

      usage:

        service <action> <serviceName>
    """
        client = ComponentMonitoringClient()
        result = client.getInstallations({'UninstallationTime': None}, {
            'System': 'External',
            'Module': service,
            'Type': 'External'
        }, {'HostName': self.host}, False)
        if not result['OK']:
            self._errMsg(result['Message'])
            return
        elif len(result['Value']) < 1:
            self._errMsg('%s is not installed' % (service))
            return

        client = SystemAdministratorClient(self.host, self.port)
        if action == 'start':
            result = client.startService(service)
        elif action == 'stop':
            result = client.stopService(service)
        elif action == 'restart':
            result = client.restartService(service)
        elif action == 'status':
            result = client.statusService(service)

        if not result['OK']:
            self._errMsg(result['Message'])
            return

        gLogger.notice(result['Value'])
Exemple #2
0
def main():
  global force

  from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller
  gComponentInstaller.exitOnError = True

  Script.registerSwitch("f", "force", "Forces the removal of the logs", setForce)
  Script.parseCommandLine()
  args = Script.getPositionalArgs()

  if len(args) == 1:
    args = args[0].split('/')

  if len(args) < 2:
    Script.showHelp(exitCode=1)

  system = args[0]
  component = args[1]

  monitoringClient = ComponentMonitoringClient()
  result = monitoringClient.getInstallations({'Instance': component, 'UnInstallationTime': None},
                                             {'System': system},
                                             {'HostName': socket.getfqdn()}, True)
  if not result['OK']:
    gLogger.error(result['Message'])
    DIRACexit(1)
  if len(result['Value']) < 1:
    gLogger.warn('Given component does not exist')
    DIRACexit(1)
  if len(result['Value']) > 1:
    gLogger.error('Too many components match')
    DIRACexit(1)

  removeLogs = False
  if force:
    removeLogs = True
  else:
    if result['Value'][0]['Component']['Type'] in gComponentInstaller.componentTypes:
      result = promptUser('Remove logs?', ['y', 'n'], 'n')
      if result['OK']:
        removeLogs = result['Value'] == 'y'
      else:
        gLogger.error(result['Message'])
        DIRACexit(1)

  result = gComponentInstaller.uninstallComponent(system, component, removeLogs)
  if not result['OK']:
    gLogger.error(result['Message'])
    DIRACexit(1)

  result = MonitoringUtilities.monitorUninstallation(system, component)
  if not result['OK']:
    gLogger.error(result['Message'])
    DIRACexit(1)
  gLogger.notice('Successfully uninstalled component %s/%s' % (system, component))
  DIRACexit()
                                    '  System:  Name of the DIRAC system (ie: WorkloadManagement)',
                                    '  Component: Name of the DIRAC component (ie: Matcher)'] ) )

Script.parseCommandLine()
args = Script.getPositionalArgs()

if len( args ) < 2:
  Script.showHelp()
  DIRACexit( 1 )

system = args[0]
component = args[1]

monitoringClient = ComponentMonitoringClient()
result = monitoringClient.getInstallations( { 'Instance': component, 'UnInstallationTime': None },
                                                  { 'System': system },
                                                  { 'HostName': socket.getfqdn() }, True )
if not result[ 'OK' ]:
  gLogger.error( result[ 'Message' ] )
  DIRACexit( 1 )
if len( result[ 'Value' ] ) < 1:
  gLogger.error( 'Given component does not exist' )
  DIRACexit( 1 )
if len( result[ 'Value' ] ) > 1:
  gLogger.error( 'Too many components match' )
  DIRACexit( 1 )

removeLogs = False
if force:
  removeLogs = True
else:
Script.parseCommandLine()
args = Script.getPositionalArgs()

if len(args) == 1:
    args = args[0].split('/')

if len(args) < 2:
    Script.showHelp(exitCode=1)

system = args[0]
component = args[1]

monitoringClient = ComponentMonitoringClient()
result = monitoringClient.getInstallations(
    {
        'Instance': component,
        'UnInstallationTime': None
    }, {'System': system}, {'HostName': socket.getfqdn()}, True)
if not result['OK']:
    gLogger.error(result['Message'])
    DIRACexit(1)
if len(result['Value']) < 1:
    gLogger.warn('Given component does not exist')
    DIRACexit(1)
if len(result['Value']) > 1:
    gLogger.error('Too many components match')
    DIRACexit(1)

removeLogs = False
if force:
    removeLogs = True
  def do_uninstall( self, args ):
    """
        Uninstall DIRAC component

        usage:

          uninstall db <database>
          uninstall <-f ForceLogUninstall> <system> <component>
    """
    argss = args.split()
    if not argss:
      gLogger.notice( self.do_uninstall.__doc__ )
      return

    # Retrieve user uninstalling the component
    result = getProxyInfo()
    if not result[ 'OK' ]:
      self.__errMsg( result[ 'Message'] )
    user = result[ 'Value' ][ 'username' ]

    option = argss[0]
    if option == 'db':
      component = argss[1]
      client = SystemAdministratorClient( self.host, self.port )

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      result = client.getAvailableDatabases()
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      system = result[ 'Value' ][ component ][ 'System' ]
      result = MonitoringUtilities.monitorUninstallation( system , component, hostname = hostname, cpu = cpu )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return

      result = client.uninstallDatabase( component )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
      else:
        gLogger.notice( "Successfully uninstalled %s" % ( component ) )
    else:
      if option == '-f':
        force = True
        del argss[0]
      else:
        force = False

      if len( argss ) != 2:
        gLogger.notice( self.do_uninstall.__doc__ )
        return

      system, component = argss
      client = SystemAdministratorClient( self.host, self.port )

      monitoringClient = ComponentMonitoringClient()
      result = monitoringClient.getInstallations( { 'Instance': component, 'UnInstallationTime': None },
                                                  { 'System': system },
                                                  { 'HostName': self.host }, True )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      if len( result[ 'Value' ] ) < 1:
        self.__errMsg( "Given component does not exist" )
        return
      if len( result[ 'Value' ] ) > 1:
        self.__errMsg( "Too many components match" )
        return

      removeLogs = False
      if force:
        removeLogs = True
      else:
        if result[ 'Value' ][0][ 'Component' ][ 'Type' ] in self.runitComponents:
          result = promptUser( 'Remove logs?', ['y', 'n'], 'n' )
          if result[ 'OK' ]:
            removeLogs = result[ 'Value' ] == 'y'

      result = client.uninstallComponent( system, component, removeLogs )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
      else:
        gLogger.notice( "Successfully uninstalled %s/%s" % ( system, component ) )

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      result = MonitoringUtilities.monitorUninstallation( system, component, hostname = hostname, cpu = cpu )
      if not result[ 'OK' ]:
        return result
  def getInstallations( self, argss ):
    """ Get data from the component monitoring database
    """
    display = 'table'
    installationFilter = {}
    componentFilter = {}
    hostFilter = {}

    key = None
    for arg in argss:
      if not key:
        if arg == 'list':
          display = 'list'
        elif arg == 'current':
          installationFilter[ 'UnInstallationTime' ] = None
        elif arg == '-t':
          key = 'Component.Type'
        elif arg == '-m':
          key = 'Component.Module'
        elif arg == '-s':
          key = 'Component.System'
        elif arg == '-h':
          key = 'Host.HostName'
        elif arg == '-n':
          key = 'Instance'
        elif arg == '-itb':
          key = 'InstallationTime.smaller'
        elif arg == '-ita':
          key = 'InstallationTime.bigger'
        elif arg == '-utb':
          key = 'UnInstallationTime.smaller'
        elif arg == '-uta':
          key = 'UnInstallationTime.bigger'
      else:
        if 'Component.' in key:
          componentFilter[ key.replace( 'Component.', '' ) ] = arg
        elif 'Host.' in key:
          hostFilter[ key.replace( 'Host.', '' ) ] = arg
        else:
          if 'Time.' in key:
            arg = datetime.datetime.strptime( arg, '%d-%m-%Y' )
          installationFilter[ key ] = arg
        key = None

    client = ComponentMonitoringClient()
    result = client.getInstallations( installationFilter, componentFilter, hostFilter, True )
    if not result[ 'OK' ]:
      self.__errMsg( 'Could not retrieve the installations: %s' % ( result[ 'Message' ] ) )
      installations = None
    else:
      installations = result[ 'Value' ]

    if installations:
      if display == 'table':
        gLogger.notice( '' )
        gLogger.notice( ' ' + 'Num'.center( 5 ) + ' ' \
                        + 'Host'.center( 20 ) + ' ' \
                        + 'Name'.center( 20 ) + ' ' \
                        + 'Module'.center( 20 ) + ' ' \
                        + 'System'.center( 16 ) + ' ' \
                        + 'Type'.center( 12 ) + ' ' \
                        + 'Installed on'.center( 18 ) + ' ' \
                        + 'Install by'.center( 12 ) + ' ' \
                        + 'Uninstalled on'.center( 18 ) + ' ' \
                        + 'Uninstall by'.center( 12 ) )
        gLogger.notice( ( '-' ) * 164 )
      for i, installation in enumerate( installations ):
        if not installation[ 'InstalledBy' ]:
          installedBy = ''
        else:
          installedBy = installation[ 'InstalledBy' ]

        if not installation[ 'UnInstalledBy' ]:
          uninstalledBy = ''
        else:
          uninstalledBy = installation[ 'UnInstalledBy' ]

        if installation[ 'UnInstallationTime' ]:
          uninstalledOn = installation[ 'UnInstallationTime' ].strftime( "%d-%m-%Y %H:%M" )
          isInstalled = 'No'
        else:
          uninstalledOn = ''
          isInstalled = 'Yes'

        if display == 'table':
          gLogger.notice( '|' + str( i + 1 ).center( 5 ) + '|' \
                          + installation[ 'Host' ][ 'HostName' ].center( 20 ) + '|' \
                          + installation[ 'Instance' ].center( 20 ) + '|' \
                          + installation[ 'Component' ][ 'Module' ].center( 20 ) + '|' \
                          + installation[ 'Component' ][ 'System' ].center( 16 ) + '|' \
                          + installation[ 'Component' ][ 'Type' ].center( 12 ) + '|' \
                          + installation[ 'InstallationTime' ].strftime( "%d-%m-%Y %H:%M" ).center( 18 ) + '|' \
                          + installedBy.center( 12 ) + '|' \
                          + uninstalledOn.center( 18 ) + '|' \
                          + uninstalledBy.center( 12 ) + '|' )
          gLogger.notice( ( '-' ) * 164 )
        elif display == 'list':
          gLogger.notice( '' )
          gLogger.notice( 'Installation: '.rjust( 20 ) + str ( i + 1 ) )
          gLogger.notice( 'Installed: '.rjust( 20 ) + isInstalled )
          gLogger.notice( 'Host: '.rjust( 20 ) + installation[ 'Host' ][ 'HostName' ] )
          gLogger.notice( 'Name: '.rjust( 20 ) + installation[ 'Instance' ] )
          gLogger.notice( 'Module: '.rjust( 20 ) + installation[ 'Component' ][ 'Module' ] )
          gLogger.notice( 'System: '.rjust( 20 ) + installation[ 'Component' ][ 'System' ] )
          gLogger.notice( 'Type: '.rjust( 20 ) + installation[ 'Component' ][ 'Type' ] )
          gLogger.notice( 'Installed on: '.rjust( 20 ) + installation[ 'InstallationTime' ].strftime( "%d-%m-%Y %H:%M" ) )
          if installedBy != '':
            gLogger.notice( 'Installed by: '.rjust( 20 ) + installedBy )
          if uninstalledOn != '':
            gLogger.notice( 'Uninstalled on: '.rjust( 20 ) + uninstalledOn )
            gLogger.notice( 'Uninstalled by: '.rjust( 20 ) + uninstalledBy )
        else:
          self.__errMsg( 'No display mode was selected' )
      gLogger.notice( '' )
Exemple #7
0
def main():
    global force

    from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller

    gComponentInstaller.exitOnError = True

    Script.registerSwitch("f", "force", "Forces the removal of the logs",
                          setForce)
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument((
        "System/Component: Full component name (ie: WorkloadManagement/Matcher)",
        "System:           Name of the DIRAC system (ie: WorkloadManagement)",
    ))
    Script.registerArgument(
        " Component:        Name of the DIRAC service (ie: Matcher)",
        mandatory=False)
    _, args = Script.parseCommandLine()

    if len(args) == 1:
        args = args[0].split("/")

    if len(args) < 2:
        Script.showHelp(exitCode=1)

    system = args[0]
    component = args[1]

    monitoringClient = ComponentMonitoringClient()
    result = monitoringClient.getInstallations(
        {
            "Instance": component,
            "UnInstallationTime": None
        }, {"System": system}, {"HostName": socket.getfqdn()}, True)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    if len(result["Value"]) < 1:
        gLogger.warn("Given component does not exist")
        DIRACexit(1)
    if len(result["Value"]) > 1:
        gLogger.error("Too many components match")
        DIRACexit(1)

    removeLogs = False
    if force:
        removeLogs = True
    else:
        if result["Value"][0]["Component"][
                "Type"] in gComponentInstaller.componentTypes:
            result = promptUser("Remove logs?", ["y", "n"], "n")
            if result["OK"]:
                removeLogs = result["Value"] == "y"
            else:
                gLogger.error(result["Message"])
                DIRACexit(1)

    result = gComponentInstaller.uninstallComponent(system, component,
                                                    removeLogs)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)

    result = MonitoringUtilities.monitorUninstallation(system, component)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    gLogger.notice("Successfully uninstalled component %s/%s" %
                   (system, component))
    DIRACexit()
Exemple #8
0
  def do_uninstall( self, args ):
    """
        Uninstall DIRAC component

        usage:

          uninstall db <database>
          uninstall <-f ForceLogUninstall> <system> <component>
    """
    argss = args.split()
    if not argss:
      gLogger.notice( self.do_uninstall.__doc__ )
      return
    
    option = argss[0]
    if option == 'db':
      component = argss[1]
      client = SystemAdministratorClient( self.host, self.port )

      result = client.uninstallDatabase( component )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
      else:
        gLogger.notice( "Successfully uninstalled %s" % ( component ) )

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      result = client.getAvailableDatabases()
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      system = result[ 'Value' ][ component ][ 'System' ]
      result = MonitoringUtilities.monitorUninstallation( system , component, hostname = hostname, cpu = cpu )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
    else:
      if option == '-f':
        force = True
        del argss[0]
      else:
        force = False

      if len( argss ) != 2:
        gLogger.notice( self.do_uninstall.__doc__ )
        return

      system, component = argss
      client = SystemAdministratorClient( self.host, self.port )

      monitoringClient = ComponentMonitoringClient()
      result = monitoringClient.getInstallations( { 'Instance': component, 'UnInstallationTime': None },
                                                  { 'System': system },
                                                  { 'HostName': self.host }, True )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      if len( result[ 'Value' ] ) < 1:
        self.__errMsg( "Given component does not exist" )
        return
      if len( result[ 'Value' ] ) > 1:
        self.__errMsg( "Too many components match" )
        return

      removeLogs = False
      if force:
        removeLogs = True
      else:
        if result[ 'Value' ][0][ 'Component' ][ 'Type' ] in self.runitComponents:
          result = promptUser( 'Remove logs?', ['y', 'n'], 'n' )
          if result[ 'OK' ]:
            removeLogs = result[ 'Value' ] == 'y'

      result = client.uninstallComponent( system, component, removeLogs )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
      else:
        gLogger.notice( "Successfully uninstalled %s/%s" % ( system, component ) )

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      result = MonitoringUtilities.monitorUninstallation( system, component, hostname = hostname, cpu = cpu )
      if not result[ 'OK' ]:
        return result
Exemple #9
0
  def getInstallations( self, argss ):
    """ Get data from the component monitoring database
    """
    display = 'table'
    installationFilter = {}
    componentFilter = {}
    hostFilter = {}

    key = None
    for arg in argss:
      if not key:
        if arg == 'list':
          display = 'list'
        elif arg == 'current':
          installationFilter[ 'UnInstallationTime' ] = None
        elif arg == '-t':
          key = 'Component.Type'
        elif arg == '-m':
          key = 'Component.Module'
        elif arg == '-s':
          key = 'Component.System'
        elif arg == '-h':
          key = 'Host.HostName'
        elif arg == '-n':
          key = 'Instance'
        elif arg == '-itb':
          key = 'InstallationTime.smaller'
        elif arg == '-ita':
          key = 'InstallationTime.bigger'
        elif arg == '-utb':
          key = 'UnInstallationTime.smaller'
        elif arg == '-uta':
          key = 'UnInstallationTime.bigger'
      else:
        if 'Component.' in key:
          componentFilter[ key.replace( 'Component.', '' ) ] = arg
        elif 'Host.' in key:
          hostFilter[ key.replace( 'Host.', '' ) ] = arg
        else:
          if 'Time.' in key:
            arg = datetime.datetime.strptime( arg, '%d-%m-%Y' )
          installationFilter[ key ] = arg
        key = None

    client = ComponentMonitoringClient()
    result = client.getInstallations( installationFilter, componentFilter, hostFilter, True )
    if not result[ 'OK' ]:
      self.__errMsg( 'Could not retrieve the installations: %s' % ( result[ 'Message' ] ) )
      installations = None
    else:
      installations = result[ 'Value' ]

    if installations:
      if display == 'table':
        gLogger.notice( '' )
        gLogger.notice( ' ' + 'Num'.center( 5 ) + ' ' \
                        + 'Host'.center( 20 ) + ' ' \
                        + 'Name'.center( 24 ) + ' ' \
                        + 'Module'.center( 24 ) + ' ' \
                        + 'System'.center( 20 ) + ' ' \
                        + 'Type'.center( 12 ) + ' ' \
                        + 'Installed on'.center( 18 ) + ' ' \
                        + 'Uninstalled on'.center( 18 ) + ' ' )
        gLogger.notice( ( '-' ) * 150 )
      for i, installation in enumerate( installations ):
        if installation[ 'UnInstallationTime' ]:
          uninstalledOn = installation[ 'UnInstallationTime' ].strftime( "%d-%m-%Y %H:%M" )
          isInstalled = 'No'
        else:
          uninstalledOn = ''
          isInstalled = 'Yes'

        if display == 'table':
          gLogger.notice( '|' + str( i + 1 ).center( 5 ) + '|' \
                          + installation[ 'Host' ][ 'HostName' ].center( 20 ) + '|' \
                          + installation[ 'Instance' ].center( 24 ) + '|' \
                          + installation[ 'Component' ][ 'Module' ].center( 24 ) + '|' \
                          + installation[ 'Component' ][ 'System' ].center( 20 ) + '|' \
                          + installation[ 'Component' ][ 'Type' ].center( 12 ) + '|' \
                          + installation[ 'InstallationTime' ].strftime( "%d-%m-%Y %H:%M" ).center( 18 ) + '|' \
                          + uninstalledOn.center( 18 ) + '|' )
          gLogger.notice( ( '-' ) * 150 )
        elif display == 'list':
          gLogger.notice( '' )
          gLogger.notice( 'Installation: '.rjust( 20 ) + str ( i + 1 ) )
          gLogger.notice( 'Installed: '.rjust( 20 ) + isInstalled )
          gLogger.notice( 'Host: '.rjust( 20 ) + installation[ 'Host' ][ 'HostName' ] )
          gLogger.notice( 'Name: '.rjust( 20 ) + installation[ 'Instance' ] )
          gLogger.notice( 'Module: '.rjust( 20 ) + installation[ 'Component' ][ 'Module' ] )
          gLogger.notice( 'System: '.rjust( 20 ) + installation[ 'Component' ][ 'System' ] )
          gLogger.notice( 'Type: '.rjust( 20 ) + installation[ 'Component' ][ 'Type' ] )
          gLogger.notice( 'Installed on: '.rjust( 20 ) + installation[ 'InstallationTime' ].strftime( "%d-%m-%Y %H:%M" ) )
          if uninstalledOn != '':
            gLogger.notice( 'Uninstalled on: '.rjust( 20 ) + uninstalledOn )
        else:
          self.__errMsg( 'No display mode was selected' )
      gLogger.notice( '' )
  def do_uninstall( self, args ):
    """
        Uninstall a DIRAC component or host along with all its components

        usage:

          uninstall db <database>
          uninstall host <hostname>
          uninstall <-f ForceLogUninstall> <system> <component>
    """
    argss = args.split()
    if not argss:
      gLogger.notice( self.do_uninstall.__doc__ )
      return

    # Retrieve user uninstalling the component
    result = getProxyInfo()
    if not result[ 'OK' ]:
      self._errMsg( result[ 'Message'] )
    user = result[ 'Value' ][ 'username' ]

    option = argss[0]
    if option == 'db':
      del argss[0]
      if not argss:
        gLogger.notice( self.do_uninstall.__doc__ )
        return
      component = argss[0]
      client = SystemAdministratorClient( self.host, self.port )

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      result = client.getAvailableDatabases()
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return
      system = result[ 'Value' ][ component ][ 'System' ]
      result = MonitoringUtilities.monitorUninstallation( system , component, hostname = hostname, cpu = cpu )
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return

      result = client.uninstallDatabase( component )
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
      else:
        gLogger.notice( "Successfully uninstalled %s" % ( component ) )
    elif option == 'host':
      del argss[0]
      if not argss:
        gLogger.notice( self.do_uninstall.__doc__ )
        return
      hostname = argss[0]

      client = ComponentMonitoringClient()
      result = client.hostExists( { 'HostName': hostname } )
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
      else:
        if not result[ 'Value' ]:
          self._errMsg( 'Given host does not exist' )
        else:
          result = client.getHosts( {'HostName': hostname }, True, False )
          if not result[ 'OK' ]:
            self._errMsg( result[ 'Message' ] )
          else:
            host = result[ 'Value' ][0]
            # Remove every installation associated with the host
            for installation in host[ 'Installations' ]:
              result = client.removeInstallations( installation, {}, { 'HostName': hostname } )
              if not result[ 'OK' ]:
                self._errMsg( result[ 'Message' ] )
                break
            # Finally remove the host
            result = client.removeHosts( { 'HostName': hostname } )
            if not result[ 'OK' ]:
              self._errMsg( result[ 'Message' ] )
            else:
              gLogger.notice( 'Host %s was successfully removed' % hostname )
    else:
      if option == '-f':
        force = True
        del argss[0]
      else:
        force = False

      if len( argss ) != 2:
        gLogger.notice( self.do_uninstall.__doc__ )
        return

      system, component = argss
      client = SystemAdministratorClient( self.host, self.port )

      monitoringClient = ComponentMonitoringClient()
      result = monitoringClient.getInstallations( { 'Instance': component, 'UnInstallationTime': None },
                                                  { 'System': system },
                                                  { 'HostName': self.host }, True )
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return
      if len( result[ 'Value' ] ) < 1:
        self._errMsg( "Given component does not exist" )
        return
      if len( result[ 'Value' ] ) > 1:
        self._errMsg( "Too many components match" )
        return

      removeLogs = False
      if force:
        removeLogs = True
      else:
        if result[ 'Value' ][0][ 'Component' ][ 'Type' ] in self.runitComponents:
          result = promptUser( 'Remove logs?', ['y', 'n'], 'n' )
          if result[ 'OK' ]:
            removeLogs = result[ 'Value' ] == 'y'

      result = client.uninstallComponent( system, component, removeLogs )
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
      else:
        gLogger.notice( "Successfully uninstalled %s/%s" % ( system, component ) )

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      result = MonitoringUtilities.monitorUninstallation( system, component, hostname = hostname, cpu = cpu )
      if not result[ 'OK' ]:
        return result