-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Added arguments to create a swarm with a custom address pool and subnet size. #2201
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
Closed
originalgremlin
wants to merge
4
commits into
docker:master
from
originalgremlin:2200-swarm-default-addr-pool
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e941c51
Added arguments to creeate a swarm with a custom address pool and sub…
b7d93f6
Check API version before setting swarm addr pool.
6e21b83
Removed accidental whitespace.
originalgremlin 422d101
Split monolithic integration tests into individual tests.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Check API version before setting swarm addr pool.
Also corrected a documentation error: the default API version from constants is currently 1.35, not 1.30 as was sometimes listed. Signed-off-by: Barry Shapira <[email protected]>
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import logging | ||
| from six.moves import http_client | ||
| from ..constants import DEFAULT_SWARM_ADDR_POOL, DEFAULT_SWARM_SUBNET_SIZE | ||
| from .. import errors | ||
| from .. import types | ||
| from .. import utils | ||
|
|
@@ -82,7 +83,7 @@ def get_unlock_key(self): | |
|
|
||
| @utils.minimum_version('1.24') | ||
| def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377', | ||
| default_addr_pool=[], subnet_size=24, | ||
| default_addr_pool=None, subnet_size=None, | ||
| force_new_cluster=False, swarm_spec=None): | ||
| """ | ||
| Initialize a new Swarm using the current connected engine as the first | ||
|
|
@@ -106,9 +107,9 @@ def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377', | |
| default_addr_pool (list of strings): Default Address Pool specifies | ||
| default subnet pools for global scope networks. Each pool | ||
| should be specified as a CIDR block, like '10.0.0.0/16'. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Might be good to use the default as the example. |
||
| Default: [] | ||
| Default: None | ||
| subnet_size (int): SubnetSize specifies the subnet size of the | ||
| networks created from the default subnet pool. Default: 24 | ||
| networks created from the default subnet pool. Default: None | ||
| force_new_cluster (bool): Force creating a new Swarm, even if | ||
| already part of one. Default: False | ||
| swarm_spec (dict): Configuration settings of the new Swarm. Use | ||
|
|
@@ -124,8 +125,28 @@ def init_swarm(self, advertise_addr=None, listen_addr='0.0.0.0:2377', | |
| """ | ||
|
|
||
| url = self._url('/swarm/init') | ||
|
|
||
| if swarm_spec is not None and not isinstance(swarm_spec, dict): | ||
| raise TypeError('swarm_spec must be a dictionary') | ||
|
|
||
| if default_addr_pool is not None: | ||
| if utils.version_lt(self._version, '1.39'): | ||
| raise errors.InvalidVersion( | ||
| 'Address pool is only available for API version >= 1.39' | ||
| ) | ||
| # subnet_size becomes 0 if not set with default_addr_pool | ||
| if subnet_size is None: | ||
| subnet_size = DEFAULT_SWARM_SUBNET_SIZE | ||
|
|
||
| if subnet_size is not None: | ||
| if utils.version_lt(self._version, '1.39'): | ||
| raise errors.InvalidVersion( | ||
| 'Subnet size is only available for API version >= 1.39' | ||
| ) | ||
| # subnet_size is ignored if set without default_addr_pool | ||
| if default_addr_pool is None: | ||
| default_addr_pool = DEFAULT_SWARM_ADDR_POOL | ||
|
|
||
| data = { | ||
| 'AdvertiseAddr': advertise_addr, | ||
| 'ListenAddr': listen_addr, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ def get_unlock_key(self): | |
| get_unlock_key.__doc__ = APIClient.get_unlock_key.__doc__ | ||
|
|
||
| def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377', | ||
| default_addr_pool=[], subnet_size=24, | ||
| default_addr_pool=None, subnet_size=None, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here for parameters. |
||
| force_new_cluster=False, **kwargs): | ||
| """ | ||
| Initialize a new swarm on this Engine. | ||
|
|
@@ -58,9 +58,9 @@ def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377', | |
| default_addr_pool (list of str): Default Address Pool specifies | ||
| default subnet pools for global scope networks. Each pool | ||
| should be specified as a CIDR block, like '10.0.0.0/16'. | ||
| Default: [] | ||
| Default: None | ||
| subnet_size (int): SubnetSize specifies the subnet size of the | ||
| networks created from the default subnet pool. Default: 24 | ||
| networks created from the default subnet pool. Default: None | ||
| force_new_cluster (bool): Force creating a new Swarm, even if | ||
| already part of one. Default: False | ||
| task_history_retention_limit (int): Maximum number of tasks | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should add new parameters at the end of the list so that callers of
init_swarmthat use ordered (i.e.: unnamed) parameters continue to work as expected.e.g.: An existing function could call:
Which would now break.