Last active
June 13, 2016 01:09
-
-
Save iggy/8389725d25db437b521caf1aa2585b73 to your computer and use it in GitHub Desktop.
first cut at ssh key support for salt-cloud vultr provider
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
| diff --git a/salt/cloud/clouds/vultrpy.py b/salt/cloud/clouds/vultrpy.py | |
| index 2c88884..29959fd 100644 | |
| --- a/salt/cloud/clouds/vultrpy.py | |
| +++ b/salt/cloud/clouds/vultrpy.py | |
| @@ -9,15 +9,22 @@ The Vultr cloud module is used to control access to the Vultr VPS system. | |
| Use of this module only requires the ``api_key`` parameter. | |
| +You can optionally use ssh keys for the bootstrapping phase. See the example below. | |
| + | |
| Set up the cloud configuration at ``/etc/salt/cloud.providers`` or | |
| ``/etc/salt/cloud.providers.d/vultr.conf``: | |
| .. code-block:: yaml | |
| -my-vultr-config: | |
| - # Vultr account api key | |
| - api_key: <supersecretapi_key> | |
| - driver: vultr | |
| + my-vultr-config: | |
| + # Vultr account api key | |
| + api_key: <supersecretapi_key> | |
| + driver: vultr | |
| + # Sometimes the below is needed to work around timing issues with Vultr's API | |
| + #hard_timeout: null | |
| + # To use SSH keys to bootstrap intead of the password | |
| + #ssh_key_file: /etc/salt/cloud.deploy.d/salt-cloud-ssh-private | |
| + #ssh_key_ids: 000a0a0a00000,0129a9000b999,2222c019494 | |
| Set up the cloud profile at ``/etc/salt/cloud.profiles`` or | |
| ``/etc/salt/cloud.profiles.d/vultr.conf``: | |
| @@ -31,6 +38,14 @@ Set up the cloud profile at ``/etc/salt/cloud.profiles`` or | |
| size: 95 | |
| enable_private_network: True | |
| +You can get a list of ssh keys, images, sizes, and locations with the following commands | |
| + | |
| +.. code-block:: shell | |
| + salt-cloud -f list_keypairs my-vultr-config | |
| + salt-cloud --list-locations my-vultr-config | |
| + salt-cloud --list-images my-vultr-config | |
| + salt-cloud --list-sizes my-vultr-config | |
| + | |
| ''' | |
| # Import python libs | |
| @@ -123,6 +138,13 @@ def avail_images(conn=None): | |
| return _query('os/list') | |
| +def list_keypairs(conn=None, call=None): | |
| + ''' | |
| + Return a list of configured ssh keypairs | |
| + ''' | |
| + return _query('sshkey/list') | |
| + | |
| + | |
| def list_nodes(**kwargs): | |
| ''' | |
| Return basic data on nodes | |
| @@ -240,6 +262,24 @@ def create(vm_): | |
| else: | |
| enable_private_network = 'no' | |
| + ipv6 = config.get_cloud_config_value( | |
| + 'ipv6', vm_, __opts__, search_global=False, default=False, | |
| + ) | |
| + | |
| + if ipv6 is not None: | |
| + if not isinstance(ipv6, bool): | |
| + raise SaltCloudConfigError("'ipv6' should be a boolean value.") | |
| + if ipv6 is True: | |
| + enable_ipv6 = 'yes' | |
| + else: | |
| + enable_ipv6 = 'no' | |
| + | |
| + ssh_keys = config.get_cloud_config_value( | |
| + 'ssh_key_ids', vm_, __opts__, search_global=False, default=False, | |
| + ) | |
| + key_filename = config.get_cloud_config_value( | |
| + 'ssh_key_file', vm_, __opts__, search_global=False, default=None | |
| + ) | |
| salt.utils.cloud.fire_event( | |
| 'event', | |
| 'starting create', | |
| @@ -271,9 +311,11 @@ def create(vm_): | |
| 'label': vm_['name'], | |
| 'OSID': osid, | |
| 'VPSPLANID': vpsplanid, | |
| + 'SSHKEYID': ssh_keys, | |
| 'DCID': dcid, | |
| 'hostname': vm_['name'], | |
| 'enable_private_network': enable_private_network, | |
| + 'enable_ipv6': enable_ipv6, | |
| } | |
| log.info('Creating Cloud VM {0}'.format(vm_['name'])) | |
| @@ -346,16 +388,18 @@ def create(vm_): | |
| return False | |
| return data['default_password'] | |
| + vm_['key_filename'] = key_filename | |
| vm_['ssh_host'] = salt.utils.cloud.wait_for_fun( | |
| wait_for_hostname, | |
| timeout=config.get_cloud_config_value( | |
| 'wait_for_fun_timeout', vm_, __opts__, default=15 * 60), | |
| ) | |
| - vm_['password'] = salt.utils.cloud.wait_for_fun( | |
| - wait_for_default_password, | |
| - timeout=config.get_cloud_config_value( | |
| - 'wait_for_fun_timeout', vm_, __opts__, default=15 * 60), | |
| - ) | |
| + if not key_filename: | |
| + vm_['password'] = salt.utils.cloud.wait_for_fun( | |
| + wait_for_default_password, | |
| + timeout=config.get_cloud_config_value( | |
| + 'wait_for_fun_timeout', vm_, __opts__, default=15 * 60), | |
| + ) | |
| __opts__['hard_timeout'] = config.get_cloud_config_value( | |
| 'hard_timeout', | |
| get_configured_provider(), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment