Skip to content

Commit

Permalink
[google compute] Add support for Subnetworks
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Johnson <erjohnso@google.com>
  • Loading branch information
erjohnso committed May 7, 2016
1 parent 9eb0507 commit 3246566
Show file tree
Hide file tree
Showing 17 changed files with 954 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ General
Compute
~~~~~~~

- Add Subnetworks to GCE driver
(GITHUB-780)
[Eric Johnson]

- Fix missing pricing data for GCE
(LIBCLOUD-713, GITHUB-779)
[Eric Johnson]
Expand Down
82 changes: 79 additions & 3 deletions demos/gce_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ def clean_up(gce, base_name, node_list=None, resource_list=None):
raise


# ==== COMPUTE CODE STARTS HERE ====
def main_compute():
start_time = datetime.datetime.now()
display('Compute demo/test start time: %s' % str(start_time))
Expand Down Expand Up @@ -300,6 +299,9 @@ def main_compute():
firewalls = gce.ex_list_firewalls()
display('Firewalls:', firewalls)

subnetworks = gce.ex_list_subnetworks()
display('Subnetworks:', subnetworks)

networks = gce.ex_list_networks()
display('Networks:', networks)

Expand All @@ -317,8 +319,78 @@ def main_compute():

# == Clean up any old demo resources ==
display('Cleaning up any "%s" resources' % DEMO_BASE_NAME)
# Delete subnetworks first, networks last
clean_up(gce, DEMO_BASE_NAME, None, subnetworks)
clean_up(gce, DEMO_BASE_NAME, all_nodes,
all_addresses + all_volumes + firewalls + networks + snapshots)
all_addresses + all_volumes + firewalls + snapshots + networks)

# == Create a Legacy Network ==
display('Creating Legacy Network:')
name = '%s-legacy-network' % DEMO_BASE_NAME
cidr = '10.10.0.0/16'
network_legacy = gce.ex_create_network(name, cidr)
display(' Network %s created' % name)

# == Delete the Legacy Network ==
display('Delete Legacy Network:')
network_legacy.destroy()
display(' Network %s delete' % name)

# == Create an auto network ==
display('Creating Auto Network:')
name = '%s-auto-network' % DEMO_BASE_NAME
network_auto = gce.ex_create_network(name, cidr=None, mode='auto')
display(' AutoNetwork %s created' % network_auto.name)

# == Display subnetworks from the auto network ==
subnets = []
for sn in network_auto.subnetworks:
subnets.append(gce.ex_get_subnetwork(sn))
display('Display subnetworks:', subnets)

# == Delete the auto network ==
display('Delete Auto Network:')
network_auto.destroy()
display(' AutoNetwork %s deleted' % name)

# == Create an custom network ==
display('Creating Custom Network:')
name = '%s-custom-network' % DEMO_BASE_NAME
network_custom = gce.ex_create_network(name, cidr=None, mode='custom')
display(' Custom Network %s created' % network_custom.name)

# == Create a subnetwork ==
display('Creating Subnetwork:')
sname = '%s-subnetwork' % DEMO_BASE_NAME
region = 'us-central1'
cidr = '192.168.17.0/24'
subnet = gce.ex_create_subnetwork(sname, cidr, network_custom, region)
display(' Subnetwork %s created' % subnet.name)
# Refresh object, now that it has a subnet
network_custom = gce.ex_get_network(name)

# == Display subnetworks from the auto network ==
subnets = []
for sn in network_custom.subnetworks:
subnets.append(gce.ex_get_subnetwork(sn))
display('Display custom subnetworks:', subnets)

# == Delete an subnetwork ==
display('Delete Custom Subnetwork:')
subnet.destroy()
display(' Custom Subnetwork %s deleted' % sname)
is_deleted = False
while not is_deleted:
time.sleep(3)
try:
subnet = gce.ex_get_subnetwork(sname, region)
except ResourceNotFoundError:
is_deleted = True

# == Delete the auto network ==
display('Delete Custom Network:')
network_custom.destroy()
display(' Custom Network %s deleted' % name)

# == Create Node with disk auto-created ==
if MAX_NODES > 1:
Expand Down Expand Up @@ -480,6 +552,9 @@ def main_compute():
firewalls = gce.ex_list_firewalls()
display('Firewalls:', firewalls)

subnetworks = gce.ex_list_subnetworks()
display('Subnetworks:', subnetworks)

networks = gce.ex_list_networks()
display('Networks:', networks)

Expand All @@ -488,8 +563,9 @@ def main_compute():

if CLEANUP:
display('Cleaning up %s resources created' % DEMO_BASE_NAME)
clean_up(gce, DEMO_BASE_NAME, None, subnetworks)
clean_up(gce, DEMO_BASE_NAME, nodes,
addresses + firewalls + networks + snapshots)
addresses + firewalls + snapshots + networks)
volumes = gce.list_volumes()
clean_up(gce, DEMO_BASE_NAME, None, volumes)
end_time = datetime.datetime.now()
Expand Down
Loading

0 comments on commit 3246566

Please sign in to comment.