##// END OF EJS Templates
automation: schedule an EC2Launch run on next boot...
Gregory Szorc -
r43528:c09e8ac3 default
parent child Browse files
Show More
@@ -687,7 +687,9 b' def temporary_ec2_instances(ec2resource,'
687
687
688
688
689 @contextlib.contextmanager
689 @contextlib.contextmanager
690 def create_temp_windows_ec2_instances(c: AWSConnection, config):
690 def create_temp_windows_ec2_instances(
691 c: AWSConnection, config, bootstrap: bool = False
692 ):
691 """Create temporary Windows EC2 instances.
693 """Create temporary Windows EC2 instances.
692
694
693 This is a higher-level wrapper around ``create_temp_ec2_instances()`` that
695 This is a higher-level wrapper around ``create_temp_ec2_instances()`` that
@@ -712,6 +714,8 b' def create_temp_windows_ec2_instances(c:'
712 'Tags': [{'Key': 'Name', 'Value': 'hg-temp-windows'}],
714 'Tags': [{'Key': 'Name', 'Value': 'hg-temp-windows'}],
713 }
715 }
714 )
716 )
717
718 if bootstrap:
715 config['UserData'] = WINDOWS_USER_DATA % password
719 config['UserData'] = WINDOWS_USER_DATA % password
716
720
717 with temporary_ec2_instances(c.ec2resource, config) as instances:
721 with temporary_ec2_instances(c.ec2resource, config) as instances:
@@ -1111,6 +1115,23 b' def ensure_windows_dev_ami('
1111 with INSTALL_WINDOWS_DEPENDENCIES.open('r', encoding='utf-8') as fh:
1115 with INSTALL_WINDOWS_DEPENDENCIES.open('r', encoding='utf-8') as fh:
1112 commands.extend(l.rstrip() for l in fh)
1116 commands.extend(l.rstrip() for l in fh)
1113
1117
1118 # Schedule run of EC2Launch on next boot. This ensures that UserData
1119 # is executed.
1120 # We disable setComputerName because it forces a reboot.
1121 # We set an explicit admin password because this causes UserData to run
1122 # as Administrator instead of System.
1123 commands.extend(
1124 [
1125 r'''Set-Content -Path C:\ProgramData\Amazon\EC2-Windows\Launch\Config\LaunchConfig.json '''
1126 r'''-Value '{"setComputerName": false, "setWallpaper": true, "addDnsSuffixList": true, '''
1127 r'''"extendBootVolumeSize": true, "handleUserData": true, '''
1128 r'''"adminPasswordType": "Specify", "adminPassword": "%s"}' '''
1129 % c.automation.default_password(),
1130 r'C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 '
1131 r'–Schedule',
1132 ]
1133 )
1134
1114 # Disable Windows Defender when bootstrapping because it just slows
1135 # Disable Windows Defender when bootstrapping because it just slows
1115 # things down.
1136 # things down.
1116 commands.insert(0, 'Set-MpPreference -DisableRealtimeMonitoring $true')
1137 commands.insert(0, 'Set-MpPreference -DisableRealtimeMonitoring $true')
@@ -1135,7 +1156,9 b' def ensure_windows_dev_ami('
1135
1156
1136 print('no suitable Windows development image found; creating one...')
1157 print('no suitable Windows development image found; creating one...')
1137
1158
1138 with create_temp_windows_ec2_instances(c, config) as instances:
1159 with create_temp_windows_ec2_instances(
1160 c, config, bootstrap=True
1161 ) as instances:
1139 assert len(instances) == 1
1162 assert len(instances) == 1
1140 instance = instances[0]
1163 instance = instances[0]
1141
1164
General Comments 0
You need to be logged in to leave comments. Login now