Example #1
0
        private void doDeploy(string subscriptionID, AzureOAuth2Token token, string id, AzureTemplate template, IConfigSectionNode customData)
        {
            var nicName = id;

            var networkClient = new NetworkClient(this, DEFAULT_RESOURCE, subscriptionID, token);

            string           securityGroup    = null;
            NetworkInterface networkInterface = null;
            List <NetworkInterfaceIPConfiguration> ipConfigurations = null;
            List <NetworkInterface> networkInterfaces = null;

            foreach (var ni in template.NetworkInterfaces.OrderBy(ni => ni.SecurityGroup))
            {
                if (networkInterfaces == null)
                {
                    networkInterfaces = new List <NetworkInterface>();
                }
                var subnet   = networkClient.GetSubnet(template.Group, ni.VNet, ni.Subnet);
                var publicIP = ni.PublicIP.IsNotNullOrWhiteSpace() ? networkClient.GetPublicIPAddress(template.Group, ni.PublicIP) : null;

                if (securityGroup != ni.SecurityGroup)
                {
                    securityGroup = ni.SecurityGroup;
                    if (networkInterface != null)
                    {
                        networkInterfaces.Add(networkClient.CreateOrUpdateNetworkInterface(template.Group, nicName, networkInterface));
                    }
                    networkInterface = null;
                }

                if (networkInterface == null)
                {
                    var nsg = ni.SecurityGroup.IsNotNullOrWhiteSpace() ? networkClient.GetNetworkSecurityGroup(template.Group, ni.SecurityGroup) : null;

                    ipConfigurations = new List <NetworkInterfaceIPConfiguration>();

                    networkInterface = new NetworkInterface
                    {
                        Location   = template.Location,
                        Properties = new NetworkInterfacePropertiesFormat
                        {
                            IPConfigurations     = ipConfigurations,
                            NetworkSecurityGroup = nsg
                        }
                    };
                }

                ipConfigurations.Add(new NetworkInterfaceIPConfiguration
                {
                    Properties = new NetworkInterfaceIPConfigurationPropertiesFormat
                    {
                        Subnet          = subnet,
                        PublicIPAddress = publicIP
                    }
                });
            }

            if (networkInterface != null)
            {
                networkInterfaces.Add(networkClient.CreateOrUpdateNetworkInterface(template.Group, nicName, networkInterface));
            }

            var computeClient = new ComputeClient(this, subscriptionID, token);

            computeClient.CreateOrUpdateVirtualMachine(template.Group, id, new VirtualMachine
            {
                Location   = template.Location,
                Properties = new VirtualMachinePropertiesFormat
                {
                    hardwareProfile = new HardwareProfile {
                        vmSize = template.HardwareProfile
                    },
                    storageProfile = new StorageProfile
                    {
                        osDisk = new OSDisk
                        {
                            osType       = OperatingSystemTypes.Windows,
                            name         = id + ".SYSTEM",
                            createOption = DiskCreateOptionTypes.fromImage,
                            image        = new VirtualHardDisk {
                                uri = template.ImageUri
                            },
                            vhd = new VirtualHardDisk {
                                uri = template.OSDiskUri.Args(id + ".SYSTEM")
                            },
                            caching = CachingTypes.ReadWrite
                        }
                    },
                    osProfile = new OSProfile
                    {
                        computerName  = id,
                        adminUserName = template.AdminUsername,
                        adminPassword = template.AdminPassword
                    },
                    networkProfile = new NetworkProfile
                    {
                        networkInterfaces = networkInterfaces.Select(ni => new NetworkInterfaceReference(ni)).ToList()
                    }
                }
            });

            throw new NotImplementedException();
        }