mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Move checks for private_key file existence and permissions to create function
Fixes #30817
This commit is contained in:
parent
f1cf027308
commit
e79321b418
1 changed files with 33 additions and 39 deletions
|
@ -190,33 +190,6 @@ def __virtual__():
|
|||
if get_dependencies() is False:
|
||||
return False
|
||||
|
||||
for provider, details in six.iteritems(__opts__['providers']):
|
||||
if 'ec2' not in details:
|
||||
continue
|
||||
|
||||
parameters = details['ec2']
|
||||
|
||||
if not os.path.exists(parameters['private_key']):
|
||||
raise SaltCloudException(
|
||||
'The EC2 key file {0!r} used in the {1!r} provider '
|
||||
'configuration does not exist\n'.format(
|
||||
parameters['private_key'],
|
||||
provider
|
||||
)
|
||||
)
|
||||
|
||||
key_mode = str(
|
||||
oct(stat.S_IMODE(os.stat(parameters['private_key']).st_mode))
|
||||
)
|
||||
if key_mode not in ('0400', '0600'):
|
||||
raise SaltCloudException(
|
||||
'The EC2 key file {0!r} used in the {1!r} provider '
|
||||
'configuration needs to be set to mode 0400 or 0600\n'.format(
|
||||
parameters['private_key'],
|
||||
provider
|
||||
)
|
||||
)
|
||||
|
||||
return __virtualname__
|
||||
|
||||
|
||||
|
@ -227,7 +200,7 @@ def get_configured_provider():
|
|||
return config.is_provider_configured(
|
||||
__opts__,
|
||||
__active_provider_name__ or __virtualname__,
|
||||
('id', 'key', 'keyname', 'private_key')
|
||||
('id', 'key')
|
||||
)
|
||||
|
||||
|
||||
|
@ -2332,6 +2305,37 @@ def create(vm_=None, call=None):
|
|||
if 'provider' in vm_:
|
||||
vm_['driver'] = vm_.pop('provider')
|
||||
|
||||
# Check for private_key and keyfile name for bootstrapping new instances
|
||||
deploy = config.get_cloud_config_value(
|
||||
'deploy', vm_, __opts__, default=True
|
||||
)
|
||||
win_password = config.get_cloud_config_value(
|
||||
'win_password', vm_, __opts__, default=''
|
||||
)
|
||||
key_filename = config.get_cloud_config_value(
|
||||
'private_key', vm_, __opts__, search_global=False, default=None
|
||||
)
|
||||
if deploy or (deploy and win_password == 'auto'):
|
||||
# The private_key and keyname settings are only needed for bootstrapping
|
||||
# new instances when deploy is True, or when win_password is set to 'auto'
|
||||
# and deploy is true.
|
||||
if not os.path.exists(key_filename):
|
||||
raise SaltCloudException(
|
||||
'The EC2 key file {0!r} does not exist.\n'.format(
|
||||
key_filename
|
||||
)
|
||||
)
|
||||
|
||||
key_mode = str(
|
||||
oct(stat.S_IMODE(os.stat(key_filename).st_mode))
|
||||
)
|
||||
if key_mode not in ('0400', '0600'):
|
||||
raise SaltCloudException(
|
||||
'The EC2 key file {0!r} needs to be set to mode 0400 or 0600.\n'.format(
|
||||
key_filename
|
||||
)
|
||||
)
|
||||
|
||||
salt.utils.cloud.fire_event(
|
||||
'event',
|
||||
'starting create',
|
||||
|
@ -2347,15 +2351,6 @@ def create(vm_=None, call=None):
|
|||
vm_['name'], vm_['profile'], 'ec2', vm_['driver']
|
||||
)
|
||||
|
||||
key_filename = config.get_cloud_config_value(
|
||||
'private_key', vm_, __opts__, search_global=False, default=None
|
||||
)
|
||||
if key_filename is not None and not os.path.isfile(key_filename):
|
||||
raise SaltCloudConfigError(
|
||||
'The defined key_filename {0!r} does not exist'.format(
|
||||
key_filename
|
||||
)
|
||||
)
|
||||
vm_['key_filename'] = key_filename
|
||||
# wait_for_instance requires private_key
|
||||
vm_['private_key'] = key_filename
|
||||
|
@ -2485,8 +2480,7 @@ def create(vm_=None, call=None):
|
|||
log.debug('Salt interface set to: {0}'.format(salt_ip_address))
|
||||
vm_['salt_host'] = salt_ip_address
|
||||
|
||||
if config.get_cloud_config_value(
|
||||
'deploy', vm_, __opts__, default=True):
|
||||
if deploy:
|
||||
display_ssh_output = config.get_cloud_config_value(
|
||||
'display_ssh_output', vm_, __opts__, default=True
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue