Beispiel #1
0
def assign_role_to_student_group(IMAGE_NAME):
    # for students group
    check_output_wrapper("""
        az role assignment create \
            --role Contributor \
            --assignee "{g}" \
            --scope "/subscriptions/{s}/resourceGroups/admin_resources/providers/Microsoft.Compute/images/{image}"
        """.format(image=IMAGE_NAME,
                   g=get_ad_group_id(AD_GROUP),
                   s=get_subscription_id()),
                         shell=True)
Beispiel #2
0
def create_vm(idx, password):
    VM_NAME = INT_DNS_NAME.format(idx)

    IMAGE_NAME = "/subscriptions/" + utils.get_subscription_id() + \
                 "/resourceGroups/admin_resources/providers/Microsoft.Compute/images/ubuntu_gpu_image1_" + region
    data_disks = "255 255 255 255"

    user_pass = password
    cloud_init_fn = cloud_init_fill_template("configs/cloud_init_sirius_template.txt", user_pass, postfix=str(idx))
    utils.create_vm(VM_NAME, rg_name, region, IMAGE_NAME, NIC_NAME.format(idx), vm_size, None, OS_DISK_NAME.format(idx),
                    user_pass, cloud_init_fn, data_disks)

    print("{} public IP: {}".format(VM_NAME, utils.get_public_ip(IP_NAME.format(idx), rg_name)))
Beispiel #3
0
def create_cluster_node(idx, user_pass):
    IP_NAME = "ip_cluster{0}".format(idx)
    NIC_NAME = "nic_cluster{0}".format(idx)
    INT_DNS_NAME = "cluster{0}".format(idx)
    OS_DISK_NAME = "cluster{0}_os_disk".format(idx)
    VM_NAME = INT_DNS_NAME
    IP = "10.0.1.2{0}".format(idx)

    if idx != 1:
        IP_NAME = None

    if args.create_aux:
        # create public IP
        if IP_NAME is not None:
            utils.create_public_ip(IP_NAME, rg_name)

        # Create network card with fixed private IP
        utils.create_nic_with_private_ip(NIC_NAME, rg_name, VNET_NAME,
                                         SUBNET_NAME, NSG_NAME, IP_NAME,
                                         INT_DNS_NAME, IP)

    # create VM https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-sizes
    IMAGE_NAME = "/subscriptions/" + utils.get_subscription_id() + \
                 "/resourceGroups/admin_resources/providers/Microsoft.Compute/images/" + \
                 "cluster{0}".format(idx) + "_image1_" + region
    data_disks = "255 255 255 255"

    if idx == 1:
        cloud_init_fn = cloud_init_fill_template(
            "configs/cloud_init_cluster_master_template.txt", user_pass)
    else:
        cloud_init_fn = "configs/cloud_init_cluster_slave.txt"
    utils.create_vm(VM_NAME, rg_name, region, IMAGE_NAME, NIC_NAME, vm_size,
                    None, OS_DISK_NAME, user_pass, cloud_init_fn, data_disks,
                    "Standard_LRS")

    if RESIZE_OS_DISK:
        utils.deallocate_vm(VM_NAME, rg_name)
        utils.resize_managed_disk(rg_name, OS_DISK_NAME, OS_DISK_SIZE)
        utils.start_vm(VM_NAME, rg_name)
Beispiel #4
0
    #%%

    options = SizeOptions()
    # options.account_names = ['']

    log = CustomLogging()

    auth = Authentication()

    credentials = utils.authenticate_device_code(auth)

    #authenticate using azure registered app
    #credentials = authenticate_client_key = utils.authenticate_client_key(auth)

    subscription_id = utils.get_subscription_id(credentials)

    print('Writing logs to:\n{}\n{}\n{}\n\n'.format(
        log.debug_log, log.blob_container_info_log, log.storage_info_log))

    azure_st = AzureStorageSize(credentials, subscription_id, log)
    azure_st.log_info(
        "Program started on: " + str(datetime.datetime.now()) + "\n",
        Log_type.debug)
    azure_st.get_storage_size(options)
    azure_st.log_info(
        "\n\nProgram ended on: " + str(datetime.datetime.now()) + "\n",
        Log_type.debug)

    print('Finished writing logs to:\n{}\n{}\n\n'.format(
        log.debug_log, log.blob_container_info_log, log.storage_info_log))
Beispiel #5
0
INT_DNS_NAME = UBUNTUGPU_VM
OS_DISK_NAME = "ubuntugpu_os_disk"
IP = "10.0.1.10"

if args.create_aux:
    # create public IP
    utils.create_public_ip(IP_NAME, RG_NAME)

    # Create network card with fixed private IP
    utils.create_nic_with_private_ip(NIC_NAME, RG_NAME, VNET_NAME, SUBNET_NAME,
                                     NSG_NAME, IP_NAME, INT_DNS_NAME, IP)

# create VM
VM_NAME = INT_DNS_NAME

IMAGE_NAME = "/subscriptions/" + utils.get_subscription_id() + \
             "/resourceGroups/" + RG_NAME + "/providers/Microsoft.Compute/images/" + UBUNTUGPU_IMAGE
data_disks = "255 255 255 255"

user_pass = utils.generate_pass()
cloud_init_fn = cloud_init_fill_template(
    "configs/cloud_init_ubuntugpu_template.txt", user_pass)
utils.create_vm(VM_NAME, RG_NAME, REGION, IMAGE_NAME, NIC_NAME, VM_SIZE, None,
                OS_DISK_NAME, user_pass, cloud_init_fn, data_disks)

if RESIZE_OS_DISK:
    utils.deallocate_vm(VM_NAME, RG_NAME)
    utils.resize_managed_disk(RG_NAME, OS_DISK_NAME, OS_DISK_SIZE)
    utils.start_vm(VM_NAME, RG_NAME)

print("ubuntugpu public IP: {}".format(utils.get_public_ip(IP_NAME, RG_NAME)))
Beispiel #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json

import pandas as pd

import utils

users = pd.read_json("users.json", orient="records")

# users = json.load(open("sber.json"))
# users = pd.DataFrame(users.keys(), columns=["user"])

subscription_id = utils.get_subscription_id()
VM_NAME = "ubuntugpu"
start = "2018-06-03T00:00:00Z"
end = "2018-06-21T00:00:00Z"
interval = "PT24H"

df = []

for idx, (_, row) in enumerate(users.iterrows()):
    row = dict(row)
    user = row["user"]
    rg_name = utils.get_student_resource_group(user)
    print user, rg_name
    out = utils.get_cpu_usage(subscription_id, rg_name, VM_NAME, start, end,
                              interval)
    if out is not None:
        out = dict(out)
        out["student"] = user