|
5 | 5 |
|
6 | 6 | import logging
|
7 | 7 | import os
|
8 |
| -from typing import Any, Dict, List, Optional, Union, cast |
| 8 | +from typing import Any, Dict, List, Optional, Set, Union, cast |
9 | 9 | from uuid import UUID
|
10 | 10 |
|
11 | 11 | from azure.core.exceptions import (
|
@@ -151,50 +151,52 @@ def check_can_update(name: UUID) -> Any:
|
151 | 151 | return vmss
|
152 | 152 |
|
153 | 153 |
|
154 |
| -def reimage_vmss_nodes(name: UUID, vm_ids: List[UUID]) -> Optional[Error]: |
| 154 | +def reimage_vmss_nodes(name: UUID, vm_ids: Set[UUID]) -> Optional[Error]: |
155 | 155 | check_can_update(name)
|
156 | 156 |
|
157 | 157 | resource_group = get_base_resource_group()
|
158 | 158 | logging.info("reimaging scaleset VM - name: %s vm_ids:%s", name, vm_ids)
|
159 | 159 | compute_client = get_compute_client()
|
160 | 160 |
|
161 |
| - instance_ids = [] |
| 161 | + instance_ids = set() |
162 | 162 | machine_to_id = list_instance_ids(name)
|
163 | 163 | for vm_id in vm_ids:
|
164 | 164 | if vm_id in machine_to_id:
|
165 |
| - instance_ids.append(machine_to_id[vm_id]) |
| 165 | + instance_ids.add(machine_to_id[vm_id]) |
166 | 166 | else:
|
167 | 167 | logging.info("unable to find vm_id for %s:%s", name, vm_id)
|
168 | 168 |
|
169 | 169 | if instance_ids:
|
170 | 170 | compute_client.virtual_machine_scale_sets.begin_reimage_all(
|
171 | 171 | resource_group,
|
172 | 172 | str(name),
|
173 |
| - VirtualMachineScaleSetVMInstanceIDs(instance_ids=instance_ids), |
| 173 | + VirtualMachineScaleSetVMInstanceIDs(instance_ids=list(instance_ids)), |
174 | 174 | )
|
175 | 175 | return None
|
176 | 176 |
|
177 | 177 |
|
178 |
| -def delete_vmss_nodes(name: UUID, vm_ids: List[UUID]) -> Optional[Error]: |
| 178 | +def delete_vmss_nodes(name: UUID, vm_ids: Set[UUID]) -> Optional[Error]: |
179 | 179 | check_can_update(name)
|
180 | 180 |
|
181 | 181 | resource_group = get_base_resource_group()
|
182 | 182 | logging.info("deleting scaleset VM - name: %s vm_ids:%s", name, vm_ids)
|
183 | 183 | compute_client = get_compute_client()
|
184 | 184 |
|
185 |
| - instance_ids = [] |
| 185 | + instance_ids = set() |
186 | 186 | machine_to_id = list_instance_ids(name)
|
187 | 187 | for vm_id in vm_ids:
|
188 | 188 | if vm_id in machine_to_id:
|
189 |
| - instance_ids.append(machine_to_id[vm_id]) |
| 189 | + instance_ids.add(machine_to_id[vm_id]) |
190 | 190 | else:
|
191 | 191 | logging.info("unable to find vm_id for %s:%s", name, vm_id)
|
192 | 192 |
|
193 | 193 | if instance_ids:
|
194 | 194 | compute_client.virtual_machine_scale_sets.begin_delete_instances(
|
195 | 195 | resource_group,
|
196 | 196 | str(name),
|
197 |
| - VirtualMachineScaleSetVMInstanceRequiredIDs(instance_ids=instance_ids), |
| 197 | + VirtualMachineScaleSetVMInstanceRequiredIDs( |
| 198 | + instance_ids=list(instance_ids) |
| 199 | + ), |
198 | 200 | )
|
199 | 201 | return None
|
200 | 202 |
|
|
0 commit comments