Exemple #1
0
def main():
    '''Main routine.'''
    # validate command line arguments
    arg_parser = argparse.ArgumentParser()

    arg_parser.add_argument('--uri',
                            '-u',
                            required=True,
                            action='store',
                            help='Template URI')
    arg_parser.add_argument('--params',
                            '-p',
                            required=True,
                            action='store',
                            help='Parameters json file')
    arg_parser.add_argument('--rg',
                            '-g',
                            required=True,
                            action='store',
                            help='Resource Group name')
    arg_parser.add_argument('--sub',
                            '-s',
                            required=False,
                            action='store',
                            help='subscription id (optional)')

    args = arg_parser.parse_args()

    template_uri = args.uri
    params = args.params
    rgname = args.rg
    subscription_id = args.sub

    # load parameters file
    try:
        with open(params) as params_file:
            param_data = json.load(params_file)
    except FileNotFoundError:
        print('Error: Expecting ' + params + ' in current folder')
        sys.exit()

    access_token = azurerm.get_access_token_from_cli()
    if subscription_id is None:
        subscription_id = azurerm.get_subscription_from_cli()
    deployment_name = Haikunator().haikunate()
    print('Deployment name:' + deployment_name)

    deploy_return = azurerm.deploy_template_uri(access_token, subscription_id,
                                                rgname, deployment_name,
                                                template_uri, param_data)

    print(
        json.dumps(deploy_return.json(),
                   sort_keys=False,
                   indent=2,
                   separators=(',', ': ')))
def main():
    '''Main routine.'''
    # validate command line arguments
    arg_parser = argparse.ArgumentParser()

    arg_parser.add_argument('--uri',
                            '-u',
                            required=True,
                            action='store',
                            help='Template URI')
    arg_parser.add_argument('--params',
                            '-p',
                            required=True,
                            action='store',
                            help='Parameters json file')
    arg_parser.add_argument('--rg',
                            '-g',
                            required=True,
                            action='store',
                            help='Resource Group name')
    args = arg_parser.parse_args()

    template_uri = args.uri
    params = args.params
    rgname = args.rg

    # Load Azure app defaults
    try:
        with open('azurermconfig.json') as config_file:
            config_data = json.load(config_file)
    except FileNotFoundError:
        print('Error: Expecting azurermconfig.json in current folder')
        sys.exit()

    tenant_id = config_data['tenantId']
    app_id = config_data['appId']
    app_secret = config_data['appSecret']
    subscription_id = config_data['subscriptionId']

    # load parameters file
    try:
        with open(params) as params_file:
            param_data = json.load(params_file)
    except FileNotFoundError:
        print('Error: Expecting ' + params + ' in current folder')
        sys.exit()

    access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)
    deployment_name = Haikunator().haikunate()
    print('Deployment name:' + deployment_name)

    deploy_return = azurerm.deploy_template_uri(access_token, subscription_id,
                                                rgname, deployment_name,
                                                template_uri, param_data)
    print(deploy_return)
Exemple #3
0
location = args.location

# Load Azure app defaults
try:
    with open('azurermconfig.json') as config_file:
        config_data = json.load(config_file)
except FileNotFoundError:
    print('Error: Expecting azurermconfig.json in current folder')
    sys.exit()

tenant_id = config_data['tenantId']
app_id = config_data['appId']
app_secret = config_data['appSecret']
subscription_id = config_data['subscriptionId']

# load parameters file
try:
    with open(params) as params_file:
        param_data = json.load(params_file)
except FileNotFoundError:
    print('Error: Expecting ' + params + ' in current folder')
    sys.exit()

access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)
deployment_name = Haikunator().haikunate() 
print('Deployment name:' + deployment_name)

deploy_return = azurerm.deploy_template_uri(
    access_token, subscription_id, rgname, deployment_name, template_uri, param_data)
