Skip to content

Commit

Permalink
modulize each resource
Browse files Browse the repository at this point in the history
  • Loading branch information
lee212 committed Oct 6, 2016
1 parent 4b847f9 commit dbfd00a
Show file tree
Hide file tree
Showing 12 changed files with 548 additions and 7 deletions.
14 changes: 7 additions & 7 deletions simpleazure/arm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

"""
simpleazure.AzureResourceManagerTemplate
simpleazure.arm
This module supports Azure Resource Manager with its Template in terms of deploying software stacks.
Expand All @@ -20,13 +20,13 @@
from . import utils


class Template(object):
"""Constructs a :class:`Template <Template>`.
Returns :class:`Template <Template>` instance.
class ARM(object):
"""Constructs a :class:`ARM <ARM>`.
Returns :class:`ARM <ARM>` instance.
Usage::
>> from simpleazure.arm import Template as armt
>> from simpleazure.arm import ARM as armt
>> arm = armt()
"""
Expand Down Expand Up @@ -57,7 +57,7 @@ def deploy(self, template=None, param=None):
self.set_sshkey()
self.set_template(template)
self.set_parameters(param)
self.set_properties()
self.set_deployment_properties()
self.update_rg()
self.call_deploy()

Expand Down Expand Up @@ -92,7 +92,7 @@ def get_location(self):
""" Returns lower case without space """
return self.location.lower().replace(" ", "")

def set_properties(self):
def set_deployment_properties(self):
self.deployment_properties = {
'mode': dm.incremental,
'template': self.template,
Expand Down
Empty file.
34 changes: 34 additions & 0 deletions simpleazure/template/compile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-

"""
simpleazure.template.compile
This module compiles Azure Resource Manager Templates
:copyright:
:license:
"""

from reader import Reader
from template import Template

class Compile(object):
"""Constructs a :class:`Compile <NEW>`.
Returns :class:`Compile <NEW>` instance.
Usage::
"""

def __init__(self):
self.template = Template()
self.reader = Reader()


def main():
template_deployment = Compile()
temp = template_deployment.reader.get_defaults()
asvm = temp['azuredeploy']
# read arm class
# set parameter
203 changes: 203 additions & 0 deletions simpleazure/template/defaults/azuredeploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUserName": {
"type": "string",
"defaultValue": "azureuser",
"metadata": {
"description": "User name for the Virtual Machine."
}
},
"sshKeyData": {
"type": "string",
"metadata": {
"description": "SSH rsa public key file as a string."
}
}
},
"variables": {
"vmSize": "Standard_DS2",
"vmName": "sshvm",
"ubuntuOSVersion": "14.04.4-LTS",
"storageAccountName": "[concat(uniquestring(resourceGroup().id), 'sasshvm')]",
"uniqueDnsLabelPrefix": "[concat('store', uniquestring(resourceGroup().id))]",
"location": "[resourceGroup().location]",
"imagePublisher": "Canonical",
"imageOffer": "UbuntuServer",
"osDiskName": "osDisk1",
"addressPrefix": "10.0.0.0/16",
"subnet1Name": "Subnet-1",
"subnet1Prefix": "10.0.0.0/24",
"vmStorageAccountContainerName": "vhds",
"nicName": "sshNIC",
"publicIPAddressName": "sshPublicIP",
"publicIPAddressType": "Dynamic",
"storageAccountType": "Premium_LRS",
"virtualNetworkName": "sshVNET",
"networkSecurityGroupName": "networkSecurityGroup1",
"sshKeyPath": "[concat('/home/',parameters('adminUserName'),'/.ssh/authorized_keys')]",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]",
"subnet1Ref": "[concat(variables('vnetID'),'/subnets/',variables('subnet1Name'))]",
"apiVersion": "2015-06-15"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "[variables('apiVersion')]",
"location": "[variables('location')]",
"properties": {
"accountType": "[variables('storageAccountType')]"
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/networkSecurityGroups",
"name": "[variables('networkSecurityGroupName')]",
"location": "[variables('location')]",
"properties": {
"securityRules": [
{
"name": "ssh_rule",
"properties": {
"description": "Locks inbound down to ssh default port 22.",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "22",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 123,
"direction": "Inbound"
}
}
]
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[variables('location')]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[variables('uniqueDnsLabelPrefix')]"
}
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[variables('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', variables('networkSecurityGroupName'))]"
],
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnet1Name')]",
"properties": {
"addressPrefix": "[variables('subnet1Prefix')]",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
}
}
}
]
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[variables('location')]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnet1Ref')]"
}
}
}
]
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[variables('location')]",
"dependsOn": [
"[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[variables('vmSize')]"
},
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUserName')]",
"linuxConfiguration": {
"disablePasswordAuthentication": "true",
"ssh": {
"publicKeys": [
{
"path": "[variables('sshKeyPath')]",
"keyData": "[parameters('sshKeyData')]"
}
]
}
}
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[variables('ubuntuOSVersion')]",
"version": "latest"
},
"osDisk": {
"name": "osdisk",
"vhd": {
"uri": "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/', variables('osDiskName'),'.vhd')]"
},
"caching": "ReadWrite",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
}
}
}
],
"outputs": {
"sshCommand": {
"type": "string",
"value": "[concat('ssh ', parameters('adminUsername'), '@', variables('uniqueDnsLabelPrefix'), '.', resourceGroup().location, '.cloudapp.azure.com')]"
}
}
}
24 changes: 24 additions & 0 deletions simpleazure/template/defaults/netSecurityGroups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/networkSecurityGroups",
"name": "[variables('networkSecurityGroupName')]",
"location": "[variables('location')]",
"properties": {
"securityRules": [
{
"name": "ssh_rule",
"properties": {
"description": "Locks inbound down to ssh default port 22.",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "22",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 123,
"direction": "Inbound"
}
}
]
}
}
26 changes: 26 additions & 0 deletions simpleazure/template/defaults/networkinterfaces.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[variables('location')]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnet1Ref')]"
}
}
}
]
}
}
12 changes: 12 additions & 0 deletions simpleazure/template/defaults/publicIPAddresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[variables('location')]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[variables('uniqueDnsLabelPrefix')]"
}
}
}
9 changes: 9 additions & 0 deletions simpleazure/template/defaults/storage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "[variables('apiVersion')]",
"location": "[variables('location')]",
"properties": {
"accountType": "[variables('storageAccountType')]"
}
}
27 changes: 27 additions & 0 deletions simpleazure/template/defaults/virtualNetworks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[variables('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', variables('networkSecurityGroupName'))]"
],
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnet1Name')]",
"properties": {
"addressPrefix": "[variables('subnet1Prefix')]",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
}
}
}
]
}
}

0 comments on commit dbfd00a

Please sign in to comment.