Elastacloud.AzureManagement.Fluent.Types.VirtualMachines.StatefulVirtualMachineSerialiser.GetVmRoles C# (CSharp) Method

GetVmRoles() public method

Gets a VM role for Windows which
public GetVmRoles ( ) : List
return List
        public override List<PersistentVMRole> GetVmRoles()
        {
            var listVm = new List<PersistentVMRole>();
            // get all of the root properties
            var roots = _document.Descendants(Namespace + "RoleList").Elements(Namespace + "Role");
            // get the virtual network name if it exists
            var network = _document.Element(Namespace + "Deployment").Element(Namespace + "VirtualNetworkName");
            string virtualNetwork = null;
            if (network != null)
            {
                virtualNetwork = network.Value;
            }
            foreach (var root in roots)
            {
                var persistentVirtualMachine = new PersistentVMRole();

                if (root.Attribute(TypeNamespace + "type").Value != "PersistentVMRole")
                    throw new ApplicationException("non persistent vm role detected");

                persistentVirtualMachine.AvailabilityNameSet =
                    GetStringValue(root.Element(Namespace + "AvailabilitySetName"));
                persistentVirtualMachine.VirtualNetworkName = virtualNetwork;

                persistentVirtualMachine.RoleSize = GetEnumValue<VmSize>(root.Element(Namespace + "RoleSize"));
                persistentVirtualMachine.RoleName = GetStringValue(root.Element(Namespace + "RoleName"));
                // get the roleinstance from the list
                var roleInstance = _document.Descendants(Namespace + "RoleInstanceList").Elements(Namespace + "RoleInstance").FirstOrDefault(
                    a => a.Element(Namespace + "RoleName").Value == persistentVirtualMachine.RoleName);
                // add the ip address
                persistentVirtualMachine.IPAddress = GetStringValue(roleInstance.Element(Namespace + "IpAddress"));
                persistentVirtualMachine.Status = GetEnumValue<RoleInstanceStatus>(roleInstance.Element(Namespace + "InstanceStatus"));
                // get the networkconfiguration
                var configurationSets = root.Descendants(Namespace + "ConfigurationSet");
                foreach (var configurationSet in configurationSets)
                {
                    persistentVirtualMachine.NetworkConfigurationSet = GetNetworkConfigurationSet(configurationSet);
                }
                // get the hard disk
                var hardDisks = root.Element(Namespace + "DataVirtualHardDisks");
                persistentVirtualMachine.HardDisks = new DataVirtualHardDisks()
                    {
                        HardDiskCollection = GetHardDisks(hardDisks)
                    };
                var osDisk = GetOSHardDisk(root.Element(Namespace + "OSVirtualHardDisk"));
                persistentVirtualMachine.OSHardDisk = osDisk;
                // check and add linux as an OS
                if (osDisk.OS.ToLower() == "linux")
                {
                    persistentVirtualMachine.OperatingSystemConfigurationSet = new LinuxConfigurationSet() { HostName = GetStringValue(roleInstance.Element(Namespace + "HostName")) };
                }

                listVm.Add(persistentVirtualMachine);
            }

            return listVm;
        }

Usage Example

 /// <summary>
 /// Used to bring back and parse the context response for a virtual machine
 /// </summary>
 /// <param name="webResponse">the Http web response</param>
 protected override void ResponseCallback(HttpWebResponse webResponse)
 {
     XDocument vmDocument;
     using (var reader = new StreamReader(webResponse.GetResponseStream()))
     {
         vmDocument = XDocument.Parse(reader.ReadToEnd());
     }
     var virtualMachine = new StatefulVirtualMachineSerialiser(vmDocument);
     // issue occurring here which is not bubbling up the exception
     try
     {
         PersistentVm = virtualMachine.GetVmRoles();
     }
     catch (Exception ex)
     {
         ResponseStackTrace = ex.ToString();
     }
     SitAndWait.Set();
 }
All Usage Examples Of Elastacloud.AzureManagement.Fluent.Types.VirtualMachines.StatefulVirtualMachineSerialiser::GetVmRoles