11import re
22import time
33
4+ from retrying import retry
5+
46from cloudshell .cp .vcenter .commands .ip_result import IpResult , IpReason
57
68from cloudshell .cp .vcenter .common .vcenter .vm_location import VMLocation
@@ -19,7 +21,8 @@ def _do_not_run_on_static_vm(self, app_request_json):
1921 if app_request_json == '' or app_request_json is None :
2022 raise ValueError ('This command cannot be executed on a Static VM.' )
2123
22- def refresh_ip (self , si , logger , session , vcenter_data_model , vm_uuid , resource_name , cancellation_context ,app_request_json ):
24+ def refresh_ip (self , si , logger , session , vcenter_data_model , vm_uuid , resource_name , cancellation_context ,
25+ app_request_json ):
2326 """
2427 Refreshes IP address of virtual machine and updates Address property on the resource
2528
@@ -34,9 +37,10 @@ def refresh_ip(self, si, logger, session, vcenter_data_model, vm_uuid, resource_
3437 self ._do_not_run_on_static_vm (app_request_json = app_request_json )
3538
3639 default_network = VMLocation .combine (
37- [vcenter_data_model .default_datacenter , vcenter_data_model .holding_network ])
40+ [vcenter_data_model .default_datacenter , vcenter_data_model .holding_network ])
3841
39- resource = session .GetResourceDetails (resource_name )
42+ # TODO remove this call and use data from context
43+ resource = self ._get_resource_with_retry (session = session , resource_name = resource_name )
4044
4145 match_function = self .ip_manager .get_ip_match_function (self ._get_ip_refresh_ip_regex (resource ))
4246
@@ -51,15 +55,25 @@ def refresh_ip(self, si, logger, session, vcenter_data_model, vm_uuid, resource_
5155 .format (resource_name , timeout ))
5256
5357 if ip_res .reason == IpReason .Success :
54- session .UpdateResourceAddress (resource_name , ip_res .ip_address )
58+ self ._update_resource_address_with_retry (session = session ,
59+ resource_name = resource_name ,
60+ ip_address = ip_res .ip_address )
5561
5662 return ip_res .ip_address
5763
64+ @retry (stop_max_attempt_number = 5 , wait_fixed = 1000 )
65+ def _update_resource_address_with_retry (self , session , resource_name , ip_address ):
66+ session .UpdateResourceAddress (resource_name , ip_address )
67+
68+ @retry (stop_max_attempt_number = 5 , wait_fixed = 1000 )
69+ def _get_resource_with_retry (self , session , resource_name ):
70+ return session .GetResourceDetails (resource_name )
71+
5872 @staticmethod
5973 def _get_ip_refresh_timeout (resource ):
6074 timeout = RefreshIpCommand ._get_custom_param (
61- resource = resource ,
62- custom_param_name = 'refresh_ip_timeout' )
75+ resource = resource ,
76+ custom_param_name = 'refresh_ip_timeout' )
6377
6478 if not timeout :
6579 raise ValueError ('Refresh IP Timeout is not set' )
@@ -69,8 +83,8 @@ def _get_ip_refresh_timeout(resource):
6983 @staticmethod
7084 def _get_ip_refresh_ip_regex (resource ):
7185 return RefreshIpCommand ._get_custom_param (
72- resource = resource ,
73- custom_param_name = 'ip_regex' )
86+ resource = resource ,
87+ custom_param_name = 'ip_regex' )
7488
7589 @staticmethod
7690 def _get_custom_param (resource , custom_param_name ):
0 commit comments