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;
}