print(deploy_return)
Exemple #4
0
def main():
    '''Main routine.'''
    # validate command line arguments
    argparser = argparse.ArgumentParser()
    argparser.add_argument('--uri',
                           '-u',
                           required=True,
                           action='store',
                           help='Template URI')
    argparser.add_argument('--params',
                           '-f',
                           required=True,
                           action='store',
                           help='Parameters json file')
    argparser.add_argument('--location',
                           '-l',
                           required=True,
                           action='store',
                           help='Location, e.g. eastus')
    argparser.add_argument('--rg',
                           '-g',
                           required=False,
                           action='store',
                           help='Resource Group name')
    argparser.add_argument('--sub',
                           '-s',
                           required=False,
                           action='store',
                           help='Subscription ID')
    argparser.add_argument(
        '--genparams',
        '-p',
        required=False,
        action='store',
        help='Comma separated list of parameters to generate strings for')
    argparser.add_argument('--wait',
                           '-w',
                           required=False,
                           action='store_true',
                           default=False,
                           help='Wait for deployment to complete and time it')
    argparser.add_argument('--debug',
                           '-d',
                           required=False,
                           action='store_true',
                           default=False,
                           help='Debug mode: print additional deployment')
    args = argparser.parse_args()

    template_uri = args.uri
    params = args.params
    rgname = args.rg
    location = args.location
    subscription_id = args.sub

    # Load Azure app defaults
    try:
        with open('azurermconfig.json') as configfile:
            configdata = json.load(configfile)
    except FileNotFoundError:
        sys.exit('Error: Expecting azurermconfig.json in current folder')

    tenant_id = configdata['tenantId']
    app_id = configdata['appId']
    app_secret = configdata['appSecret']
    if subscription_id is None:
        subscription_id = configdata['subscriptionId']

    # authenticate
    access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)

    # load parameters file
    try:
        with open(params) as params_file:
            param_data = json.load(params_file)
    except FileNotFoundError:
        sys.exit('Error: Expecting ' + params + ' in current folder')

    # prep Haikunator
    haikunator = Haikunator()

    # if there is a genparams argument generate values and merge the list
    if args.genparams is not None:
        newdict = {}
        genlist = args.genparams.split(',')
        for param in genlist:
            # generate a random prhase, include caps and puncs in case it's a passwd
            newval = haikunator.haikunate(delimiter='-').title()
            newdict[param] = {'value': newval}
        params = {**param_data, **newdict}
    else:
        params = param_data

    # create resource group if not specified
    if rgname is None:
        rgname = haikunator.haikunate()
        ret = azurerm.create_resource_group(access_token, subscription_id,
                                            rgname, location)
        print('Creating resource group: ' + rgname + ', location:',
              location + ', return code:', ret)

    deployment_name = haikunator.haikunate()

    # measure time from beginning of deployment call (after creating resource group etc.)
    start_time = time.time()

    # deploy template and print response
    deploy_return = azurerm.deploy_template_uri(access_token, subscription_id,
                                                rgname, deployment_name,
                                                template_uri, params)
    print('Deployment name: ' + deployment_name + ', return code:',
          deploy_return)
    if 'Response [20' not in str(deploy_return):
        print('Return from deployment: ', deploy_return.text)
        sys.exit('Deployment failed. Exiting.. ')
    if args.debug is True:
        print(
            json.dumps(deploy_return.json(),
                       sort_keys=False,
                       indent=2,
                       separators=(',', ': ')))

    # show deployment status
    if args.debug is True:
        print('Deployment status:')
        deploy_return = azurerm.show_deployment(access_token, subscription_id,
                                                rgname, deployment_name)
        print(
            json.dumps(deploy_return,
                       sort_keys=False,
                       indent=2,
                       separators=(',', ': ')))

    # wait for deployment to complete
    if args.wait is True:
        print('Waiting for provisioning to complete..')
        provisioning_state = ''
        try:
            while True:
                time.sleep(10)
                deploy_return = azurerm.show_deployment(
                    access_token, subscription_id, rgname, deployment_name)
                provisioning_state = deploy_return['properties'][
                    'provisioningState']
                if provisioning_state != 'Running':
                    break
            print('Provisioning state:', provisioning_state)
        except KeyError:
            print('Deployment failure:', deploy_return)

    elapsed_time = time.time() - start_time
    print('Elapsed time:', elapsed_time)
Exemple #5
0
# create resource group
rgreturn = azurerm.create_resource_group(access_token, subscription_id, rgname,
                                         location)
print(rgreturn)

print('Enter VMSS name')
vmss_name = input()

print('Enter instance count')
instance_count = input()

params = raw_params.replace('VMSSNAME', vmss_name)
params = params.replace('INSTANCECOUNT', instance_count)
params = params.replace('LOCATION', location)

print('Enter user name')
user_name = input()

params = params.replace('ADMINUSER', user_name)

print('Enter password')
password = input()

params = params.replace('ADMINPASSWORD', password)

deploy_return = azurerm.deploy_template_uri(access_token, subscription_id,
                                            rgname, 'mydep3', template_uri,
                                            params)
print(deploy_return)
                       action='store', help='Resource Group name')
argParser.add_argument('--sub', '-s', required=False,
                       action='store', help='subscription id (optional)')                       

args = argParser.parse_args()

template_uri = args.uri
params = args.params
rgname = args.rg
location = args.location
subscription_id = args.sub

# load parameters file
try:
    with open(params) as params_file:
        param_data = json.load(params_file)
except FileNotFoundError:
    print('Error: Expecting ' + params + ' in current folder')
    sys.exit()

access_token = azurerm.get_access_token_from_cli()
if subscription_id is None:
    subscription_id = azurerm.get_subscription_from_cli()
deployment_name = Haikunator().haikunate() 
print('Deployment name:' + deployment_name)

deploy_return = azurerm.deploy_template_uri(
    access_token, subscription_id, rgname, deployment_name, template_uri, param_data)

