From 03fb50bd2c271cf5f01b1067156d2becb0a4e861 Mon Sep 17 00:00:00 2001 From: Rafael Godinho Date: Thu, 19 Apr 2018 17:27:34 -0700 Subject: [PATCH] Simple scenario --- generator/debug.sh | 12 +++++++ generator/deploy.sh | 1 + generator/deployment.py | 61 +++++++++++++++++--------------- generator/parameters/simple.yaml | 2 +- 4 files changed, 46 insertions(+), 30 deletions(-) create mode 100644 generator/debug.sh diff --git a/generator/debug.sh b/generator/debug.sh new file mode 100644 index 0000000..dcd0652 --- /dev/null +++ b/generator/debug.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +#Install Python +#sudo apt install python-minimal + +#Install pip +#sudo apt install python-pip + +#Install pyyaml +#sudo pip install pyyaml + +./deploy.sh simple rgName$(date +%Y%m%d) \ No newline at end of file diff --git a/generator/deploy.sh b/generator/deploy.sh index 3b5abbf..97a1dec 100755 --- a/generator/deploy.sh +++ b/generator/deploy.sh @@ -7,4 +7,5 @@ RESOURCE_GROUP=$2 python deployment.py parameters/${PARAMETERS_FILE}.yaml az group create --name $RESOURCE_GROUP --location westus --output table +#az group deployment validate --template-file generatedTemplate.json --resource-group $RESOURCE_GROUP az group deployment create --verbose --template-file generatedTemplate.json --resource-group $RESOURCE_GROUP --output table diff --git a/generator/deployment.py b/generator/deployment.py index 7c04689..04af740 100644 --- a/generator/deployment.py +++ b/generator/deployment.py @@ -14,6 +14,8 @@ def main(): license = parameters['license'] username = parameters['username'] password = parameters['password'] + serverVersion = parameters['serverVersion'] + syncGatewayVersion = parameters['syncGatewayVersion'] template={ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", @@ -28,13 +30,13 @@ def main(): } for cluster in parameters['clusters']: - template['resources']+=generateCluster(license, username, password, cluster) + template['resources']+=generateCluster(license, username, password, serverVersion, syncGatewayVersion, cluster) file = open('generatedTemplate.json', 'w') file.write(json.dumps(template, sort_keys=True, indent=4, separators=(',', ': ')) + '\n') file.close() -def generateCluster(license, username, password, cluster): +def generateCluster(license, username, password, serverVersion, syncGatewayVersion, cluster): resources = [] clusterName = cluster['cluster'] region = cluster['region'] @@ -42,7 +44,7 @@ def generateCluster(license, username, password, cluster): resources.append(generateNetworkSecurityGroups(clusterName, region)) resources.append(generateVirtualNetwork(clusterName, region)) for group in cluster['groups']: - resources+=generateGroup(license, username, password, clusterName, region, group) + resources+=generateGroup(license, username, password, clusterName, region, group, serverVersion, syncGatewayVersion) return resources @@ -213,7 +215,7 @@ def generateVirtualNetwork(clusterName, region): } return virtualNetwork -def generateGroup(license, username, password, clusterName, region, group): +def generateGroup(license, username, password, clusterName, region, group, serverVersion, syncGatewayVersion): groupName = group['group'] nodeCount = group['nodeCount'] nodeType = group['nodeType'] @@ -221,28 +223,29 @@ def generateGroup(license, username, password, clusterName, region, group): services = group['services'] resources=[] - resources.append(generateServer(region)) - resources.append(generateSyncGateway(region)) + resources.append(generateServer(clusterName, region, license, serverVersion, username, password, diskSize, nodeCount, nodeType)) + resources.append(generateSyncGateway(clusterName, region, license, username, password, nodeCount, nodeType, syncGatewayVersion)) #Probably needs to be moved to the cluster level + return resources -def generateServer(): +def generateServer(clusterName, region, license, serverVersion, username, password, diskSize, nodeCount, nodeType): server={ "type": "Microsoft.Compute/virtualMachineScaleSets", "name": "server", "location": region, "apiVersion": "2017-03-30", "dependsOn": [ - "Microsoft.Network/virtualNetworks/vnet" + "Microsoft.Network/virtualNetworks/" + clusterName ], "plan": { "publisher": "couchbase", "product": "couchbase-server-enterprise", - "name": "[parameters('license')]" + "name": license }, "sku": { - "name": "[parameters('vmSize')]", + "name": nodeType, "tier": "Standard", - "capacity": "[parameters('serverNodeCount')]" + "capacity": nodeCount }, "properties": { "overprovision": False, @@ -257,7 +260,7 @@ def generateServer(): "imageReference": { "publisher": "couchbase", "offer": "couchbase-server-enterprise", - "sku": "[parameters('license')]", + "sku": license, "version": "latest" }, "dataDisks": [ @@ -268,14 +271,14 @@ def generateServer(): "storageAccountType": "Premium_LRS" }, "caching": "None", - "diskSizeGB": "[parameters('serverDiskSize')]" + "diskSizeGB": diskSize } ] }, "osProfile": { "computerNamePrefix": "server", - "adminUsername": "[parameters('adminUsername')]", - "adminPassword": "[parameters('adminPassword')]" + "adminUsername": username, + "adminPassword": password }, "networkProfile": { "networkInterfaceConfigurations": [ @@ -288,7 +291,7 @@ def generateServer(): "name": "ipconfig", "properties": { "subnet": { - "id": "[concat(resourceId('Microsoft.Network/virtualNetworks/', 'vnet'), '/subnets/subnet')]" + "id": "[concat(resourceId('Microsoft.Network/virtualNetworks/', '{0}'), '/subnets/subnet')]".format(clusterName) }, "publicipaddressconfiguration": { "name": "public", @@ -320,7 +323,7 @@ def generateServer(): "[concat(variables('extensionUrl'), 'server.sh')]", "[concat(variables('extensionUrl'), 'util.sh')]" ], - "commandToExecute": "[concat('bash server.sh ', parameters('serverVersion'), ' ', parameters('adminUsername'), ' ', parameters('adminPassword'), ' ', variables('uniqueString'), ' ', parameters('location'))]" + "commandToExecute": "[concat('bash server.sh ', '{1}', ' ', '{2}', ' ', '{3}', ' ', variables('uniqueString'), ' ', '{0}')]".format(region, serverVersion, username, password) } } } @@ -331,24 +334,24 @@ def generateServer(): } return server -def generateSyncGateway(): +def generateSyncGateway(clusterName, region, license, username, password, nodeCount, nodeType, syncGatewayVersion): syncGateway={ "type": "Microsoft.Compute/virtualMachineScaleSets", "name": "syncgateway", - "location": "[parameters('location')]", + "location": region, "apiVersion": "2017-03-30", "dependsOn": [ - "Microsoft.Network/virtualNetworks/vnet" + "Microsoft.Network/virtualNetworks/" + clusterName ], "plan": { "publisher": "couchbase", "product": "couchbase-sync-gateway-enterprise", - "name": "[parameters('license')]" + "name": license }, "sku": { - "name": "[parameters('vmSize')]", + "name": nodeType, "tier": "Standard", - "capacity": "[parameters('syncGatewayNodeCount')]" + "capacity": nodeCount }, "properties": { "overprovision": False, @@ -363,14 +366,14 @@ def generateSyncGateway(): "imageReference": { "publisher": "couchbase", "offer": "couchbase-sync-gateway-enterprise", - "sku": "[parameters('license')]", + "sku": license, "version": "latest" } }, "osProfile": { "computerNamePrefix": "syncgateway", - "adminUsername": "[parameters('adminUsername')]", - "adminPassword": "[parameters('adminPassword')]" + "adminUsername": username, + "adminPassword": password }, "networkProfile": { "networkInterfaceConfigurations": [ @@ -383,7 +386,7 @@ def generateSyncGateway(): "name": "ipconfig", "properties": { "subnet": { - "id": "[concat(resourceId('Microsoft.Network/virtualNetworks/', 'vnet'), '/subnets/subnet')]" + "id": "[concat(resourceId('Microsoft.Network/virtualNetworks/', '{0}'), '/subnets/subnet')]".format(clusterName) }, "publicipaddressconfiguration": { "name": "public", @@ -415,7 +418,7 @@ def generateSyncGateway(): "[concat(variables('extensionUrl'), 'syncGateway.sh')]", "[concat(variables('extensionUrl'), 'util.sh')]" ], - "commandToExecute": "[concat('bash syncGateway.sh ', parameters('syncGatewayVersion'))]" + "commandToExecute": "[concat('bash syncGateway.sh ', '{0}')]".format(syncGatewayVersion) } } } @@ -445,4 +448,4 @@ def generateOutputs(clusters): return outputs -main() +main() \ No newline at end of file diff --git a/generator/parameters/simple.yaml b/generator/parameters/simple.yaml index fa5ca0a..bc38f9d 100644 --- a/generator/parameters/simple.yaml +++ b/generator/parameters/simple.yaml @@ -1,4 +1,4 @@ -license: hourly_pricing +license: byol username: couchbase password: foo123! serverVersion: 5.1.0