|
124 | 124 | fetch_compute_hosts: |
125 | 125 | description: When set, the compute nodes are fetched. Default value set to True. |
126 | 126 | type: bool |
| 127 | + fetch_only_running_hosts: |
| 128 | + description: When set along with fetch_compute_hosts, only compute nodes in a RUNNING lifecycle state are fetched. Default value set to True. |
| 129 | + type: bool |
127 | 130 | primary_vnic_only: |
128 | 131 | description: The default behavior of the plugin is to process all VNIC's attached to a compute instance. |
129 | 132 | This might result in instance having multiple entries. When this parameter is set to True, |
|
354 | 357 |
|
355 | 358 | # Compute Hosts (bool type) |
356 | 359 | fetch_compute_hosts: True |
| 360 | +fetch_only_running_hosts: True |
357 | 361 |
|
358 | 362 | # Process only the primary vnic of a compute instance |
359 | 363 | primary_vnic_only: True |
@@ -736,6 +740,12 @@ def _fetch_compute_hosts(self): |
736 | 740 | return True |
737 | 741 | return self.get_option("fetch_compute_hosts") |
738 | 742 |
|
| 743 | + def _fetch_only_running_hosts(self): |
| 744 | + # check if we should fetch only running hosts |
| 745 | + if self.get_option("fetch_only_running_hosts") is None: |
| 746 | + return True |
| 747 | + return self.get_option("fetch_only_running_hosts") |
| 748 | + |
739 | 749 | @staticmethod |
740 | 750 | def create_instance_principal_signer(delegation_token_location=None): |
741 | 751 | """ |
@@ -1845,16 +1855,20 @@ def get_filtered_instances(self, compartment_ocid, region): |
1845 | 1855 | ) |
1846 | 1856 | try: |
1847 | 1857 | compute_client = self.get_compute_client_for_region(region) |
| 1858 | + list_all_resources_args = { |
| 1859 | + "target_fn": compute_client.list_instances, |
| 1860 | + "compartment_id": compartment_ocid, |
| 1861 | + "limit": 2000, |
| 1862 | + } |
| 1863 | + |
| 1864 | + if self._fetch_only_running_hosts(): |
| 1865 | + list_all_resources_args["lifecycle_state"] = "RUNNING" |
1848 | 1866 |
|
1849 | 1867 | instances = self.get_filtered_resources( |
1850 | | - oci_common_utils.list_all_resources( |
1851 | | - target_fn=compute_client.list_instances, |
1852 | | - compartment_id=compartment_ocid, |
1853 | | - lifecycle_state="RUNNING", |
1854 | | - limit=2000, |
1855 | | - ), |
| 1868 | + oci_common_utils.list_all_resources(**list_all_resources_args), |
1856 | 1869 | compartment_ocid, |
1857 | 1870 | ) |
| 1871 | + |
1858 | 1872 | return instances |
1859 | 1873 | except ServiceError as ex: |
1860 | 1874 | self.debug( |
|
0 commit comments