print(json.dumps(deploy_return.json(), sort_keys=False, indent=2, separators=(',', ': ')))
def main():
    '''Main routine.'''
    # validate command line arguments
    argparser = argparse.ArgumentParser()
    argparser.add_argument('--uri', '-u', required=True,
                           action='store', help='Template URI')
    argparser.add_argument('--params', '-f', required=True,
                           action='store', help='Parameters json file')
    argparser.add_argument('--location', '-l', required=True,
                           action='store', help='Location, e.g. eastus')
    argparser.add_argument('--rg', '-g', required=False,
                           action='store', help='Resource Group name')
    argparser.add_argument('--sub', '-s', required=False,
                           action='store', help='Subscription ID')
    argparser.add_argument('--genparams', '-p', required=False,
                           action='store', help='Comma separated list of parameters to generate strings for')
    argparser.add_argument('--wait', '-w', required=False, action='store_true', default=False,
                           help='Wait for deployment to complete and time it')
    argparser.add_argument('--debug', '-d', required=False, action='store_true', default=False,
                           help='Debug mode: print additional deployment')
    args = argparser.parse_args()

    template_uri = args.uri
    params = args.params
    rgname = args.rg
    location = args.location
    subscription_id = args.sub

    # Load Azure app defaults
    try:
        with open('azurermconfig.json') as configfile:
            configdata = json.load(configfile)
    except FileNotFoundError:
        sys.exit('Error: Expecting azurermconfig.json in current folder')

    tenant_id = configdata['tenantId']
    app_id = configdata['appId']
    app_secret = configdata['appSecret']
    if subscription_id is None:
        subscription_id = configdata['subscriptionId']

    # authenticate
    access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)

    # load parameters file
    try:
        with open(params) as params_file:
            param_data = json.load(params_file)
    except FileNotFoundError:
        sys.exit('Error: Expecting ' + params + ' in current folder')

    # prep Haikunator
    haikunator = Haikunator()

    # if there is a genparams argument generate values and merge the list
    if args.genparams is not None:
        newdict = {}
        genlist = args.genparams.split(',')
        for param in genlist:
            # generate a random prhase, include caps and puncs in case it's a passwd
            newval = haikunator.haikunate(delimiter='-').title()
            newdict[param] = {'value': newval}
        params = {**param_data, **newdict}
    else:
        params = param_data


    # create resource group if not specified
    if rgname is None:
        rgname = haikunator.haikunate()
        ret = azurerm.create_resource_group(
            access_token, subscription_id, rgname, location)
        print('Creating resource group: ' + rgname +
              ', location:', location + ', return code:', ret)

    deployment_name = haikunator.haikunate()

    # measure time from beginning of deployment call (after creating resource group etc.)
    start_time = time.time()

    # deploy template and print response
    deploy_return = azurerm.deploy_template_uri(
        access_token, subscription_id, rgname, deployment_name, template_uri, params)
    print('Deployment name: ' + deployment_name +
          ', return code:', deploy_return)
    if 'Response [20' not in str(deploy_return):
        print('Return from deployment: ', deploy_return.text)
        sys.exit('Deployment failed. Exiting.. ')
    if args.debug is True:
        print(json.dumps(deploy_return.json(), sort_keys=False,
                         indent=2, separators=(',', ': ')))

    # show deployment status
    if args.debug is True:
        print('Deployment status:')
        deploy_return = azurerm.show_deployment(
            access_token, subscription_id, rgname, deployment_name)
        print(json.dumps(deploy_return, sort_keys=False,
                         indent=2, separators=(',', ': ')))
    
    # wait for deployment to complete
    if args.wait is True:
        print('Waiting for provisioning to complete..')
        provisioning_state = ''
        try:
            while True:
                time.sleep(10)
                deploy_return = azurerm.show_deployment(
                    access_token, subscription_id, rgname, deployment_name) 
                provisioning_state = deploy_return['properties']['provisioningState']
                if provisioning_state != 'Running':
                    break
            print('Provisioning state:', provisioning_state)
        except KeyError:
            print('Deployment failure:', deploy_return)

    elapsed_time = time.time() - start_time
    print('Elapsed time:', elapsed_time)
Exemple #8
0
print('Enter new resource group name')
rgname = input()

# create resource group
rgreturn = azurerm.create_resource_group(access_token, subscription_id, rgname, location)
print(rgreturn)

print('Enter VMSS name')
vmss_name = input()

print('Enter instance count')
instance_count = input()

params = raw_params.replace('VMSSNAME', vmss_name)
params = params.replace('INSTANCECOUNT', instance_count)
params = params.replace('LOCATION', location)

print('Enter user name')
user_name = input()

params = params.replace('ADMINUSER', user_name)

print('Enter password')
password = input()

params = params.replace('ADMINPASSWORD', password)

deploy_return = azurerm.deploy_template_uri(access_token, subscription_id, rgname, 'mydep3', template_uri, params)
print(deploy_return)