def aznsg(csvfile): utils.Timed() prefs = Preferences() os_path = os.path.abspath(os.path.dirname(__file__)) # Build NSG list from AzCLI Json doc try: Az = JSONParser().parseAzureAccountJson() print( f"Importing NSGs from Azure:\nAccount: {Az['name']}\nEnvironment: {Az['environmentName']}" ) nsglist = JSONParser().parseJson() grouper_file = os.path.join(os_path, csvfile) CSVParser(csvfile).writeCSVFromNSGList(nsglist, os_path) utils.printOutputTable(nsglist) print( f"Successfully imported NSG Rules from Azure to file [{csvfile}]!") except: print( "An error occurred while accessing Azure. Please verify your Azure CLI installation, or your current login with Azure CLI (use 'az login') before continuing." ) utils.Timed()
def csvtoarm(csvfile): utils.Timed() os_path = os.path.abspath(os.path.dirname(__file__)) #Parse datafile if provided if(len(csvfile) > 0): grouper_file = os.path.join(os_path, csvfile) file_exists = os.path.isfile(grouper_file) if(file_exists == False): print(f"Error: There was an issue reading in the data file {csvfile}.\n\nPlease use the --genfile option to generate a sample data file to customize.") sys.exit(200) parser = CSVParser(grouper_file) nsglist = parser.doCSVParse() armWriter = ARMWriter() arm_template = armWriter.doBuild_Nsg_Template(nsglist.nsgDict) if (armWriter.doWrite_ARMTemplate(arm_template)): utils.printOutputTable(nsglist) print(f"Successfully created output ARM Templates in [output] directory for each NSG!") utils.Timed()
def csvtocli(csvfile, clifile): utils.Timed() os_path = os.path.abspath(os.path.dirname(__file__)) #Parse datafile if provided if (len(csvfile) > 0): grouper_file = os.path.join(os_path, csvfile) file_exists = os.path.isfile(grouper_file) if (file_exists == False): print( f"Error: There was an error reading in the data file {csvfile}.\n\nPlease use the --genfile option to generate a sample data file to customize." ) sys.exit(200) parser = CSVParser(grouper_file) nsglist = parser.doCSVParse() cliWriter = CLIWriter(clifile) if (cliWriter.doWrite_CLIScript( nsglist.nsgDict, os.path.abspath(os.path.dirname(__file__)))): utils.printOutputTable(nsglist) print( f"Successfully created CLI Scripts in [output] directory for each NSG!" ) utils.Timed()