Created
March 2, 2017 17:25
-
-
Save iassael/68abb2fed6a9430f7dccdac83e1c2f9e to your computer and use it in GitHub Desktop.
Azure CLI create VM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import subprocess | |
import string | |
import random | |
import csv | |
import json | |
import pprint | |
ips = [] | |
passwords = [] | |
machines = [] | |
output = '' | |
with open('students.csv') as csvfile: | |
rows = csv.DictReader(csvfile) | |
for row in rows: | |
first_name = row["First name"].replace(' ', '').title() | |
last_name = row["Last name"].replace(' ', '').title() | |
if len(row["Ip"]) > 2: | |
continue | |
# Alphanumeric + special characters | |
password = ''.join((random.choice(string.ascii_letters.lower())) for x in range(3)) + ''.join((random.choice(string.ascii_letters.upper())) for x in range(3)) + ''.join((random.choice(string.digits)) for x in range(2)) | |
passwords.append(password) | |
machines.append(first_name + last_name + 'NLP2017') | |
command = [ 'az', 'vm', 'create', | |
'--output', 'json', | |
'--image', 'Canonical:UbuntuServer:16.04-LTS:latest', | |
'--authentication-type', 'password', | |
'--admin-username', 'deepnlp2017', | |
'--admin-password', password, | |
'--storage-sku', 'Standard_LRS', | |
'--size', 'Standard_NC6', | |
'--resource-group', 'DeepNLPEUS', | |
'--name', first_name + last_name + 'NLP2017'] | |
# '--location', 'eastus', | |
print(' '.join(command)) | |
p_out = subprocess.check_output(command, stderr=subprocess.STDOUT).decode('utf8') | |
print(p_out) | |
p_out_json = json.loads(p_out) | |
ip = p_out_json["publicIpAddress"] | |
ips.append(ip) | |
output += first_name + last_name + 'NLP2017\t' + password + '\t' + ip + '\n' | |
f = open('students_output.csv', 'w') | |
f.write(output) | |
f.close() | |
f = open('students_machine.csv', 'w') | |
f.write('\n'.join(machines)) | |
f.close() | |
f = open('students_pass.csv', 'w') | |
f.write('\n'.join(passwords)) | |
f.close() | |
f = open('students_ip.csv', 'w') | |
f.write('\n'.join(ips)) | |
f.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment