|
33 | 33 | CuckooMachineError,
|
34 | 34 | CuckooOperationalError,
|
35 | 35 | )
|
36 |
| -from lib.cuckoo.core.database import TASK_PENDING |
| 36 | +from lib.cuckoo.core.database import TASK_PENDING, Machine |
37 | 37 |
|
38 | 38 | # Only log INFO or higher from imported python packages
|
39 | 39 | logging.getLogger("adal-python").setLevel(logging.INFO)
|
@@ -104,16 +104,23 @@ class Azure(Machinery):
|
104 | 104 | WINDOWS_PLATFORM = "windows"
|
105 | 105 | LINUX_PLATFORM = "linux"
|
106 | 106 |
|
| 107 | + def set_options(self, options: dict) -> None: |
| 108 | + """Set machine manager options. |
| 109 | + @param options: machine manager options dict. |
| 110 | + """ |
| 111 | + self.options = options |
| 112 | + |
107 | 113 | def _initialize(self):
|
108 | 114 | """
|
109 | 115 | Overloading abstracts.py:_initialize()
|
110 | 116 | Read configuration.
|
111 | 117 | @param module_name: module name
|
112 | 118 | @raise CuckooDependencyError: if there is a problem with the dependencies call
|
113 | 119 | """
|
| 120 | + # Using "scale_sets" here instead of "machines" to avoid KeyError |
114 | 121 | mmanager_opts = self.options.get(self.module_name)
|
115 | 122 | if not isinstance(mmanager_opts["scale_sets"], list):
|
116 |
| - mmanager_opts["scale_sets"] = mmanager_opts["scale_sets"].strip().split(",") |
| 123 | + mmanager_opts["scale_sets"] = str(mmanager_opts["scale_sets"]).strip().split(",") |
117 | 124 |
|
118 | 125 | # Replace a list of IDs with dictionary representations
|
119 | 126 | scale_sets = mmanager_opts.pop("scale_sets")
|
@@ -238,7 +245,7 @@ def _thr_machine_pool_monitor(self):
|
238 | 245 | threading.Thread(target=self._thr_scale_machine_pool, args=(vals["tag"],)).start()
|
239 | 246 |
|
240 | 247 | # Check the machine pools every 5 minutes
|
241 |
| - threading.Timer(300, self._thr_machine_pool_monitor).start() |
| 248 | + threading.Timer(self.options.az.monitor_rate, self._thr_machine_pool_monitor).start() |
242 | 249 |
|
243 | 250 | def _set_vmss_stage(self):
|
244 | 251 | """
|
@@ -461,8 +468,13 @@ def stop(self, label):
|
461 | 468 | time.sleep(5)
|
462 | 469 | with reimage_lock:
|
463 | 470 | label_in_reimage_vm_list = label in [f"{vm['vmss']}_{vm['id']}" for vm in reimage_vm_list]
|
| 471 | + |
| 472 | + def release(self, machine: Machine): |
| 473 | + vmss_name = machine.label.split("_")[0] |
| 474 | + if machine_pools[vmss_name]["is_scaling_down"]: |
| 475 | + self.delete_machine(machine.label) |
464 | 476 | else:
|
465 |
| - self.delete_machine(label) |
| 477 | + _ = super(Azure, self).release(machine) |
466 | 478 |
|
467 | 479 | def availables(self, label=None, platform=None, tags=None, arch=None, include_reserved=False, os_version=[]):
|
468 | 480 | """
|
@@ -619,7 +631,7 @@ def delete_machine(self, label, delete_from_vmss=True):
|
619 | 631 | """
|
620 | 632 | global vms_currently_being_deleted
|
621 | 633 |
|
622 |
| - _ = super(Azure, self).delete_machine(label) |
| 634 | + super(Azure, self).delete_machine(label) |
623 | 635 |
|
624 | 636 | if delete_from_vmss:
|
625 | 637 | vmss_name, instance_id = label.split("_")
|
@@ -716,7 +728,10 @@ def _thr_create_vmss(self, vmss_name, vmss_image_ref, vmss_image_os):
|
716 | 728 | managed_disk=vmss_managed_disk,
|
717 | 729 | # Ephemeral disk time
|
718 | 730 | caching="ReadOnly",
|
719 |
| - diff_disk_settings=models.DiffDiskSettings(option="Local"), |
| 731 | + diff_disk_settings=models.DiffDiskSettings( |
| 732 | + option="Local", |
| 733 | + placement=self.options.az.ephemeral_os_disk_placement |
| 734 | + ), |
720 | 735 | )
|
721 | 736 | vmss_storage_profile = models.VirtualMachineScaleSetStorageProfile(
|
722 | 737 | image_reference=vmss_image_ref,
|
@@ -1110,7 +1125,7 @@ def _get_relevant_machines(self, tag):
|
1110 | 1125 | """
|
1111 | 1126 | # The number of relevant machines are those from the list of locked and unlocked machines
|
1112 | 1127 | # that have the correct tag in their name
|
1113 |
| - return [machine for machine in self.db.list_machines() if tag in machine.label] |
| 1128 | + return [machine for machine in self.db.list_machines([tag])] |
1114 | 1129 |
|
1115 | 1130 | @staticmethod
|
1116 | 1131 | def _wait_for_concurrent_operations_to_complete():
|
|
0 commit comments