From 8ec9ab937d6fff8821a4abedc6cf9043f74ef857 Mon Sep 17 00:00:00 2001 From: Joseph Hall Date: Mon, 8 Dec 2014 13:54:25 -0700 Subject: [PATCH] Allow userdata to be passed to EC2 --- salt/cloud/clouds/ec2.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/salt/cloud/clouds/ec2.py b/salt/cloud/clouds/ec2.py index 129853427d..14aba6d903 100644 --- a/salt/cloud/clouds/ec2.py +++ b/salt/cloud/clouds/ec2.py @@ -1394,6 +1394,22 @@ def request_instance(vm_=None, call=None): image_id = vm_['image'] params[spot_prefix + 'ImageId'] = image_id + userdata_file = config.get_cloud_config_value( + 'userdata_file', vm_, __opts__, search_global=False, default=None + ) + if userdata_file is None: + userdata = config.get_cloud_config_value( + 'userdata', vm_, __opts__, search_global=False, default=None + ) + else: + log.trace('userdata_file: {0}'.format(userdata_file)) + if os.path.exists(userdata_file): + with salt.utils.fopen(userdata_file, 'r') as fh_: + userdata = fh_.read() + + if userdata is not None: + params['UserData'] = base64.b64encode(userdata) + vm_size = config.get_cloud_config_value( 'size', vm_, __opts__, search_global=False ) @@ -1889,6 +1905,25 @@ def wait_for_instance( win_passwd = config.get_cloud_config_value( 'win_password', vm_, __opts__, default='' ) + if win_passwd and win_passwd == 'auto': + log.debug('Waiting for auto-generated Windows EC2 password') + while True: + password_data = get_password_data( + name=vm_['name'], + kwargs={ + 'key_file': vm_['private_key'], + }, + call='action', + ) + log.debug(password_data) + win_passwd = password_data.get('password', None) + if win_passwd is None: + # This wait is so high, because the password is unlikely to + # be generated for at least 4 minutes + time.sleep(60) + else: + break + if not salt.utils.cloud.wait_for_port(ip_address, port=445, timeout=ssh_connect_timeout): @@ -3858,7 +3893,7 @@ def get_password_data( ret = {} data = aws.query(params, - return_url=True, + return_root=True, location=get_location(), provider=get_provider(), opts=__opts__,