Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement subnetwork.get_or_create_default #67

Closed
wants to merge 4 commits into from

Conversation

chiniforooshan
Copy link
Collaborator

@coveralls
Copy link

coveralls commented Sep 1, 2017

Coverage Status

Coverage decreased (-0.1%) to 52.138% when pulling d05d4b8 on chiniforooshan:subnets into d3e9c56 on gvlproject:gce.

if not name:
name = 'subnet-{0}'.format(uuid.uuid4())
region = self.provider.region_name
if region is not None and zone is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this require explicitly checking for "None" or can it be:

if region and zone:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N/A: this part is removed in the newer version #74.

@@ -774,10 +773,13 @@ def list(self, network=None, region=None, limit=None, marker=None):
response.get('nextPageToken'),
False, data=subnets)

def create(self, network, cidr_block, name=None, zone=None):
def create(self, network, cidr_block, name=None, zone=None, region=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment explaining how regions and zones are intended to work here.
I'm not sure if the implementation reflects what had been discussed.

I think the intended implementation is:

# GCE subnets are regional. The logic for determining the subnet region here is:
# - If a region is provided, use it.
# - If a zone is provided, use the region that it belongs to.
# - If neither is provided, use the default region as set in the provider.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, region is not a method param in the interface (https://github.com/gvlproject/cloudbridge/blob/master/cloudbridge/cloud/interfaces/services.py#L728). Is it not possible to obtain the region from the zone object? and use the default region when the zone is not provided?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: fixed in #74.

if not name:
name = 'subnet-{0}'.format(uuid.uuid4())
region = self.provider.region_name
if region is not None and zone is not None:
cb.log.warning('Both parameters "zone" and "region" are provided')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the message also specify what the outcome is?
Something like:

Both parameters zone and region are provided; using region.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N/A: this part is removed in the newer version #74.

if region is not None and zone is not None:
cb.log.warning('Both parameters "zone" and "region" are provided')
if region is None:
region = self.provider.region_name
if isinstance(zone, GCEPlacementZone):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I read this, if a zone is specified it ends up being the thing used, even if a region was specified as well.
Is that what was intended?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N/A: this part is removed in the newer version #74.

if subnet.id == response['targetId']:
return subnet
except:
return None

def get_or_create_default(self, zone=None):
raise NotImplementedError('To be implemented')
"""
Every GCP project comes with a default auto mode VPC network. An auto
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is true for every new GCP project, but is not true for old projects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same situation happens on AWS so if a provider-default does not exist, we create a CloudBridge-default: https://github.com/gvlproject/cloudbridge/blob/master/cloudbridge/cloud/providers/aws/services.py#L884

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: fixed in #74.

Copy link
Contributor

@nuwang nuwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these changes. A few additional comments below. We've also been tweaking things and the main change is that networks have been moved under networking for consistency. Now, networks, subnets, routers, and gateways are all categorized under networking.

@@ -1384,7 +1384,7 @@ def region(self):

@property
def zone(self):
raise NotImplementedError('To be implemented')
raise NotImplementedError('GCP subnetworks are regional resources')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zone is an optional parameter mainly for informational purposes so it's probably better to return None here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: fixed in #74.

returns the subnetwork of the default network that spans the given
zone.
"""
network = self.provider.network.get_by_name(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be replaced by self.provider.networking.networks.find(name=GCEFirewallsDelegate.DEFAULT_NETWORK)[0]

Also, in some recent refactoring we did, networks have been moved under networking for greater consistency, and the parameter order for network.create() has been changed.

Which also brings up the question, do we need the get_by_name function since the find function exists?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N/A: this part is removed in the newer version #74.

@codecov-io
Copy link

codecov-io commented Sep 15, 2017

Codecov Report

Merging #67 into gce will decrease coverage by 0.09%.
The diff coverage is 12.5%.

Impacted file tree graph

@@            Coverage Diff            @@
##              gce      #67     +/-   ##
=========================================
- Coverage   51.06%   50.96%   -0.1%     
=========================================
  Files          21       21             
  Lines        4179     4187      +8     
  Branches      552      555      +3     
=========================================
  Hits         2134     2134             
- Misses       1996     2004      +8     
  Partials       49       49
Impacted Files Coverage Δ
cloudbridge/cloud/providers/gce/resources.py 27.44% <0%> (ø) ⬆️
cloudbridge/cloud/providers/gce/services.py 22.66% <13.33%> (-0.31%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d3e9c56...3f2a648. Read the comment docs.

@@ -626,28 +626,27 @@ def list(self, limit=None, marker=None, filter=None):
except:
return []

def create(self, name):
def _create(self, name, autoCreateSubnetworks):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autoCreateSubnetworks should be auto_create_subnetworks. Possibly even better to shorten it to just create_subnetworks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: fixed in #74.

network = self.provider.network.get_or_create_default()
subnets = self.list(network, zone)
if len(subnets) > 1:
cb.log.warning('The default network has more than one subnetwork '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to go against the intent of this method. As a user, by calling get_or_create_default I'd expect to get something back. I guess it's not likely that this condition will be triggered as it's likely there will be only one subnet for the default network so it's probably ok but I wonder if perhaps we should instead just return a random subnet here as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this line just logs a warning. Next lines will actually return something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, yes, I see. I just took the next if as else if...

@afgane
Copy link
Contributor

afgane commented Sep 15, 2017

@chiniforooshan should we close this PR given #74? There's a couple more bits here but not sure if those are a result of the the git mixup...

@chiniforooshan chiniforooshan deleted the subnets branch September 18, 2017 15:32
@nuwang nuwang added this to the release 1.0.0 milestone Oct 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants