mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
Adds support for creating GCE persistent disks from snapshots
This commit is contained in:
parent
0b45b1256d
commit
d227330a55
6 changed files with 183 additions and 7 deletions
40
test/integration/setup_gce.py
Normal file
40
test/integration/setup_gce.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
'''
|
||||
Create GCE resources for use in integration tests.
|
||||
|
||||
Takes a prefix as a command-line argument and creates a persistent disk
|
||||
named ${prefix}-base and a snapshot of it named ${prefix}-snapshot.
|
||||
prefix will be forced to lowercase, to ensure the names are legal GCE
|
||||
resource names.
|
||||
'''
|
||||
|
||||
import sys
|
||||
import optparse
|
||||
|
||||
import gce_credentials
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = optparse.OptionParser(
|
||||
usage="%s [options] <prefix>" % (sys.argv[0],), description=__doc__)
|
||||
gce_credentials.add_credentials_options(parser)
|
||||
parser.add_option("--prefix",
|
||||
action="store", dest="prefix",
|
||||
help="String used to prefix GCE resource names (default: %default)")
|
||||
|
||||
(opts, args) = parser.parse_args()
|
||||
gce_credentials.check_required(opts, parser)
|
||||
if not args:
|
||||
parser.error("Missing required argument: name prefix")
|
||||
return (opts, args)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
(opts, args) = parse_args()
|
||||
gce = gce_credentials.get_gce_driver(opts)
|
||||
prefix = args[0].lower()
|
||||
try:
|
||||
base_volume = gce.create_volume(
|
||||
size=10, name=prefix+'-base', location='us-central1-a')
|
||||
gce.create_volume_snapshot(base_volume, name=prefix+'-snapshot')
|
||||
except KeyboardInterrupt, e:
|
||||
print "\nExiting on user command."
|
Loading…
Add table
Add a link
Reference in a new issue