Ejemplo n.º 1
0
 def supply(self, software_url, computer_id, state="available"):
   """
   Request the installation of a software release on a specific node
   Ex :
   my_controler.supply('kvm.cfg', 'COMP-726')
   """
   self.log('SlapOSControler : supply')
   parser = argparse.ArgumentParser()
   parser.add_argument("configuration_file")
   parser.add_argument("software_url")
   parser.add_argument("node")
   if os.path.exists(self.configuration_file_path):
     args = parser.parse_args([self.configuration_file_path, software_url, computer_id])
     config = client.Config()
     config.setConfig(args, args.configuration_file)
     try:
       local = client.init(config)
       local['supply'](software_url, computer_guid=computer_id, state=state)
       self.log('SlapOSControler : supply %s %s %s' %(software_url, computer_id, state))
     except:
       self.log("SlapOSControler.supply, \
                exception in registerOpenOrder", exc_info=sys.exc_info())
       raise ValueError("Unable to supply (or remove)")
   else:
     raise ValueError("Configuration file not found.")
Ejemplo n.º 2
0
 def supply(self, software_url, computer_id, state="available"):
     """
 Request the installation of a software release on a specific node
 Ex :
 my_controler.supply('kvm.cfg', 'COMP-726')
 """
     self.log('SlapOSControler : supply')
     parser = argparse.ArgumentParser()
     parser.add_argument("configuration_file")
     parser.add_argument("software_url")
     parser.add_argument("node")
     if os.path.exists(self.configuration_file_path):
         args = parser.parse_args(
             [self.configuration_file_path, software_url, computer_id])
         config = client.Config()
         config.setConfig(args, args.configuration_file)
         try:
             local = client.init(config)
             local['supply'](software_url,
                             computer_guid=computer_id,
                             state=state)
             self.log('SlapOSControler : supply %s %s %s' %
                      (software_url, computer_id, state))
         except:
             self.log("SlapOSControler.supply, \
              exception in registerOpenOrder",
                      exc_info=sys.exc_info())
             raise ValueError("Unable to supply (or remove)")
     else:
         raise ValueError("Configuration file not found.")
Ejemplo n.º 3
0
    def request(self,
                reference,
                software_url,
                software_type=None,
                software_configuration=None,
                computer_guid=None,
                state='started'):
        """
    configuration_file_path (slapos acount)
    reference : instance title
    software_url : software path/url
    software_type : scalability
    software_configuration : dict { "_" : "{'toto' : 'titi'}" } 

    Ex :
    my_controler._request('Instance16h34Ben',
                               'kvm.cfg', 'cluster', { "_" : "{'toto' : 'titi'}" } )

    """
        logger.debug('SlapOSControler : request-->SlapOSMaster')
        current_intance_config = {
            'software_type': software_type,
            'software_configuration': software_configuration,
            'computer_guid': computer_guid,
            'software_url': software_url,
            'requested_state': state,
            'partition': None
        }
        self.instance_config[reference] = current_intance_config

        filter_kw = None
        if computer_guid != None:
            filter_kw = {"computer_guid": computer_guid}
        if os.path.exists(self.configuration_file_path):
            parser = argparse.ArgumentParser()
            parser.add_argument("configuration_file")
            args = parser.parse_args([self.configuration_file_path])
            config = client.Config()
            config.setConfig(args, args.configuration_file)
            try:
                local = client.init(config)
                partition = local['request'](
                    software_release=software_url,
                    partition_reference=reference,
                    partition_parameter_kw=software_configuration,
                    software_type=software_type,
                    filter_kw=filter_kw,
                    state=state)
                self.instance_config[reference]['partition'] = partition
                if state == 'destroyed':
                    del self.instance_config[reference]
                elif state == 'started':
                    logger.debug('Instance started with configuration: %s',
                                 software_configuration)
            except Exception:
                logger.exception("SlapOSControler.request")
                raise ValueError("Unable to do this request")
        else:
            raise ValueError("Configuration file not found.")
Ejemplo n.º 4
0
    def take_action(self, args):
        configp = self.fetch_config(args)
        conf = ClientConfig(args, configp)

        local = init(conf, self.app.log)
        exit_code = do_info(self.app.log, conf, local)
        if exit_code != 0:
          exit(exit_code)
