Skip to content

Commit

Permalink
AV-192668: Fixes for nsxt converter for cutover and rollback operatio…
Browse files Browse the repository at this point in the history
…ns, fixes for nsx-policy python sdk dependancy
  • Loading branch information
shardullatkar authored and Shardul Latkar committed Nov 14, 2023
1 parent b7fc3dc commit 20b444c
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 136 deletions.
5 changes: 5 additions & 0 deletions python/avi/migrationtools/avi_migration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
warning_count = 0
error_count = 0

HTTP_RESPONSE_CODE_1XX = "HTTP_1XX"
HTTP_RESPONSE_CODE_2XX = "HTTP_2XX"
HTTP_RESPONSE_CODE_3XX = "HTTP_3XX"
HTTP_RESPONSE_CODE_4XX = "HTTP_4XX"
HTTP_RESPONSE_CODE_5XX = "HTTP_5XX"

def set_update_count():
global warning_count, error_count
Expand Down
28 changes: 13 additions & 15 deletions python/avi/migrationtools/nsxt_converter/monitor_converter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Copyright 2021 VMware, Inc.
# SPDX-License-Identifier: Apache License 2.0

import time, logging
import logging

import com.vmware.nsx_policy.model_client as model_client

from avi.migrationtools.avi_migration_utils import update_count
from avi.migrationtools.avi_migration_utils import update_count, HTTP_RESPONSE_CODE_1XX, HTTP_RESPONSE_CODE_2XX, \
HTTP_RESPONSE_CODE_3XX, HTTP_RESPONSE_CODE_4XX, HTTP_RESPONSE_CODE_5XX
from avi.migrationtools.nsxt_converter.conversion_util import NsxtConvUtil, csv_writer_dict_list
import avi.migrationtools.nsxt_converter.converter_constants as conv_const
from avi.migrationtools.avi_migration_utils import MigrationUtil
Expand Down Expand Up @@ -51,24 +50,23 @@ def __init__(self, nsxt_monitor_attributes, object_merge_check, merge_object_map
def get_alb_response_codes(self, response_codes):
if not response_codes:
return None
HttpResponseCode = model_client.ALBHealthMonitorHttp
codes = list()
for code in response_codes:
if code < 200:
if HttpResponseCode.HTTP_RESPONSE_CODE_1XX not in codes:
codes.append(HttpResponseCode.HTTP_RESPONSE_CODE_1XX)
if HTTP_RESPONSE_CODE_1XX not in codes:
codes.append(HTTP_RESPONSE_CODE_1XX)
elif code > 199 and code < 300:
if HttpResponseCode.HTTP_RESPONSE_CODE_2XX not in codes:
codes.append(HttpResponseCode.HTTP_RESPONSE_CODE_2XX)
if HTTP_RESPONSE_CODE_2XX not in codes:
codes.append(HTTP_RESPONSE_CODE_2XX)
elif code > 299 and code < 400:
if HttpResponseCode.HTTP_RESPONSE_CODE_3XX not in codes:
codes.append(HttpResponseCode.HTTP_RESPONSE_CODE_3XX)
if HTTP_RESPONSE_CODE_3XX not in codes:
codes.append(HTTP_RESPONSE_CODE_3XX)
elif code > 399 and code < 500:
if HttpResponseCode.HTTP_RESPONSE_CODE_4XX not in codes:
codes.append(HttpResponseCode.HTTP_RESPONSE_CODE_4XX)
if HTTP_RESPONSE_CODE_4XX not in codes:
codes.append(HTTP_RESPONSE_CODE_4XX)
elif code > 499 and code < 600:
if HttpResponseCode.HTTP_RESPONSE_CODE_5XX not in codes:
codes.append(HttpResponseCode.HTTP_RESPONSE_CODE_5XX)
if HTTP_RESPONSE_CODE_5XX not in codes:
codes.append(HTTP_RESPONSE_CODE_5XX)
return codes

def update_alb_type(self, lb_hm, alb_hm, skipped):
Expand Down
5 changes: 3 additions & 2 deletions python/avi/migrationtools/nsxt_converter/nsxt_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def convert(self, alb_config, output_path):
'custom ref')
parser.add_argument('--traffic_enabled',
help='Traffic Enabled on all migrated VS VIPs',
action="store_true")
action="store_false")
# Added command line args to execute vs_filter.py with vs_name.
parser.add_argument('--vs_filter',
help='comma separated names of virtualservices.\n'
Expand All @@ -441,7 +441,8 @@ def convert(self, alb_config, output_path):
help='Add columns of vs reference and overall skipped '
'settings in status excel sheet')
parser.add_argument('-s', '--vs_state', choices=ARG_CHOICES['vs_state'],
help='State of created VS')
help='State of created VS',
default="deactivate")


start = datetime.now()
Expand Down
16 changes: 13 additions & 3 deletions python/avi/migrationtools/nsxt_converter/nsxt_traffic_cutover.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def __init__(self, args):
# Load values from state file if not given on command line while executing script
if self.nsxt_ip:
output_path = output_dir + os.path.sep + self.nsxt_ip + os.path.sep + "output"
with open(output_path + os.path.sep + "state.json", 'r') as file:
data = json.load(file)
if os.path.isfile(output_path + os.path.sep + "state.json"):
with open(output_path + os.path.sep + "state.json", 'r') as file:
data = json.load(file)
if not self.nsxt_user:
self.nsxt_user = data.get('nsxt_user')
if not self.nsxt_port:
Expand All @@ -71,6 +72,15 @@ def __init__(self, args):
if not self.prefix:
self.prefix = data.get('prefix')

input_path = None
self.input_data = None
if self.nsxt_ip:
input_path = output_dir + os.path.sep + self.nsxt_ip + os.path.sep + "input"
else:
input_path = output_dir + os.path.sep + "config-output" + os.path.sep + "input"
with open(input_path + os.path.sep + "config.json", 'r') as file:
self.input_data = json.load(file)

def initiate_cutover_vs(self):

if not os.path.exists(self.output_file_path):
Expand All @@ -79,7 +89,7 @@ def initiate_cutover_vs(self):

nsx_util = NSXUtil(self.nsxt_user, self.nsxt_password, self.nsxt_ip, self.nsxt_port,
self.controller_ip, self.user, self.password, self.controller_version)
vs_not_found = nsx_util.cutover_vs(self.vs_filter, self.prefix, self.alb_controller_tenant)
vs_not_found = nsx_util.cutover_vs(self.vs_filter, self.input_data, self.prefix, self.alb_controller_tenant)
if vs_not_found:
print_msg = "\033[93m" + "Warning: Following virtual service/s could not be found" + "\033[0m"
print(print_msg)
Expand Down
Loading

0 comments on commit 20b444c

Please sign in to comment.