-
Notifications
You must be signed in to change notification settings - Fork 50
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
Conversation
if not name: | ||
name = 'subnet-{0}'.format(uuid.uuid4()) | ||
region = self.provider.region_name | ||
if region is not None and zone is not None: |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: fixed in #74.
There was a problem hiding this 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') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 Report
@@ 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
Continue to review full report at Codecov.
|
@@ -626,28 +626,27 @@ def list(self, limit=None, marker=None, filter=None): | |||
except: | |||
return [] | |||
|
|||
def create(self, name): | |||
def _create(self, name, autoCreateSubnetworks): |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 ' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
...
@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... |
@nuwang @afgane @baizhang @mbookman