Ejemplo n.º 5
0
    def take_action(self, args):
        args.node = parse_option_dict(args.node)
        args.parameters = parse_option_dict(args.parameters)

        configp = self.fetch_config(args)
        conf = ClientConfig(args, configp)

        local = init(conf, self.app.log)
        do_request(self.app.log, conf, local)
Ejemplo n.º 6
0
  def request(self, reference, software_url, software_type=None,
            software_configuration=None, computer_guid=None, state='started'):
    """
    configuration_file_path (slapos acount)
    reference : instance title
    software_url : software path/url
    software_type : scalability
    software_configuration : dict { "_" : "{'toto' : 'titi'}" } 

    Ex :
    my_controler._request('Instance16h34Ben',
                               'kvm.cfg', 'cluster', { "_" : "{'toto' : 'titi'}" } )

    """
    self.log('SlapOSControler : request-->SlapOSMaster')
    current_intance_config = {'software_type':software_type,
                              'software_configuration':software_configuration,
                              'computer_guid':computer_guid,
                              'software_url':software_url,
                              'requested_state':state,
                              'partition':None
                              }
    self.instance_config[reference] = current_intance_config

    filter_kw = None
    if computer_guid != None:
      filter_kw = { "computer_guid": computer_guid }
    if os.path.exists(self.configuration_file_path):
      parser = argparse.ArgumentParser()
      parser.add_argument("configuration_file")
      args = parser.parse_args([self.configuration_file_path])
      config = client.Config()
      config.setConfig(args, args.configuration_file)
      try:
        local = client.init(config)
        partition = local['request'](
          software_release = software_url,
          partition_reference = reference,
          partition_parameter_kw = software_configuration,
          software_type = software_type,
          filter_kw = filter_kw,
          state = state)
        self.instance_config[reference]['partition'] = partition
        if state == 'destroyed':
          del self.instance_config[reference]
        if state == 'started':
          self.log('Instance started with configuration: %s' %str(software_configuration))
      except:
        self.log("SlapOSControler.request, \
              exception in registerOpenOrder", exc_info=sys.exc_info())
        raise ValueError("Unable to do this request")
    else:
      raise ValueError("Configuration file not found.")
Ejemplo n.º 7
0
    def take_action(self, args):
        configp = self.fetch_config(args)
        conf = ClientConfig(args, configp)
        local = init(conf)

        if not any([args.python, args.ipython, args.bpython]):
            args.bpython = True

        if args.ipython:
            try:
                do_ipython_console(local)
            except ShellNotFound:
                self.app.log.info('IPython not available - using plain Python shell')
                do_console(local)
        elif args.bpython:
            try:
                do_bpython_console(local)
            except ShellNotFound:
                self.app.log.info('bpython not available - using plain Python shell')
                do_console(local)
        else:
            do_console(local)
Ejemplo n.º 8
0
def console():
  description = textwrap.dedent("""\
    slapconsole allows you interact with slap API. You can play with the global
    "slap" object and with the global "request" method.

    examples :
    >>> # Request instance
    >>> request(kvm, "myuniquekvm")
    >>> # Request software installation on owned computer
    >>> supply(kvm, "mycomputer")
    >>> # Fetch instance informations on already launched instance
    >>> request(kvm, "myuniquekvm").getConnectionParameter("url")""")

  ap = argparse.ArgumentParser(description=description,
                               formatter_class=argparse.RawDescriptionHelpFormatter)

  ap.add_argument('-u', '--master_url',
                  default=None,
                  help='Url of SlapOS Master to use.')

  ap.add_argument('-k', '--key_file',
                  help="SSL Authorisation key file.")

  ap.add_argument('-c', '--cert_file',
                  help="SSL Authorisation certificate file.")

  ap.add_argument('configuration_file',
                  help='path to slapos.cfg')

  args = ap.parse_args()

  if not os.path.isfile(args.configuration_file):
    ap.error("%s: Not found or not a regular file." % args.configuration_file)

  configp = get_config_parser(args.configuration_file)
  conf = ClientConfig(args, configp)
  local = init(conf)
  do_console(local)
Ejemplo n.º 9
0
 def take_action(self, args):
     configp = self.fetch_config(args)
     conf = ClientConfig(args, configp)
     local = init(conf)
     do_supply(self.app.log, args.software_url, args.node, local)
Ejemplo n.º 10
0
    def take_action(self, args):
        configp = self.fetch_config(args)
        conf = ClientConfig(args, configp)

        local = init(conf, self.app.log)
        do_list(self.app.log, conf, local)