Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Python Azure Webserver example #236

Merged
merged 9 commits into from
Mar 21, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Format code
  • Loading branch information
swgillespie committed Mar 20, 2019
commit 2c801609fc105bff66199f10e88ee6df440a55f2
114 changes: 60 additions & 54 deletions azure-py-webserver/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,73 @@
password = config.require("password")

resource_group = core.ResourceGroup("server", location="West US")
net = network.VirtualNetwork("server-network",
resource_group_name=resource_group.name,
location=resource_group.location,
address_spaces=["10.0.0.0/16"],
subnets=[{
"name": "default",
"address_prefix": "10.0.1.0/24",
}])
net = network.VirtualNetwork(
"server-network",
resource_group_name=resource_group.name,
location=resource_group.location,
address_spaces=["10.0.0.0/16"],
subnets=[{
"name": "default",
"address_prefix": "10.0.1.0/24",
}])

subnet = network.Subnet("server-subnet",
resource_group_name=resource_group.name,
virtual_network_name=net.name,
address_prefix="10.0.2.0/24")
public_ip = network.PublicIp("server-ip",
resource_group_name=resource_group.name,
location=resource_group.location,
allocation_method="Dynamic")
subnet = network.Subnet(
"server-subnet",
resource_group_name=resource_group.name,
virtual_network_name=net.name,
address_prefix="10.0.2.0/24")
public_ip = network.PublicIp(
"server-ip",
resource_group_name=resource_group.name,
location=resource_group.location,
allocation_method="Dynamic")

network_iface = network.NetworkInterface("server-nic",
resource_group_name=resource_group.name,
location=resource_group.location,
ip_configurations=[{
"name": "webserveripcfg",
"subnet_id": subnet.id,
"private_ip_address_allocation": "Dynamic",
"public_ip_address_id": public_ip.id,
}])
network_iface = network.NetworkInterface(
"server-nic",
resource_group_name=resource_group.name,
location=resource_group.location,
ip_configurations=[{
"name": "webserveripcfg",
"subnet_id": subnet.id,
"private_ip_address_allocation": "Dynamic",
"public_ip_address_id": public_ip.id,
}])

userdata = """#!/bin/bash

echo "Hello, World!" > index.html
nohup python -m SimpleHTTPServer 80 &"""

vm = compute.VirtualMachine("server-vm",
resource_group_name=resource_group.name,
location=resource_group.location,
network_interface_ids=[network_iface.id],
vm_size="Standard_A0",
delete_data_disks_on_termination=True,
delete_os_disk_on_termination=True,
os_profile={
"computer_name": "hostname",
"admin_username": username,
"admin_password": password,
"custom_data": userdata,
},
os_profile_linux_config={
"disable_password_authentication": False,
},
storage_os_disk={
"create_option": "FromImage",
"name": "myosdisk1",
},
storage_image_reference={
"publisher": "canonical",
"offer": "UbuntuServer",
"sku": "16.04-LTS",
"version": "latest",
})
vm = compute.VirtualMachine(
"server-vm",
resource_group_name=resource_group.name,
location=resource_group.location,
network_interface_ids=[network_iface.id],
vm_size="Standard_A0",
delete_data_disks_on_termination=True,
delete_os_disk_on_termination=True,
os_profile={
"computer_name": "hostname",
"admin_username": username,
"admin_password": password,
"custom_data": userdata,
},
os_profile_linux_config={
"disable_password_authentication": False,
},
storage_os_disk={
"create_option": "FromImage",
"name": "myosdisk1",
},
storage_image_reference={
"publisher": "canonical",
"offer": "UbuntuServer",
"sku": "16.04-LTS",
"version": "latest",
})


combined_output = Output.all(vm.id, public_ip.name, public_ip.resource_group_name)
public_ip_addr = combined_output.apply(lambda lst: network.get_public_ip(name=lst[1], resource_group_name=lst[2]))
combined_output = Output.all(vm.id, public_ip.name,
public_ip.resource_group_name)
public_ip_addr = combined_output.apply(
lambda lst: network.get_public_ip(name=lst[1], resource_group_name=lst[2]))
pulumi.export("public_ip", public_ip_addr.ip_address)