def main():
<EOL>arg_parser = argparse.ArgumentParser()<EOL>arg_parser.add_argument('<STR_LIT>', '<STR_LIT>', required=True, action='<STR_LIT:store>', help='<STR_LIT:Name>')<EOL>arg_parser.add_argument('<STR_LIT>', '<STR_LIT>', required=True, action='<STR_LIT:store>',<EOL>help='<STR_LIT>')<EOL>arg_parser.add_argument('<STR_LIT>', '<STR_LIT>', required=False, action='<STR_LIT:store>', default='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>arg_parser.add_argument('<STR_LIT>', '<STR_LIT>', required=False, action='<STR_LIT:store>',<EOL>help='<STR_LIT>')<EOL>arg_parser.add_argument('<STR_LIT>', '<STR_LIT>', required=False, action='<STR_LIT:store>',<EOL>help='<STR_LIT>')<EOL>arg_parser.add_argument('<STR_LIT>', '<STR_LIT>', required=False, action='<STR_LIT:store>',<EOL>help='<STR_LIT>')<EOL>arg_parser.add_argument('<STR_LIT>', '<STR_LIT>', required=False, action='<STR_LIT:store>',<EOL>help='<STR_LIT>')<EOL>arg_parser.add_argument('<STR_LIT>', required=False, action='<STR_LIT:store>', default='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>arg_parser.add_argument('<STR_LIT>', '<STR_LIT>', required=False, action='<STR_LIT:store>',<EOL>help='<STR_LIT>')<EOL>arg_parser.add_argument('<STR_LIT>', required=False, action='<STR_LIT:store>',<EOL>help='<STR_LIT>')<EOL>arg_parser.add_argument('<STR_LIT>', action='<STR_LIT:store_true>', default=False,<EOL>help='<STR_LIT>')<EOL>arg_parser.add_argument('<STR_LIT>', action='<STR_LIT:store_true>', default=False,<EOL>help='<STR_LIT>')<EOL>arg_parser.add_argument('<STR_LIT>', '<STR_LIT>', action='<STR_LIT:store_true>', default=False,<EOL>help='<STR_LIT>')<EOL>args = arg_parser.parse_args()<EOL>name = args.vmname<EOL>rgname = args.rgname<EOL>vnet = args.vnet<EOL>location = args.location<EOL>username = args.user<EOL>password = args.password<EOL>sshkey = args.sshkey<EOL>sshpath = args.sshpath<EOL>verbose = args.verbose<EOL>dns_label = args.dns<EOL>no_wait = args.nowait<EOL>no_nsg = args.nonsg<EOL>vmsize = args.vmsize<EOL>if sshkey is not None and sshpath is not None:<EOL><INDENT>sys.exit('<STR_LIT>')<EOL><DEDENT>if password is not None and (sshkey is not None or sshpath is not None):<EOL><INDENT>sys.exit('<STR_LIT>')<EOL><DEDENT>use_password = False<EOL>if password is not None:<EOL><INDENT>use_password = True<EOL><DEDENT>else:<EOL><INDENT>if sshkey is None and sshpath is None: <EOL><INDENT>home = os.path.expanduser('<STR_LIT>')<EOL>sshpath = home + os.sep + '<STR_LIT>' + os.sep + '<STR_LIT>'<EOL>if os.path.isfile(sshpath) is False:<EOL><INDENT>print('<STR_LIT>')<EOL>use_password = True<EOL>password = Haikunator().haikunate(delimiter='<STR_LIT:U+002C>') <EOL>print('<STR_LIT>' + password)<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>if use_password is False:<EOL><INDENT>print('<STR_LIT>')<EOL>if sshkey is None:<EOL><INDENT>with open(sshpath, '<STR_LIT:r>') as pub_ssh_file_fd:<EOL><INDENT>sshkey = pub_ssh_file_fd.read()<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>with open('<STR_LIT>') as config_file:<EOL><INDENT>config_data = json.load(config_file)<EOL><DEDENT><DEDENT>except FileNotFoundError:<EOL><INDENT>sys.exit("<STR_LIT>")<EOL><DEDENT>tenant_id = config_data['<STR_LIT>']<EOL>app_id = config_data['<STR_LIT>']<EOL>app_secret = config_data['<STR_LIT>']<EOL>subscription_id = config_data['<STR_LIT>']<EOL>access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)<EOL>if location is None:<EOL><INDENT>try:<EOL><INDENT>rgroup = azurerm.get_resource_group(access_token, subscription_id, rgname)<EOL>location = rgroup['<STR_LIT:location>']<EOL><DEDENT>except KeyError:<EOL><INDENT>print('<STR_LIT>' + rgname + '<STR_LIT>')<EOL>print(json.dumps(rgroup, sort_keys=False, indent=<NUM_LIT:2>, separators=('<STR_LIT:U+002C>', '<STR_LIT>')))<EOL>sys.exit()<EOL><DEDENT>print('<STR_LIT>' + location)<EOL><DEDENT>print('<STR_LIT>')<EOL>vnet_not_found = False<EOL>if vnet is None:<EOL><INDENT>print('<STR_LIT>')<EOL>try:<EOL><INDENT>vnets = azurerm.list_vnets_rg(access_token, subscription_id, rgname)<EOL>vnetresource = vnets['<STR_LIT:value>'][<NUM_LIT:0>]<EOL><DEDENT>except IndexError:<EOL><INDENT>print('<STR_LIT>')<EOL>vnet_not_found = True<EOL>vnet = name + '<STR_LIT>'<EOL><DEDENT><DEDENT>else:<EOL><INDENT>print('<STR_LIT>' + vnet)<EOL>vnetresource = azurerm.get_vnet(access_token, subscription_id, rgname, vnet)<EOL>if '<STR_LIT>' not in vnetresource:<EOL><INDENT>print('<STR_LIT>' + vnet + '<STR_LIT>' + rgname)<EOL>vnet_not_found = True<EOL><DEDENT><DEDENT>if vnet_not_found is True:<EOL><INDENT>print('<STR_LIT>' + vnet)<EOL>rmresource = azurerm.create_vnet(access_token, subscription_id, rgname, vnet, location,address_prefix='<STR_LIT>', nsg_id=None)<EOL>if rmresource.status_code != <NUM_LIT>:<EOL><INDENT>print('<STR_LIT>' + str(vnetresource.status_code) + '<STR_LIT>' + vnetresource.text)<EOL>sys.exit()<EOL><DEDENT>vnetresource = azurerm.get_vnet(access_token, subscription_id, rgname, vnet)<EOL><DEDENT>try:<EOL><INDENT>subnet_id = vnetresource['<STR_LIT>']['<STR_LIT>'][<NUM_LIT:0>]['<STR_LIT:id>']<EOL><DEDENT>except KeyError:<EOL><INDENT>print('<STR_LIT>' + vnet)<EOL>sys.exit()<EOL><DEDENT>if verbose is True:<EOL><INDENT>print('<STR_LIT>' + subnet_id)<EOL><DEDENT>public_ip_name = name + '<STR_LIT>'<EOL>if dns_label is None:<EOL><INDENT>dns_label = name + '<STR_LIT>'<EOL><DEDENT>print('<STR_LIT>')<EOL>rmreturn = azurerm.create_public_ip(access_token, subscription_id, rgname, public_ip_name,<EOL>dns_label, location)<EOL>if rmreturn.status_code not in [<NUM_LIT:200>, <NUM_LIT>]:<EOL><INDENT>print(rmreturn.text)<EOL>sys.exit('<STR_LIT>' + str(rmreturn.status_code) + '<STR_LIT>')<EOL><DEDENT>ip_id = rmreturn.json()['<STR_LIT:id>']<EOL>if verbose is True:<EOL><INDENT>print('<STR_LIT>' + ip_id)<EOL><DEDENT>print('<STR_LIT>')<EOL>waiting = True<EOL>while waiting:<EOL><INDENT>pip = azurerm.get_public_ip(access_token, subscription_id, rgname, public_ip_name)<EOL>if pip['<STR_LIT>']['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>waiting = False<EOL><DEDENT>time.sleep(<NUM_LIT:1>)<EOL><DEDENT>if no_nsg is True:<EOL><INDENT>nsg_id = None<EOL><DEDENT>else:<EOL><INDENT>nsg_name = name + '<STR_LIT>'<EOL>print('<STR_LIT>' + nsg_name)<EOL>rmreturn = azurerm.create_nsg(access_token, subscription_id, rgname, nsg_name, location)<EOL>if rmreturn.status_code not in [<NUM_LIT:200>, <NUM_LIT>]:<EOL><INDENT>print('<STR_LIT>' + str(rmreturn.status_code) + '<STR_LIT>' + rmreturn.text)<EOL>sys.exit()<EOL><DEDENT>nsg_id = rmreturn.json()['<STR_LIT:id>']<EOL>nsg_rule = '<STR_LIT>'<EOL>print('<STR_LIT>' + nsg_rule)<EOL>rmreturn = azurerm.create_nsg_rule(access_token, subscription_id, rgname, nsg_name,<EOL>nsg_rule, description='<STR_LIT>',<EOL>destination_range='<STR_LIT>')<EOL>if rmreturn.status_code not in [<NUM_LIT:200>, <NUM_LIT>]:<EOL><INDENT>print('<STR_LIT>' + str(rmreturn.status_code) + '<STR_LIT>' + rmreturn.text)<EOL>sys.exit()<EOL><DEDENT><DEDENT>nic_name = name + '<STR_LIT>'<EOL>print('<STR_LIT>' + nic_name)<EOL>rmreturn = azurerm.create_nic(access_token, subscription_id, rgname, nic_name, ip_id,<EOL>subnet_id, location, nsg_id=nsg_id)<EOL>if rmreturn.status_code not in [<NUM_LIT:200>, <NUM_LIT>]:<EOL><INDENT>print('<STR_LIT>' + rmreturn.status_code + '<STR_LIT>' + rmreturn.text)<EOL>sys.exit()<EOL><DEDENT>nic_id = rmreturn.json()['<STR_LIT:id>']<EOL>print('<STR_LIT>')<EOL>waiting = True<EOL>while waiting:<EOL><INDENT>nic = azurerm.get_nic(access_token, subscription_id, rgname, nic_name)<EOL>if nic['<STR_LIT>']['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>waiting = False<EOL><DEDENT>time.sleep(<NUM_LIT:1>)<EOL><DEDENT>vm_name = name<EOL>publisher = '<STR_LIT>'<EOL>offer = '<STR_LIT>'<EOL>sku = '<STR_LIT>'<EOL>version = '<STR_LIT>'<EOL>print('<STR_LIT>' + vm_name)<EOL>if use_password is True:<EOL><INDENT>rmreturn = azurerm.create_vm(access_token, subscription_id, rgname, vm_name, vmsize,<EOL>publisher, offer, sku, version, nic_id, location,<EOL>username=username, password=password)<EOL><DEDENT>else:<EOL><INDENT>rmreturn = azurerm.create_vm(access_token, subscription_id, rgname, vm_name, vmsize,<EOL>publisher, offer, sku, version, nic_id, location,<EOL>username=username, public_key=sshkey)<EOL><DEDENT>if rmreturn.status_code != <NUM_LIT>:<EOL><INDENT>sys.exit('<STR_LIT>' + rmreturn.status_code + '<STR_LIT>' + rmreturn.text)<EOL><DEDENT>if no_wait is False:<EOL><INDENT>print('<STR_LIT>')<EOL>waiting = True<EOL>while waiting:<EOL><INDENT>vm_model = azurerm.get_vm(access_token, subscription_id, rgname, vm_name)<EOL>if vm_model['<STR_LIT>']['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>waiting = False<EOL><DEDENT>time.sleep(<NUM_LIT:5>)<EOL><DEDENT>print('<STR_LIT>')<EOL><DEDENT>print('<STR_LIT>')<EOL>print('<STR_LIT>' + dns_label + '<STR_LIT:.>' + location + '<STR_LIT>' + username)<EOL>
Main routine.