Ejemplo n.º 1
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()
Ejemplo n.º 2
0
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:
  if result[ 'Value' ][0][ 'Component' ][ 'Type' ] in InstallTools.COMPONENT_TYPES:
    result = promptUser( 'Remove logs?', [ 'y', 'n' ], 'n' )
    if result[ 'OK' ]:
      removeLogs = result[ 'Value' ] == 'y'
    else:
      gLogger.error( result[ 'Message' ] )
      DIRACexit( 1 )

result = InstallTools.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()
Ejemplo n.º 3
0
    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()
Ejemplo n.º 4
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

    # 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
Ejemplo n.º 5
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()
Ejemplo n.º 6
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
Ejemplo n.º 7
0
  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