Skip to content

Commit

Permalink
Merge pull request #91 from vmware-samples/development
Browse files Browse the repository at this point in the history
v. 1.9.3 Update
  • Loading branch information
Chris White authored Jan 31, 2024
2 parents 1c09ee2 + a053428 commit b61bd19
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
38 changes: 19 additions & 19 deletions VMCImportExport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2215,7 +2215,7 @@ def invokeCSPGET(self,url: str) -> requests.Response:
try:
response = requests.get(url,headers= {"Authorization":"Bearer " + self.vmc_auth.access_token})
if response.status_code != 200:
self.lastJSONResponse = f'API Call Status {response.status_code}, text:{response.text}'
self.error_handling(response)
return response
except Exception as e:
self.lastJSONResponse = e
Expand All @@ -2225,25 +2225,13 @@ def invokeVMCGET(self,url: str) -> requests.Response:
"""Invokes a VMC On AWS GET request"""
self.vmc_auth.check_access_token_expiration()
myHeader = {'csp-auth-token': self.vmc_auth.access_token}
attempts = 1
status_code = 0
try:
while attempts <=3 and status_code != 200:
if attempts > 1:
print('Retrying...')
response = requests.get(url,headers=myHeader)
status_code = response.status_code
if status_code == 200:
break
self.lastJSONResponse = f'API Call Status {response.status_code}, text:{response.text}'
if status_code == 504:
attempts +=1
print('Received gateway time out error 504, pausing...')
time.sleep(5)
response = requests.get(url, headers=myHeader)
if response.status_code == requests.codes.ok:
return response
except Exception as e:
self.lastJSONResponse = e
return None
else:
self.error_handling(response)
sys.exit(1)


def invokeVMCPUT(self, url: str,json_data: str) -> requests.Response:
"""Invokes a VMC on AWS PUT request"""
Expand Down Expand Up @@ -3601,6 +3589,18 @@ def getNSXTproxy(self, org_id, sddc_id):
print(json_response)
return self.proxy_url

def connectNSX(self):
"""Test connectivity to NSX-T Manager"""
self.vmc_auth.check_access_token_expiration()
my_header = {'csp-auth-token': self.vmc_auth.access_token}
my_url = f'{self.proxy_url}/policy/api/v1/infra'
response = requests.get(my_url, headers=my_header)
if response.status_code == requests.codes.ok:
return True
else:
self.error_handling(response)
return False

def loadConfigFlag(self,config,section,key):
"""Load a True/False flag from the config file"""
try:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ configparser==6.0.0
idna==3.4
PTable==0.9.2
requests==2.31.0
urllib3==1.26.16
urllib3==1.26.18
wcwidth==0.2.6
boto3==1.28.30
prettytable==3.8.0
Expand Down
14 changes: 12 additions & 2 deletions sddc_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,13 @@ def main(args):
if retval == False:
print("Unable to load Source SDDC Data. Server response:{}".format(ioObj.lastJSONResponse))
sys.exit()

retval = ioObj.connectNSX()
if retval == False:
print(f'Unable to connect to Source NSX-T Manager.')
sys.exit(1)

print(f'Export configuration: Org {ioObj.source_org_display_name} ({ioObj.source_org_id}), SDDC {ioObj.source_sddc_name} ({ioObj.source_sddc_id}), SDDC version {ioObj.source_sddc_version}')
print(f'Export configuration: Org {ioObj.source_org_display_name} ({ioObj.source_org_id}), SDDC {ioObj.source_sddc_name} ({ioObj.source_sddc_id}), SDDC version {ioObj.source_sddc_version}, NSX-T Manager reachable.')

ioObj.vmc_auth.getAccessToken(ioObj.dest_refresh_token)
if (ioObj.vmc_auth.access_token == ""):
Expand All @@ -437,8 +442,13 @@ def main(args):
if retval == False:
print("Unable to load Dest SDDC Data. Server response:{}".format(ioObj.lastJSONResponse))
sys.exit()

retval = ioObj.connectNSX()
if retval == False:
print(f'Unable to connect to Destination NSX-T Manager.')
sys.exit(1)

print(f'Import configuration: Org {ioObj.dest_org_display_name} ({ioObj.dest_org_id}), SDDC {ioObj.dest_sddc_name} ({ioObj.dest_sddc_id}), SDDC version {ioObj.dest_sddc_version}')
print(f'Import configuration: Org {ioObj.dest_org_display_name} ({ioObj.dest_org_id}), SDDC {ioObj.dest_sddc_name} ({ioObj.dest_sddc_id}), SDDC version {ioObj.dest_sddc_version}, NSX-T Manager reachable.')

if intent_name == "export" or intent_name == "export-import":
no_intent_found = False
Expand Down

0 comments on commit b61bd19

Please sign in to comment.