Example #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
Example #2
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)
Example #3
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