Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_aksagentpool_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2022 xuzhang3 (@xuzhang3), Fred-sun (@Fred-sun)
4 #
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8 __metaclass__ = type
9
10
11 DOCUMENTATION = '''
12 ---
13 module: azure_rm_aksagentpool_info
14 version_added: '1.14.0'
15 short_description: Show the details for a node pool in the managed Kubernetes cluster
16 description:
17 - Get the details for a node pool in the managed Kubernetes cluster.
18
19 options:
20 resource_group:
21 description:
22 - The name of the resource group.
23 type: str
24 required: True
25 cluster_name:
26 description:
27 - The cluster name.
28 type: str
29 required: True
30 name:
31 description:
32 - The node pool name.
33 type: str
34
35 extends_documentation_fragment:
36 - azure.azcollection.azure
37
38 author:
39 - xuzhang3 (@xuzhang3)
40 - Fred Sun (@Fred-sun)
41 '''
42
43 EXAMPLES = '''
44 - name: Get node agent pool by cluster name
45 azure_rm_aksagentpool_info:
46 resource_group: myRG
47 cluster_name: testcluster
48
49 - name: Get node agent pool by name
50 azure_rm_aksagentpool_info:
51 resource_group: myRG
52 cluster_name: testcluster
53 name: default
54 '''
55
56 RETURN = '''
57 aks_agent_pools:
58 description:
59 - Details for a node pool in the managed Kubernetes cluster.
60 returned: always
61 type: complex
62 contains:
63 id:
64 description:
65 - Resource ID.
66 type: str
67 returned: always
68 sample: "/subscriptions/xxx-xxxf/resourcegroups/myRG/providers/Microsoft.ContainerService/managedClusters/cluster/agentPools/default"
69 resource_group:
70 description:
71 - Resource group name.
72 type: str
73 returned: always
74 sample: myRG
75 name:
76 description:
77 - Resource name.
78 type: str
79 returned: always
80 sample: default
81 cluster_name:
82 description:
83 - The cluster name.
84 type: str
85 returned: always
86 sample: testcluster
87 availability_zones:
88 description:
89 - Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType.
90 type: list
91 returned: always
92 sample: [1, 2]
93 count:
94 description:
95 - Number of agents (VMs) to host docker containers.
96 type: int
97 returned: always
98 sample: 2
99 enable_auto_scaling:
100 description:
101 - Whether to enable auto-scaler.
102 type: bool
103 returned: always
104 sample: null
105 enable_node_public_ip:
106 description:
107 - Enable public IP for nodes.
108 type: bool
109 returned: always
110 sample: True
111 max_count:
112 description:
113 - Maximum number of nodes for auto-scaling.
114 type: int
115 returned: always
116 sample: 10
117 min_count:
118 description:
119 - Minimum number of nodes for auto-scaling.
120 type: int
121 returned: always
122 sample: 1
123 max_pods:
124 description:
125 - Maximum number of pods that can run on a node.
126 type: int
127 returned: always
128 sample: 42
129 mode:
130 description:
131 - AgentPoolMode represents mode of an agent pool.
132 type: str
133 returned: always
134 sample: System
135 node_image_version:
136 description:
137 - Version of node image.
138 type: str
139 returned: always
140 sample: AKSUbuntu-1804gen2containerd-2022.08.23
141 node_labels:
142 description:
143 - Agent pool node labels to be persisted across all nodes in agent pool.
144 type: list
145 returned: always
146 sample: ["release":"stable"]
147 node_taints:
148 description:
149 - Taints added to new nodes during node pool create and scale.
150 type: list
151 returned: always
152 sample: ["CriticalAddonsOnly=false:NoSchedule"]
153 orchestrator_version:
154 description:
155 - Version of orchestrator specified when creating the managed cluster.
156 type: str
157 returned: always
158 sample: 1.22.11
159 os_disk_size_gb:
160 description:
161 - OS Disk Size in GB to be used to specify the disk size for every machine in this master agent pool.
162 type: int
163 returned: always
164 sample: 128
165 os_type:
166 description:
167 - OsType to be used to specify os type.
168 type: str
169 returned: always
170 sample: Linux
171 os_sku:
172 description:
173 - OS SKU to be used to specify os type.
174 type: str
175 returned: always
176 sample: Windows2022
177 provisioning_state:
178 description:
179 - The current deployment or provisioning state, which only appears in the response.
180 type: str
181 returned: always
182 sample: Succeeded
183 scale_set_eviction_policy:
184 description:
185 - ScaleSetEvictionPolicy to be used to specify eviction policy for Spot virtual machine scale set.
186 type: str
187 returned: always
188 sample: null
189 scale_set_priority:
190 description:
191 - caleSetPriority to be used to specify virtual machine scale set priority.
192 type: str
193 returned: always
194 sample: null
195 spot_max_price:
196 description:
197 - SpotMaxPrice to be used to specify the maximum price you are willing to pay in US Dollars.
198 type: float
199 returned: always
200 sample: null
201 security_profile:
202 description:
203 - The security settings of an agent pool.
204 type: complex
205 contains:
206 enable_secure_boot:
207 description:
208 - The secure boot is diabled or enabled.
209 type: bool
210 returned: always
211 sample: true
212 enable_vtpm:
213 description:
214 - The vTPM is diabled or enabled.
215 type: bool
216 returned: always
217 sample: true
218 type:
219 description:
220 - Resource Type.
221 type: str
222 returned: always
223 sample: Microsoft.ContainerService/managedClusters/agentPools
224 type_properties_type:
225 description:
226 - AgentPoolType represents types of an agent pool.
227 type: str
228 returned: always
229 sample: VirtualMachineScaleSets
230 upgrade_settings:
231 description:
232 - Settings for upgrading the agentpool.
233 type: str
234 returned: always
235 sample: null
236 vm_size:
237 description:
238 - Size of agent VMs.
239 type: str
240 returned: always
241 sample: Standard_B2s
242 vnet_subnet_id:
243 description:
244 - VNet SubnetID specifies the VNet's subnet identifier.
245 type: str
246 returned: always
247 sample: null
248 kubelet_config:
249 description:
250 - The Kubelet configuration on the agent pool nodes.
251 type: dict
252 returned: always
253 sample: {
254 cpu_cfs_quota: true,
255 cpu_cfs_quota_period: 100ms,
256 cpu_manager_policy: static,
257 fail_swap_on: false,
258 image_gc_high_threshold: 85,
259 image_gc_low_threshold: 80,
260 topology_manager_policy: none
261 }
262 linux_os_config:
263 description:
264 - The OS configuration of Linux agent nodes.
265 type: dict
266 returned: always
267 sample: {
268 swap_file_size_mb: 1500,
269 sysctls: {},
270 transparent_huge_page_defrag: defer+madvise,
271 transparent_huge_page_enabled: madvise
272 }
273 power_state:
274 description:
275 - The agent pool's power state.
276 type: dict
277 returned: always
278 sample: {code: Running}
279 tags:
280 description:
281 - The tags of the node agent pool.
282 type: dict
283 returned: always
284 sample: {key1: value1, key2: value2}
285 kubelet_disk_type:
286 description:
287 - Determines the placement of emptyDir volumes, container runtime data root, and Kubelet ephemeral storage.
288 type: str
289 returned: always
290 sample: OS
291 workload_runtime:
292 description:
293 - Determines the type of workload a node can run.
294 type: str
295 returned: always
296 sample: OCIContainer
297 scale_down_mode:
298 description:
299 - This also effects the cluster autoscaler behavior.
300 type: str
301 returned: always
302 sample: Delete
303 node_public_ip_prefix_id:
304 description:
305 - The Azure Public IP prefix's ID.
306 type: str
307 returned: always
308 sample: null
309 proximity_placement_group_id:
310 description:
311 - The ID for Proximity Placement Group.
312 type: str
313 returned: always
314 sample: /subscriptions/xxx-xxx/resourceGroups/myRG/providers/Microsoft.Compute/proximityPlacementGroups/proxi01
315 enable_encryption_at_host:
316 description:
317 - This is only supported on certain VM sizes and in certain Azure regions.
318 type: bool
319 returned: always
320 sample: false
321 enable_ultra_ssd:
322 description:
323 - Whether enable FIPS node pool.
324 type: bool
325 returned: always
326 sample: false
327 gpu_instance_profile:
328 description:
329 - GPUInstanceProfile to be used to specify GPU MIG instance profile for supported GPU VM SKU.
330 type: str
331 returned: always
332 sample: MIG1g
333 windows_profile:
334 description:
335 - The Windows agent pool's specific profile.
336 type: dict
337 returned: when-used
338 sample: {"disable_outbound_nat": false}
339 network_profile:
340 description:
341 - Network-related settings of an agent pool.
342 type: complex
343 returned: when-used
344 contains:
345 allowed_host_ports:
346 description:
347 - The port ranges that are allowed to access.
348 type: list
349 returned: always
350 sample: [{"port_end": 200, "port_start": 10, "protocol": "TCP"}]
351 application_security_groups:
352 description:
353 - The IDs of the application security groups which agent pool will associate when created.
354 type: list
355 returned: always
356 sample: ["/subscriptions/xxxxxx/resourceGroups/testRG/providers/Microsoft.Network/applicationSecurityGroups/appnsg"]
357 pod_subnet_id:
358 description:
359 - The subnet ID.
360 type: str
361 returned: always
362 sample: "/subscriptions/xxxx/resourceGroups/testRG/providers/Microsoft.Network/virtualNetworks/My_Virtual_Network/subnets/foobar"
363 host_group_id:
364 description:
365 - The host group ID.
366 type: str
367 returned: always
368 sample: "/subscriptions/xxxxx/resourceGroups/testRG/providers/Microsoft.Compute/hostGroups/hostgroup"
369 capacity_reservation_group_id:
370 description:
371 - The ID of Capacity Reservation Group.
372 returned: always
373 type: str
374 sample: "/subscriptions/xxxxx/resourceGroups/testRG/providers/Microsoft.Compute/capacityReservationGroups/crgid"
375 os_disk_type:
376 description:
377 - The type of the OS disk.
378 returned: always
379 sample: Managed
380 type: str
381 '''
382
383 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
384
385 try:
386 from azure.core.exceptions import ResourceNotFoundError
387 except ImportError:
388 pass
389
390
391 class AzureRMAgentPoolInfo(AzureRMModuleBase):
392 def __init__(self):
393 # define user inputs into argument
394 self.module_arg_spec = dict(
395 resource_group=dict(
396 type='str',
397 required=True
398 ),
399 name=dict(
400 type='str'
401 ),
402 cluster_name=dict(
403 type='str',
404 required=True
405 )
406 )
407 # store the results of the module operation
408 self.results = dict()
409 self.resource_group = None
410 self.name = None
411 self.cluster_name = None
412
413 super(AzureRMAgentPoolInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False, facts_module=True)
414
415 def exec_module(self, **kwargs):
416
417 for key in list(self.module_arg_spec):
418 setattr(self, key, kwargs[key])
419
420 if self.name:
421 aks_agent_pools = [self.get_agentpool()]
422 else:
423 aks_agent_pools = self.list_agentpool()
424 self.results['aks_agent_pools'] = [self.to_dict(x) for x in aks_agent_pools]
425 return self.results
426
427 def get_agentpool(self):
428 try:
429 return self.managedcluster_client.agent_pools.get(self.resource_group, self.cluster_name, self.name)
430 except ResourceNotFoundError:
431 pass
432
433 def list_agentpool(self):
434 result = []
435 try:
436 resp = self.managedcluster_client.agent_pools.list(self.resource_group, self.cluster_name)
437 while True:
438 result.append(resp.next())
439 except StopIteration:
440 pass
441 except Exception:
442 pass
443 return result
444
445 def to_dict(self, agent_pool):
446 if not agent_pool:
447 return None
448 agent_pool_dict = dict(
449 resource_group=self.resource_group,
450 cluster_name=self.cluster_name,
451 id=agent_pool.id,
452 type=agent_pool.type,
453 name=agent_pool.name,
454 count=agent_pool.count,
455 vm_size=agent_pool.vm_size,
456 os_disk_size_gb=agent_pool.os_disk_size_gb,
457 vnet_subnet_id=agent_pool.vnet_subnet_id,
458 max_pods=agent_pool.max_pods,
459 os_type=agent_pool.os_type,
460 os_sku=agent_pool.os_sku,
461 max_count=agent_pool.max_count,
462 min_count=agent_pool.min_count,
463 enable_auto_scaling=agent_pool.enable_auto_scaling,
464 type_properties_type=agent_pool.type_properties_type,
465 mode=agent_pool.mode,
466 availability_zones=[],
467 orchestrator_version=agent_pool.orchestrator_version,
468 node_image_version=agent_pool.node_image_version,
469 upgrade_settings=dict(),
470 provisioning_state=agent_pool.provisioning_state,
471 enable_node_public_ip=agent_pool.enable_node_public_ip,
472 scale_set_priority=agent_pool.scale_set_priority,
473 scale_set_eviction_policy=agent_pool.scale_set_eviction_policy,
474 spot_max_price=agent_pool.spot_max_price,
475 node_labels=agent_pool.node_labels,
476 node_taints=agent_pool.node_taints,
477 tags=agent_pool.tags,
478 kubelet_disk_type=agent_pool.kubelet_disk_type,
479 workload_runtime=agent_pool.workload_runtime,
480 scale_down_mode=agent_pool.scale_down_mode,
481 power_state=dict(),
482 node_public_ip_prefix_id=agent_pool.node_public_ip_prefix_id,
483 proximity_placement_group_id=agent_pool.proximity_placement_group_id,
484 kubelet_config=dict(),
485 linux_os_config=dict(),
486 security_profile=dict(),
487 enable_encryption_at_host=agent_pool.enable_encryption_at_host,
488 enable_ultra_ssd=agent_pool.enable_ultra_ssd,
489 enable_fips=agent_pool.enable_fips,
490 gpu_instance_profile=agent_pool.gpu_instance_profile,
491 os_disk_type=agent_pool.os_disk_type,
492 capacity_reservation_group_id=agent_pool.capacity_reservation_group_id,
493 host_group_id=agent_pool.host_group_id,
494 pod_subnet_id=agent_pool.pod_subnet_id,
495 network_profile=dict(),
496 windows_profile=dict(),
497 )
498
499 if agent_pool.upgrade_settings is not None:
500 agent_pool_dict['upgrade_settings']['max_surge'] = agent_pool.upgrade_settings.max_surge
501 else:
502 agent_pool_dict['upgrade_settings'] = None
503
504 if agent_pool.availability_zones is not None:
505 for key in agent_pool.availability_zones:
506 agent_pool_dict['availability_zones'].append(int(key))
507 else:
508 agent_pool_dict['availability_zones'] = None
509
510 if agent_pool.kubelet_config is not None:
511 agent_pool_dict['kubelet_config'] = agent_pool.kubelet_config.as_dict()
512 else:
513 agent_pool_dict['kubelet_config'] = None
514
515 if agent_pool.linux_os_config is not None:
516 agent_pool_dict['linux_os_config']['transparent_huge_page_enabled'] = agent_pool.linux_os_config.transparent_huge_page_enabled
517 agent_pool_dict['linux_os_config']['transparent_huge_page_defrag'] = agent_pool.linux_os_config.transparent_huge_page_defrag
518 agent_pool_dict['linux_os_config']['swap_file_size_mb'] = agent_pool.linux_os_config.swap_file_size_mb
519 agent_pool_dict['linux_os_config']['sysctls'] = dict()
520 if agent_pool.linux_os_config.sysctls is not None:
521 agent_pool_dict['linux_os_config']['sysctls'] = agent_pool.linux_os_config.sysctls.as_dict()
522 else:
523 agent_pool_dict['linux_os_config']['sysctls'] = None
524 else:
525 agent_pool_dict['linux_os_config'] = None
526
527 if agent_pool.power_state is not None:
528 agent_pool_dict['power_state']['code'] = agent_pool.power_state.code
529 else:
530 agent_pool_dict['power_state'] = None
531
532 if agent_pool.security_profile is not None:
533 agent_pool_dict['security_profile']['enable_vtpm'] = agent_pool.security_profile.enable_vtpm
534 agent_pool_dict['security_profile']['enable_secure_boot'] = agent_pool.security_profile.enable_secure_boot
535 else:
536 agent_pool_dict['security_profile'] = None
537
538 if agent_pool.network_profile is not None:
539 agent_pool_dict['network_profile'] = agent_pool.network_profile.as_dict()
540 else:
541 agent_pool_dict['network_profile'] = None
542
543 if agent_pool.windows_profile is not None:
544 agent_pool_dict['windows_profile']['disable_outbound_nat'] = agent_pool.windows_profile.disable_outbound_nat
545 else:
546 agent_pool_dict['windows_profile'] = None
547
548 return agent_pool_dict
549
550
551 def main():
552 AzureRMAgentPoolInfo()
553
554
555 if __name__ == '__main__':
556 main()