public VirtualMachine(AzureContext azureContext, CloudService asmCloudService, ISettingsProvider settingsProvider, XmlNode virtualMachineXml, Hashtable vmDetails) { this._AsmCloudService = asmCloudService; this._AzureContext = azureContext; this._XmlNode = virtualMachineXml; this._VmDetails = vmDetails; this.TargetName = this.RoleName; this._PrimaryNetworkInterface = new NetworkInterface(azureContext, this, settingsProvider, null); _OSVirtualHardDisk = new Disk(azureContext, _XmlNode.SelectSingleNode("//OSVirtualHardDisk")); _DataDisks = new List <Disk>(); foreach (XmlNode dataDiskNode in _XmlNode.SelectNodes("//DataVirtualHardDisks/DataVirtualHardDisk")) { Disk asmDisk = new Disk(azureContext, dataDiskNode); _DataDisks.Add(asmDisk); } _LoadBalancerRules = new List <LoadBalancerRule>(); foreach (XmlNode loadBalancerRuleNode in _XmlNode.SelectNodes("//ConfigurationSets/ConfigurationSet/InputEndpoints/InputEndpoint")) { _LoadBalancerRules.Add(new LoadBalancerRule(_AzureContext, loadBalancerRuleNode)); } _NetworkInterfaces = new List <NetworkInterface>(); foreach (XmlNode networkInterfaceNode in _XmlNode.SelectNodes("//ConfigurationSets/ConfigurationSet/NetworkInterfaces/NetworkInterface")) { _NetworkInterfaces.Add(new NetworkInterface(_AzureContext, this, settingsProvider, networkInterfaceNode)); } }
public VirtualMachine(AzureContext azureContext, CloudService asmCloudService, ISettingsProvider settingsProvider, XmlNode virtualMachineXml, Hashtable vmDetails) { this._AsmCloudService = asmCloudService; this._AzureContext = azureContext; this._XmlNode = virtualMachineXml; this._VmDetails = vmDetails; _OSVirtualHardDisk = new Disk(azureContext, _XmlNode.SelectSingleNode("//OSVirtualHardDisk")); _DataDisks = new List <Disk>(); foreach (XmlNode dataDiskNode in _XmlNode.SelectNodes("//DataVirtualHardDisks/DataVirtualHardDisk")) { Disk asmDisk = new Disk(azureContext, dataDiskNode); _DataDisks.Add(asmDisk); } foreach (XmlNode loadBalancerRuleNode in _XmlNode.SelectNodes("//ConfigurationSets/ConfigurationSet/InputEndpoints/InputEndpoint")) { _LoadBalancerRules.Add(new LoadBalancerRule(_AzureContext, loadBalancerRuleNode)); } #region Primary Network Interface NetworkInterface primaryNetworkInterface = new NetworkInterface(_AzureContext, this); this.NetworkInterfaces.Add(primaryNetworkInterface); primaryNetworkInterface.IsPrimary = true; primaryNetworkInterface.Name = this.RoleName + "-NIC1"; NetworkInterfaceIpConfiguration primaryNetworkInterfaceIpConfiguration = new NetworkInterfaceIpConfiguration(_AzureContext); primaryNetworkInterface.NetworkInterfaceIpConfigurations.Add(primaryNetworkInterfaceIpConfiguration); primaryNetworkInterfaceIpConfiguration.VirtualNetworkName = vmDetails["virtualnetworkname"].ToString(); // code note, unclear why this is index [1] on the ConfigurationSet ... couldn't it be a different order? if (_XmlNode.SelectSingleNode("//ConfigurationSets/ConfigurationSet[1]/SubnetNames/SubnetName") != null) { primaryNetworkInterfaceIpConfiguration.SubnetName = _XmlNode.SelectSingleNode("//ConfigurationSets/ConfigurationSet[1]/SubnetNames/SubnetName").InnerText; } if (_XmlNode.SelectSingleNode("//ConfigurationSets/ConfigurationSet[1]/StaticVirtualNetworkIPAddress") != null) { primaryNetworkInterfaceIpConfiguration.PrivateIpAllocationMethod = "Static"; primaryNetworkInterfaceIpConfiguration.PrivateIpAddress = _XmlNode.SelectSingleNode("//ConfigurationSets/ConfigurationSet[1]/StaticVirtualNetworkIPAddress").InnerText; } if (_XmlNode.SelectSingleNode("//ConfigurationSets/ConfigurationSet[1]/NetworkSecurityGroup") != null) { _NetworkSecurityGroupName = _XmlNode.SelectSingleNode("//ConfigurationSets/ConfigurationSet[1]/NetworkSecurityGroup").InnerText; } #endregion #region Additional Network Interfaces foreach (XmlNode additionalNetworkInterfaceXml in _XmlNode.SelectNodes("//ConfigurationSets/ConfigurationSet/NetworkInterfaces/NetworkInterface")) { NetworkInterface additionalNetworkInterface = new NetworkInterface(_AzureContext, this); this.NetworkInterfaces.Add(additionalNetworkInterface); additionalNetworkInterface.Name = this.RoleName + "-" + additionalNetworkInterfaceXml.SelectSingleNode("Name").InnerText; if (additionalNetworkInterfaceXml.SelectNodes("IPForwarding").Count > 0) { additionalNetworkInterface.EnableIpForwarding = true; } NetworkInterfaceIpConfiguration ipConfiguration = new NetworkInterfaceIpConfiguration(_AzureContext); additionalNetworkInterface.NetworkInterfaceIpConfigurations.Add(ipConfiguration); ipConfiguration.Name = "ipconfig1"; ipConfiguration.VirtualNetworkName = vmDetails["virtualnetworkname"].ToString(); if (_XmlNode.SelectSingleNode("IPConfigurations/IPConfiguration/SubnetName") != null) { ipConfiguration.SubnetName = additionalNetworkInterfaceXml.SelectSingleNode("IPConfigurations/IPConfiguration/SubnetName").InnerText; } if (additionalNetworkInterfaceXml.SelectSingleNode("IPConfigurations/IPConfiguration/StaticVirtualNetworkIPAddress") != null) { ipConfiguration.PrivateIpAllocationMethod = "Static"; ipConfiguration.PrivateIpAddress = additionalNetworkInterfaceXml.SelectSingleNode("IPConfigurations/IPConfiguration/StaticVirtualNetworkIPAddress").InnerText; } } #endregion }