Exemplo n.º 1
0
def main():
  (args, params) = parseArguments()

  opts = {'verbose': args.verbose,
          'console': True,
          }
  log.init_logging(opts)

  ecs_api = api.EcsApi(args.access_key, args.access_key_secret)
  if args.info and args.api:
    api_info = ecs_api.get_api_info(args.api)
    print_api_info(api_info)
    return 0

  if args.info:
    api_list = ecs_api.get_available_apis()
    print_api_list(api_list)
    return 0

  method = getattr(ecs_api, args.api)
  if not method:
    log.error("API %s not implemented", args.api)
    raise exp.InvalidParameterValue(opt_name="api", opt_value=method)

  resp = method(**params)
  print "Aliyun ECS API %s results:\n%s" % (args.api, json.dumps(resp,
                                                                 indent=2,
                                                                 sort_keys=True))

  return 0
Exemplo n.º 2
0
def prepare():
    args = parseArguments()
    log.init_logging({'verbose': args.verbose,
                      'console': args.console,
                      'logfile': args.logfile,
                      })

    if not os.path.isfile(args.pmt):
        log.error("Error: file %s not exists", args.pmt)
        raise exp.InvalidConfigurationOption(opt_name='pmt', opt_value=args.pmt)

    return args
Exemplo n.º 3
0
def prepare():
    args = parseArguments()
    log.init_logging({
        'verbose': args.verbose,
        'console': args.console,
        'logfile': args.logfile,
    })

    if not os.path.isfile(args.pmt):
        log.error("Error: file %s not exists", args.pmt)
        raise exp.InvalidConfigurationOption(opt_name='pmt',
                                             opt_value=args.pmt)

    return args
Exemplo n.º 4
0
def prepare():
  args = parseArguments()

  log.init_logging({'verbose': args.verbose,
                    'console': args.console,
                    'logfile': args.logfile})

  if args.boot is True and args.ecs_name is None:
    log.error("ecs_name must be given in boot mode")
    raise exp.InvalidConfigurationOption(opt_name="ecs_name",
                                         opt_val=None)

  if not os.path.isfile(args.pmt):
    log.error("file %s not exists", args.pmt)
    raise exp.InvalidConfigurationOption(opt_name='pmt',
                                         opt_value=args.pmt)

  if not os.path.isfile(args.template):
    log.error("template file %s not exists", args.template)
    raise exp.InvalidConfigurationOption(opt_name='template',
                                         opt_value=args.template)

  return args
Exemplo n.º 5
0
def prepare():
  args = parseArguments()
  pid = str(os.getpid())
  pidfile = args.pid

  log.init_logging({'verbose': args.verbose,
                    'console': args.console,
                    'logfile': args.logfile})

  if utils.check_pid(pidfile) is True:
    log.error("Pid %s already exists, exiting.", pidfile)
    sys.exit()
  else:
    file(pidfile, 'w').write(pid)

  metric_def = validate_metric(args.metric, args.value)

  # initialize statsdclient
  global statsd_client

  statsd_client = StatsClient(host=args.server, port=args.port,
                              prefix=(args.prefix + "." + args.source
                                      if args.prefix is not None else args.source))
  return (args, metric_def)
Exemplo n.º 6
0
def prepare():
    args = parseArguments()

    log.init_logging({
        'verbose': args.verbose,
        'console': args.console,
        'logfile': args.logfile
    })

    if args.boot is True and args.ecs_name is None:
        log.error("ecs_name must be given in boot mode")
        raise exp.InvalidConfigurationOption(opt_name="ecs_name", opt_val=None)

    if not os.path.isfile(args.pmt):
        log.error("file %s not exists", args.pmt)
        raise exp.InvalidConfigurationOption(opt_name='pmt',
                                             opt_value=args.pmt)

    if not os.path.isfile(args.template):
        log.error("template file %s not exists", args.template)
        raise exp.InvalidConfigurationOption(opt_name='template',
                                             opt_value=args.template)

    return args
Exemplo n.º 7
0
  def setUp(self):
    super(BaseTestCase, self).setUp()

    # initialize logging
    opts = { 'verbose': True, 'console': True }
    log.init_logging(opts)