Esempio n. 1
0
def main(*args):
  parser = argparse.ArgumentParser()
  parser.add_argument("-m", "--message", default='', help="Message for bang.")
  parser.add_argument("configuration_file", nargs=1, type=argparse.FileType(),
      help="SlapOS configuration file.")
  if len(args) == 0:
    argument = parser.parse_args()
  else:
    argument = parser.parse_args(list(args))
  configuration_file = argument.configuration_file[0]
  message = argument.message
  # Loads config (if config specified)
  configuration = ConfigParser.SafeConfigParser()
  configuration.readfp(configuration_file)
  computer_id = configuration.get('slapos', 'computer_id')
  master_url = configuration.get('slapos', 'master_url')
  if configuration.has_option('slapos', 'key_file'):
    key_file = configuration.get('slapos', 'key_file')
  else:
    key_file = None
  if configuration.has_option('slapos', 'cert_file'):
    cert_file = configuration.get('slapos', 'cert_file')
  else:
    cert_file = None
  slap = slapos.slap.slap()
  slap.initializeConnection(master_url, key_file=key_file, cert_file=cert_file)
  computer = slap.registerComputer(computer_id)
  print 'Banging to %r' % master_url
  computer.bang(message)
  print 'Bang with message %r' % message
Esempio n. 2
0
def init(config):
  """Initialize Slap instance, connect to server and create
  aliases to common software releases"""
  slap = slapos.slap.slap()
  slap.initializeConnection(config.master_url,
      key_file=config.key_file, cert_file=config.cert_file)
  local = globals().copy()
  local['slap'] = slap
  # Create aliases as global variables
  try:
    alias = config.alias.split('\n')
  except AttributeError:
    alias = []
  software_list = []
  for software in alias:
    if software is not '':
      name, url = software.split(' ')
      software_list.append(name)
      local[name] = url
  # Create global variable too see available aliases
  local['software_list'] = software_list
  # Create global shortcut functions to request instance and software
  def shorthandRequest(*args, **kwargs):
    return slap.registerOpenOrder().request(*args, **kwargs)
  def shorthandSupply(*args, **kwargs):
    return slap.registerSupply().supply(*args, **kwargs)
  local['request'] = shorthandRequest
  local['supply'] = shorthandSupply

  return local
Esempio n. 3
0
def init(config):
  """Initialize Slap instance, connect to server and create
  aliases to common software releases"""
  slap = slapos.slap.slap()
  slap.initializeConnection(config.master_url,
      key_file=config.key_file, cert_file=config.cert_file)
  local = globals().copy()
  local['slap'] = slap
  # Create aliases as global variables
  try:
    alias = config.alias.split('\n')
  except AttributeError:
    alias = []
  software_list = []
  for software in alias:
    if software is not '':
      name, url = software.split(' ')
      software_list.append(name)
      local[name] = url
  # Create global variable too see available aliases
  local['software_list'] = software_list
  # Create global shortcut functions to request instance and software
  # XXX-Cedric : can we change given parameters to something like
  # *args, **kwargs, but without the bad parts, in order to be generic?
  def shorthandRequest(software_release, partition_reference,
      partition_parameter_kw=None, software_type=None, filter_kw=None,
      state=None):
    return slap.registerOpenOrder().request(software_release, partition_reference,
      partition_parameter_kw, software_type, filter_kw, state)
  def shorthandSupply(software_release, computer_guid=None, state='available'):
    return slap.registerSupply().supply(software_release, computer_guid, state)
  local['request'] = shorthandRequest
  local['supply'] = shorthandSupply

  return local
Esempio n. 4
0
def init(conf):
    """Initialize Slap instance, connect to server and create
  aliases to common software releases"""
    # XXX check certificate and key existence
    slap = slapos.slap.slap()
    slap.initializeConnection(conf.master_url, key_file=conf.key_file, cert_file=conf.cert_file)
    local = globals().copy()
    local["slap"] = slap
    # Create aliases as global variables
    try:
        alias = conf.alias.split("\n")
    except AttributeError:
        alias = []
    software_list = []
    for software in alias:
        if software:
            name, url = software.split(" ")
            software_list.append(name)
            local[name] = url
    # Create global variable too see available aliases
    local["software_list"] = software_list
    # Create global shortcut functions to request instance and software

    def shorthandRequest(*args, **kwargs):
        return slap.registerOpenOrder().request(*args, **kwargs)

    def shorthandSupply(*args, **kwargs):
        return slap.registerSupply().supply(*args, **kwargs)

    local["request"] = shorthandRequest
    local["supply"] = shorthandSupply

    return local
Esempio n. 5
0
 def initializeConnection(self):
     connection_dict = {}
     connection_dict['key_file'] = self.key_file
     connection_dict['cert_file'] = self.cert_file
     slap = slapos.slap.slap()
     slap.initializeConnection(self.master_url,
                               **connection_dict)
     self._slap_computer = slap.registerComputer(self.computer_id)
Esempio n. 6
0
def do_bang(configp, message):
  computer_id = configp.get('slapos', 'computer_id')
  master_url = configp.get('slapos', 'master_url')
  if configp.has_option('slapos', 'key_file'):
    key_file = configp.get('slapos', 'key_file')
  else:
    key_file = None
  if configp.has_option('slapos', 'cert_file'):
    cert_file = configp.get('slapos', 'cert_file')
  else:
    cert_file = None
  slap = slapos.slap.slap()
  slap.initializeConnection(master_url, key_file=key_file, cert_file=cert_file)
  computer = slap.registerComputer(computer_id)
  print 'Banging to %r' % master_url
  computer.bang(message)
  print 'Bang with message %r' % message
Esempio n. 7
0
def init(conf, logger):
  """Initialize Slap instance, connect to server and create
  aliases to common software releases"""
  # XXX check certificate and key existence
  slap = slapos.slap.slap()
  slap.initializeConnection(conf.master_url,
      key_file=conf.key_file, cert_file=conf.cert_file,
      slapgrid_rest_uri=conf.master_rest_url)
  local = globals().copy()
  local['slap'] = slap
  # Create global shortcut functions to request instance and software
  def shorthandRequest(*args, **kwargs):
    return slap.registerOpenOrder().request(*args, **kwargs)
  def shorthandSupply(*args, **kwargs):
    # XXX-Cedric Implement computer_group support
    return slap.registerSupply().supply(*args, **kwargs)
  local['request'] = shorthandRequest
  local['supply'] = shorthandSupply
  local['product'] = SoftwareProductCollection(logger, slap)

  return local