@@ -2293,7 +2293,7 @@ def get_all_uuids(self):
2293
2293
logger .info ('found cluster uuids: {0}' .format (self .clusters ))
2294
2294
return self .clusters
2295
2295
2296
- def get (self , clusteruuid = None ):
2296
+ def get (self , clusteruuid = None , refresh = False ):
2297
2297
"""Retrieve data for a specific cluster
2298
2298
2299
2299
:param clusteruuid: A cluster UUID to define the specific cluster to query. Only required to be used when the :class:`ntnx.client.ApiClient`
@@ -2307,6 +2307,11 @@ def get(self, clusteruuid=None):
2307
2307
payload = None
2308
2308
uri = '/cluster'
2309
2309
2310
+ # Remove existing data for this cluster if it exists
2311
+ if self .cluster .get (clusteruuid ):
2312
+ self .cluster .pop (clusteruuid )
2313
+ logger .info ('removing existing data from class dict cluster for cluster {0}' .format (clusteruuid ))
2314
+
2310
2315
if clusteruuid :
2311
2316
params ['proxyClusterUuid' ] = clusteruuid
2312
2317
@@ -2429,7 +2434,7 @@ def get(self, clusteruuid=None):
2429
2434
'entities' )
2430
2435
return self .hosts [clusteruuid ]
2431
2436
2432
- def search_uuid (self , uuid , clusteruuid = None ):
2437
+ def search_uuid (self , uuid , clusteruuid = None , refresh = False ):
2433
2438
"""Retrieve data for a specific host, in a specific cluster by host uuid
2434
2439
2435
2440
:param clusteruuid: A cluster UUID to define the specific cluster to query. Only required to be used when the :class:`ntnx.client.ApiClient`
@@ -2443,7 +2448,7 @@ def search_uuid(self, uuid, clusteruuid=None):
2443
2448
"""
2444
2449
logger = logging .getLogger ('ntnx_api.prism.Hosts.search_uuid' )
2445
2450
found = {}
2446
- if not self .hosts .get (clusteruuid ):
2451
+ if not self .hosts .get (clusteruuid ) or refresh :
2447
2452
self .get (clusteruuid )
2448
2453
2449
2454
for entity in self .hosts .get (clusteruuid ):
@@ -2453,21 +2458,23 @@ def search_uuid(self, uuid, clusteruuid=None):
2453
2458
2454
2459
return found
2455
2460
2456
- def search_name (self , name , clusteruuid = None ):
2461
+ def search_name (self , name , clusteruuid = None , refresh = False ):
2457
2462
"""Retrieve data for a specific host, in a specific cluster by host name
2458
2463
2459
2464
:param clusteruuid: A cluster UUID to define the specific cluster to query. Only required to be used when the :class:`ntnx.client.ApiClient`
2460
2465
`connection_type` is set to `pc`.
2461
2466
:type clusteruuid: str, optional
2462
2467
:param name: A host name to search for.
2463
2468
:type name: str, optional
2469
+ :param refresh: Whether to refresh the class dataset (default=False).
2470
+ :type refresh: bool, optional
2464
2471
2465
2472
:returns: A dictionary describing the found host.
2466
2473
:rtype: ResponseDict
2467
2474
"""
2468
2475
logger = logging .getLogger ('ntnx_api.prism.Hosts.search_name' )
2469
2476
found = {}
2470
- if not self .hosts .get (clusteruuid ):
2477
+ if not self .hosts .get (clusteruuid ) or refresh :
2471
2478
self .get (clusteruuid )
2472
2479
2473
2480
for entity in self .hosts .get (clusteruuid ):
@@ -2477,21 +2484,23 @@ def search_name(self, name, clusteruuid=None):
2477
2484
2478
2485
return found
2479
2486
2480
- def search_ip (self , ip_address , clusteruuid = None ):
2487
+ def search_ip (self , ip_address , clusteruuid = None , refresh = False ):
2481
2488
"""Retrieve data for a specific host, in a specific cluster by ip_address. The CVM, Hypervisor and IPMI IP addresses will be tested
2482
2489
2483
2490
:param clusteruuid: A cluster UUID to define the specific cluster to query. Only required to be used when the :class:`ntnx.client.ApiClient`
2484
2491
`connection_type` is set to `pc`.
2485
2492
:type clusteruuid: str, optional
2486
2493
:param ip_address: A host name to search for.
2487
2494
:type ip_address: str, optional
2495
+ :param refresh: Whether to refresh the class dataset (default=False).
2496
+ :type refresh: bool, optional
2488
2497
2489
2498
:returns: A dictionary describing the found host.
2490
2499
:rtype: ResponseDict
2491
2500
"""
2492
2501
logger = logging .getLogger ('ntnx_api.prism.Hosts.search_ip' )
2493
2502
found = {}
2494
- if not self .hosts .get (clusteruuid ):
2503
+ if not self .hosts .get (clusteruuid ) or refresh :
2495
2504
self .get (clusteruuid )
2496
2505
2497
2506
for entity in self .hosts .get (clusteruuid ):
@@ -2501,6 +2510,51 @@ def search_ip(self, ip_address, clusteruuid=None):
2501
2510
2502
2511
return found
2503
2512
2513
+ def get_project (self , uuid , clusteruuid = None , refresh = False ):
2514
+ """Retrieve the project assigned to the specified host if connected to a prism central
2515
+
2516
+ :param clusteruuid: A cluster UUID to define the specific cluster to query. Only required to be used when the :class:`ntnx.client.ApiClient`
2517
+ `connection_type` is set to `pc`.
2518
+ :type clusteruuid: str, optional
2519
+ :param uuid: The UUID of a host.
2520
+ :type uuid: str
2521
+ :param refresh: Whether to refresh the class dataset (default=False).
2522
+ :type refresh: bool, optional
2523
+
2524
+ :returns: A string containing the project name.
2525
+ :rtype: str
2526
+ """
2527
+ logger = logging .getLogger ('ntnx_api.prism.Hosts.get_project' )
2528
+ project = ''
2529
+ if self .api_client .connection_type == 'pc' :
2530
+ metadata = self .search_uuid (uuid = uuid , clusteruuid = clusteruuid , refresh = refresh ).get ('vm_metadata' )
2531
+ if metadata .get ('project_reference' ).get ('kind' ) == 'project' :
2532
+ project = metadata .get ('project_reference' ).get ('name' )
2533
+ return project
2534
+
2535
+ def get_categories (self , uuid , clusteruuid = None , refresh = False ):
2536
+ """Retrieve the categories assigned to the specified host if connected to a prism central
2537
+
2538
+ :param clusteruuid: A cluster UUID to define the specific cluster to query. Only required to be used when the :class:`ntnx.client.ApiClient`
2539
+ `connection_type` is set to `pc`.
2540
+ :type clusteruuid: str, optional
2541
+ :param uuid: The UUID of a host.
2542
+ :type uuid: str
2543
+ :param refresh: Whether to refresh the class dataset (default=False).
2544
+ :type refresh: bool, optional
2545
+
2546
+ :returns: A dictionary with all .
2547
+ :rtype: ResponseDict
2548
+ """
2549
+ logger = logging .getLogger ('ntnx_api.prism.Hosts.get_categories' )
2550
+ categories = []
2551
+ if self .api_client .connection_type == 'pc' :
2552
+ metadata = self .search_uuid (uuid = uuid , clusteruuid = clusteruuid , refresh = refresh ).get ('categories' )
2553
+ if metadata .get ('project_reference' ).get ('kind' ) == 'project' :
2554
+ for key , value in metadata .get ('categories' ).items ():
2555
+ categories [key ] = value
2556
+ return categories
2557
+
2504
2558
2505
2559
class Vms (object ):
2506
2560
"""A class to represent a Nutanix Clusters Virtual Machines
@@ -2548,6 +2602,8 @@ def search_uuid(self, uuid, clusteruuid=None, refresh=False):
2548
2602
:type clusteruuid: str, optional
2549
2603
:param uuid: A vm uuid to search for.
2550
2604
:type uuid: str, optional
2605
+ :param refresh: Whether to refresh the class VM dataset (default=False).
2606
+ :type refresh: bool, optional
2551
2607
2552
2608
:returns: A dictionary describing the found vm.
2553
2609
:rtype: ResponseDict
@@ -2572,6 +2628,8 @@ def search_name(self, name, clusteruuid=None, refresh=False):
2572
2628
:type clusteruuid: str, optional
2573
2629
:param name: A vm name to search for.
2574
2630
:type name: str, optional
2631
+ :param refresh: Whether to refresh the class VM dataset (default=False).
2632
+ :type refresh: bool, optional
2575
2633
2576
2634
:returns: A dictionary describing the found vm.
2577
2635
:rtype: ResponseDict
@@ -2588,6 +2646,51 @@ def search_name(self, name, clusteruuid=None, refresh=False):
2588
2646
2589
2647
return found
2590
2648
2649
+ def get_project (self , uuid , clusteruuid = None , refresh = False ):
2650
+ """Retrieve the project assigned to the specified VM if connected to a prism central
2651
+
2652
+ :param clusteruuid: A cluster UUID to define the specific cluster to query. Only required to be used when the :class:`ntnx.client.ApiClient`
2653
+ `connection_type` is set to `pc`.
2654
+ :type clusteruuid: str, optional
2655
+ :param uuid: The UUID of a VM.
2656
+ :type uuid: str
2657
+ :param refresh: Whether to refresh the class VM dataset (default=False).
2658
+ :type refresh: bool, optional
2659
+
2660
+ :returns: A string containing the project name.
2661
+ :rtype: str
2662
+ """
2663
+ logger = logging .getLogger ('ntnx_api.prism.Vms.get_project' )
2664
+ project = ''
2665
+ if self .api_client .connection_type == 'pc' :
2666
+ metadata = self .search_uuid (uuid = uuid , clusteruuid = clusteruuid , refresh = refresh ).get ('vm_metadata' )
2667
+ if metadata .get ('project_reference' ).get ('kind' ) == 'project' :
2668
+ project = metadata .get ('project_reference' ).get ('name' )
2669
+ return project
2670
+
2671
+ def get_categories (self , uuid , clusteruuid = None , refresh = False ):
2672
+ """Retrieve the categories assigned to the specified VM if connected to a prism central
2673
+
2674
+ :param clusteruuid: A cluster UUID to define the specific cluster to query. Only required to be used when the :class:`ntnx.client.ApiClient`
2675
+ `connection_type` is set to `pc`.
2676
+ :type clusteruuid: str, optional
2677
+ :param uuid: The UUID of a VM.
2678
+ :type uuid: str
2679
+ :param refresh: Whether to refresh the class VM dataset (default=False).
2680
+ :type refresh: bool, optional
2681
+
2682
+ :returns: A dictionary with all .
2683
+ :rtype: ResponseDict
2684
+ """
2685
+ logger = logging .getLogger ('ntnx_api.prism.Vms.get_categories' )
2686
+ categories = []
2687
+ if self .api_client .connection_type == 'pc' :
2688
+ metadata = self .search_uuid (uuid = uuid , clusteruuid = clusteruuid , refresh = refresh ).get ('categories' )
2689
+ if metadata .get ('project_reference' ).get ('kind' ) == 'project' :
2690
+ for key , value in metadata .get ('categories' ).items ():
2691
+ categories [key ] = value
2692
+ return categories
2693
+
2591
2694
2592
2695
class Images (object ):
2593
2696
"""A class to represent a Nutanix Clusters Images
0 commit comments