Exemplo n.º 1
0
  def RunCommand(self, argv):
    if not FLAGS['continue'].value and len(argv) < 2:
      raise app.UsageError(
          'You must specify at least one instance and a destination zone.')

    if FLAGS['continue'].value and argv:
      raise app.UsageError(
          'You cannot specify instances or a destination zone when continuing '
          'a failed move.')

    credentials = gce_util.get_credentials()
    api = gce.get_api(
        credentials,
        version=FLAGS.service_version,
        default_project=FLAGS.project)

    if not FLAGS['continue'].value:
      name_regexes = argv[:-1]
      dest_zone = argv[-1]
    else:
      name_regexes = None
      dest_zone = None
    args = collections.namedtuple(
        'Namespace', ['name_regexes', 'dest_zone', 'replay_log_file'])(
            name_regexes, dest_zone, FLAGS['continue'].value)
    InstanceMigrator(api)(args)
    return True
Exemplo n.º 2
0
    def Initialize(self):
        credentials = gce_util.get_credentials()

        self.api = gce_v1beta12.GoogleComputeEngine(
            credentials,
            default_project=CLOUD9_PROJECT,
            default_zone="us-east1-a",
            default_image=CLOUD9_IMAGE,
            default_machine_type="n1-standard-1")
Exemplo n.º 3
0
 def Initialize(self):
   credentials = gce_util.get_credentials()
   
   self.api = gce_v1beta12.GoogleComputeEngine(
       credentials,
       default_project=CLOUD9_PROJECT,
       default_zone="us-east1-a",
       default_image=CLOUD9_IMAGE,
       default_machine_type="n1-standard-1")
Exemplo n.º 4
0
def main():
  # Performs the oauth2 dance.
  credentials = gce_util.get_credentials()

  # Grabs default values. Defaults can be saved in ~/.gce.config in
  # the following format:
  #
  # [gce_config]
  # project: my-project
  # image: projects/google/images/ubuntu-12-04-v20120621
  # zone: us-east-a
  # machine_type: n1-standard-1
  defaults = gce_util.get_defaults()

  if DEFAULT_PROJECT is None and defaults.project is None:
    print 'Please specify a default project by editing DEFAULT_PROJECT in'
    print 'this script or by using a ~/gce.config file.'
    exit(1)

  # Constructs an instance of GoogleComputeEngine.
  api = gce.get_api(
      credentials,
      logging_level=LOG_LEVEL,
      default_project=defaults.project or DEFAULT_PROJECT,
      default_zone=defaults.zone or DEFAULT_ZONE,
      default_image=defaults.image or DEFAULT_IMAGE,
      default_machine_type=defaults.machine_type or DEFAULT_MACHINE_TYPE)

  # Prints project info.
  print api.get_project()

  # Creates an instance asynchronously.
  print api.insert_instance(
      'i-was-created-asynchronously',
      networkInterfaces=shortcuts.network(),
      blocking=False)

  # Creates 9 test instances synchronously.
  names = ['test-instance-{0}'.format(i) for i in xrange(9)]
  print api.insert_instances(names, networkInterfaces=shortcuts.network())

  # Prints the names of all instances in the given project.
  for instance in api.all_instances():
    print instance.name

  # Prints the number of instances by zone.
  print get_instances_by_zone(api)

  # Deletes the asynchronously-created instance.
  print api.delete_instance('i-was-created-asynchronously', blocking=False)

  # Deletes the test instances synchronously.
  print api.delete_instances(names)

  # Prints the number of operations.
  print len(list(api.all_operations()))
Exemplo n.º 5
0
def main():
  # Create command line options parser.
  parser = optparse.OptionParser()
  parser.add_option('-p', '--project', dest='project',
                    help='Project to use', default=None)
  parser.add_option('-d', '--debug', action='store_true', dest='debug',
                    help='Run in debug mode.', default=False)
  parser.add_option('-a', '--aliases', action='store_true', dest='aliases',
                    help='Enable aliases.')
  parser.add_option('-n', '--noaliases', action='store_false',
                    dest='aliases', help='Disable aliases.')
  parser.add_option('--config',
                    dest='config_file', help='The configuration file to use.')
  parser.add_option('-t', '--trace_token', dest='trace_token',
                    help='A Google-provided token for tracing API calls.')
  parser.set_default('config_file', gce_util.DEFAULT_GCE_CONFIG_FILE)
  parser.set_default('aliases', None)
  add_version_options(parser)
  # Parse command line args.
  options, args = parser.parse_args()
  if options.aliases is None:
    options.aliases = sys.stdin.isatty() and not args

  # Load default settings from the given config file.
  defaults = gce_util.get_defaults(options.config_file)

  # Create an instance of the GoogleComputeEngine client.
  api = gce.get_api(
      gce_util.get_credentials(),
      logging_level=logging.DEBUG if options.debug else logging.ERROR,
      default_image=defaults.image,
      default_machine_type=defaults.machine_type,
      default_network=defaults.network,
      default_project=options.project or defaults.project,
      default_zone=defaults.zone,
      version=options.service_version,
      trace_token=options.trace_token)

  # Build the dictionary of commands (bound GCE API functions).
  commands = create_commands(options, api)
  if args:
    # execute the file provided
    execfile(args[0], commands, {})
  else:
    # Enter interactive mode.
    interact(options, commands)
Exemplo n.º 6
0
def main():
  '''Uses gcelib (now deprecated) to get instance names and quotas for your project
  '''
  # Performs oauth2 authentication. You must be authenticated
  # before you can access and modify your resurces.
  # get_credentials() does all the hard work.
  credentials = gce_util.get_credentials()

  # Constructs a new GoogleComputeEngine object with the
  # given defaults (in this case, the object corresponds
  # to the latest version of the API).
  api = gce.get_api(
      credentials,
			default_project='google.com:sakura',  # Change this to your project's name.
      default_zone='us-central1-a',  # Or some other zone.
      default_image='projects/google/images/gcel-12-04-v20121106',
      default_machine_type='n1-standard-1')

  # Place future code here to follow along with the examples.
  p = api.get_project()
  #my_new_instance = api.insert_instance(my_instance, name='my-new-instance-with-network', networkInterfaces=shortcuts.network())

  print "= Project: '{}' =".format(p.name)
  print "Description: '''{}'''".format(p.description)
  print "Id: {} # Not the project_id unfortunately!".format(p.id)
  print "Ext IPs: [{}]".format(','.join(p.externalIpAddresses))
  ssh_keys = getMetadata(p,'sshKeys')
  print "SSH Keys: {}".format(ssh_keys.splitlines().__len__())

  #pprint(p, depth=2)

  print "Instances: "
  for instance in api.all_instances():
    print " - {}\t# {}".format(instance.name,instance.description)

  print 'Usage/quotas:'
  for q in p.quotas:
    print " {}:\t{}/{}".format(q.metric,q.usage,q.limit)