2014-04-12 00:45:56 +02:00
|
|
|
'''
|
|
|
|
Create GCE resources for use in integration tests.
|
|
|
|
|
2014-04-13 00:21:26 +02:00
|
|
|
Takes a prefix as a command-line argument and creates two persistent disks named
|
|
|
|
${prefix}-base and ${prefix}-extra and a snapshot of the base disk named
|
|
|
|
${prefix}-snapshot. prefix will be forced to lowercase, to ensure the names are
|
|
|
|
legal GCE resource names.
|
2014-04-12 00:45:56 +02:00
|
|
|
'''
|
|
|
|
|
|
|
|
import gce_credentials
|
2017-05-30 19:05:19 +02:00
|
|
|
import optparse
|
|
|
|
import sys
|
2014-04-12 00:45:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
parser = optparse.OptionParser(
|
2017-05-30 19:05:19 +02:00
|
|
|
usage="%s [options] <prefix>" % (sys.argv[0],), description=__doc__
|
|
|
|
)
|
2014-04-12 00:45:56 +02:00
|
|
|
gce_credentials.add_credentials_options(parser)
|
2017-05-30 19:05:19 +02:00
|
|
|
parser.add_option(
|
|
|
|
"--prefix",
|
|
|
|
action="store",
|
|
|
|
dest="prefix",
|
|
|
|
help="String used to prefix GCE resource names (default: %default)"
|
|
|
|
)
|
2014-04-12 00:45:56 +02:00
|
|
|
|
|
|
|
(opts, args) = parser.parse_args()
|
|
|
|
gce_credentials.check_required(opts, parser)
|
|
|
|
if not args:
|
2017-01-31 00:01:47 +01:00
|
|
|
parser.error("Missing required argument: name prefix")
|
2014-04-12 00:45:56 +02:00
|
|
|
return (opts, args)
|
|
|
|
|
2017-05-30 19:05:19 +02:00
|
|
|
|
2014-04-12 00:45:56 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
(opts, args) = parse_args()
|
|
|
|
gce = gce_credentials.get_gce_driver(opts)
|
|
|
|
prefix = args[0].lower()
|
|
|
|
try:
|
2017-01-31 00:01:47 +01:00
|
|
|
base_volume = gce.create_volume(
|
2017-05-30 19:05:19 +02:00
|
|
|
size=10, name=prefix + '-base', location='us-central1-a')
|
|
|
|
gce.create_volume_snapshot(base_volume, name=prefix + '-snapshot')
|
|
|
|
gce.create_volume(size=10, name=prefix + '-extra', location='us-central1-a')
|
2015-08-27 20:58:51 +02:00
|
|
|
except KeyboardInterrupt as e:
|
2015-08-27 21:02:35 +02:00
|
|
|
print("\nExiting on user command.")
|