Esempio n. 1
0
        private static void ValidateDisks(RASD_Type rasd, File_Type[] files, VirtualDiskDesc_Type[] disks,
                                          ref List <File_Type> linkedFiles, ref List <string> warnings)
        {
            log.Info("Validating disks");

            VirtualDiskDesc_Type disk;

            if (rasd.HostResource != null && rasd.HostResource.Length > 0)
            {
                disk = disks.FirstOrDefault(d => rasd.HostResource[0].Value.Contains(d.diskId));
            }
            else
            {
                disk = disks.FirstOrDefault(d => rasd.InstanceID.Value == d.diskId);
            }

            File_Type file = null;

            if (disk != null)
            {
                file = files.FirstOrDefault(f => f.id == disk.fileRef);
            }

            if (file != null && !linkedFiles.Contains(file))
            {
                linkedFiles.Add(file);
            }
        }
Esempio n. 2
0
        private static void ValidateNetworks(RASD_Type rasd, NetworkSection_TypeNetwork[] networks, ref List <string> warnings)
        {
            log.Info("Validating Networks");

            if (rasd.InstanceID == null || rasd.InstanceID.Value.Length <= 0)
            {
                log.Info("Network has an invalid InstanceID, creating a new one.");
                warnings.Add(Messages.VALIDATION_INVALID_INSTANCEID);
                rasd.InstanceID = new cimString(Guid.NewGuid().ToString());
                return;
            }

            bool linkage = false;

            foreach (NetworkSection_TypeNetwork net in networks)
            {
                // TODO: this may only work for Citrix created VIFs; for others we may need to use a different key to validate linkage.

                if (rasd.Connection != null && rasd.Connection.Length > 0 && net.name == rasd.Connection[0].Value ||
                    net.Description.msgid == rasd.InstanceID.Value)
                {
                    linkage = true;
                }
            }

            if (!linkage)
            {
                log.Error(Messages.VALIDATION_NETWORK_NO_DEVICE);
                warnings.Add(Messages.VALIDATION_NETWORK_NO_DEVICE);
            }
        }
Esempio n. 3
0
        public VirtualDisk(long diskSize, BusType busType, BusSubType busSubType)
            : base(new RASD_Type())
        {
            cimString           cimString1       = new cimString();
            List <XmlAttribute> xmlAttributeList = new List <XmlAttribute>();
            XmlDocument         xmlDocument      = new XmlDocument();

            if (busType.Value().Equals(BusType.IDE.Value()))
            {
                XmlAttribute attribute = xmlDocument.CreateAttribute("vcloud", nameof(busType), "http://www.vmware.com/vcloud/v1.5");
                attribute.Value = "5";
                xmlAttributeList.Add(attribute);
            }
            else
            {
                XmlAttribute attribute1 = xmlDocument.CreateAttribute("vcloud", nameof(busSubType), "http://www.vmware.com/vcloud/v1.5");
                attribute1.Value = busSubType.Value();
                XmlAttribute attribute2 = xmlDocument.CreateAttribute("vcloud", nameof(busType), "http://www.vmware.com/vcloud/v1.5");
                attribute2.Value = "6";
                xmlAttributeList.Add(attribute1);
                xmlAttributeList.Add(attribute2);
            }
            XmlAttribute attribute3 = xmlDocument.CreateAttribute("vcloud", "capacity", "http://www.vmware.com/vcloud/v1.5");

            attribute3.Value = diskSize.ToString();
            xmlAttributeList.Add(attribute3);
            if (cimString1.AnyAttr == null)
            {
                cimString1.AnyAttr = xmlAttributeList.ToArray();
            }
            else
            {
                List <XmlAttribute> list = ((IEnumerable <XmlAttribute>)cimString1.AnyAttr).ToList <XmlAttribute>();
                list.AddRange((IEnumerable <XmlAttribute>)xmlAttributeList);
                cimString1.AnyAttr = list.ToArray();
            }
            cimString cimString2 = new cimString();

            cimString2.Value = "";
            cimString cimString3 = new cimString();

            cimString3.Value = "";
            ResourceType1 resourceType1 = new ResourceType1();

            resourceType1.Value = "17";
            RASD_Type itemResource = this.GetItemResource();

            itemResource.ElementName  = cimString2;
            itemResource.InstanceID   = cimString3;
            itemResource.ResourceType = resourceType1;
            itemResource.HostResource = new cimString[1]
            {
                cimString1
            };
        }
Esempio n. 4
0
        private static void ValidateCapability(RASD_Type rasd, ref List <string> warnings)
        {
            log.Info("Validating Capabilities");

            switch (rasd.ResourceType.Value)
            {
            // CIM SCHEMA 2.19.0
            case 3:      // Processor
            case 4:      // Memory
            case 5:      // IDE Controller
            case 6:      // Parallel SCSI HBA
            case 7:      // FC HBA
            case 8:      // iSCSI HBA
            case 9:      // IB HCA
            case 10:     // Ethernet Adapter
            case 15:     // CD Drive
            case 16:     // DVD Drive
            case 17:     // Disk Drive
            case 19:     // Storage Extent
            case 20:     // Other storage Device
            case 21:     // Serial Port  // Microsoft uses this for Hard Disk Image also, based on an OLDER schema
                break;

            case 1:      // Other
            case 2:      // Computer System
            case 11:     // Other Network Adapter
            case 12:     // I/O Slot
            case 13:     // I/O Device
            case 14:     // Floppy Drive
            case 18:     // Tape Drive
            case 22:     // Parallel Port
            case 23:     // USB Controller
            case 24:     // Graphics Controller
            case 25:     // IEEE 1394 Controller
            case 26:     // Partitionable Unit
            case 27:     // Base Partitionable Unit
            case 28:     // Power
            case 29:     // Cooling Capacity
            case 30:     // Ethernet Switch Port
            case 31:     // Logical Disk
            case 32:     // Storage Volume
            case 33:     // Ethernet Connection
            default:
                if (rasd.required)
                {
                    var message = string.Format(Messages.VALIDATION_REQUIRED_ELEMENT_NOT_RECOGNIZED, rasd.ResourceType.Value, rasd.ElementName.Value);
                    log.Error(message);
                    warnings.Add(message);
                }
                break;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// An ovf can contain both encrypted and non-encrypted file mixed together.
        /// find if file name is encrypted.
        /// 1. check the References for the security ID
        /// 2. check the Security id section exists.
        /// </summary>
        /// <param name="ovfObj">OVF Envelope</param>
        /// <param name="filename">filename to check</param>
        /// <returns>true = encrypted; false = not encrypted</returns>
        public static bool IsThisEncrypted(EnvelopeType ovfObj, RASD_Type rasd)
        {
            bool _isEncrypted = false;

            // 15,16,17,19,20 are attached files.
            // rest is RASD specific

            switch (rasd.ResourceType.Value)
            {
            case 15:
            case 16:
            case 17:
            case 19:
            case 20:
            {
                File_Type file = FindFileReferenceByRASD(ovfObj, rasd);
                if (file != null)
                {
                    if (!string.IsNullOrEmpty(file.Id))
                    {
                        _isEncrypted = IsThisIdEncrypted(ovfObj, file.Id);
                    }
                }
                break;
            }

            default:
            {
                // currently encrypted RASD or Elements, isn't being done, but this can check it.
                if (rasd.AnyAttr != null && rasd.AnyAttr.Length > 0)
                {
                    foreach (XmlAttribute xa in rasd.AnyAttr)
                    {
                        if (xa.Name.ToLower().Equals("xenc:id"))
                        {
                            _isEncrypted = IsThisIdEncrypted(ovfObj, xa.Value);
                            break;
                        }
                    }
                }
                break;
            }
            }
            return(_isEncrypted);
        }
Esempio n. 6
0
        private static void ValidateMemory(RASD_Type rasd, ref List <string> warnings)
        {
            log.Info("Validating Memory");

            if (rasd.VirtualQuantity == null || rasd.VirtualQuantity.Value <= 0)
            {
                log.Warn("Memory invalid Virtual Quantity");
                warnings.Add(Messages.VALIDATION_INVALID_MEMORY_QUANTITY);
            }
            else if (rasd.AllocationUnits == null || rasd.AllocationUnits.Value.Length <= 0)
            {
                log.Warn("Memory AllocationUnits not valid");
                warnings.Add(Messages.VALIDATION_INVALID_MEMORY_ALLOCATIONUNITS);
            }
            else if (rasd.InstanceID == null || rasd.InstanceID.Value.Length <= 0)
            {
                log.Info("Memory has an invalid InstanceID, creating a new one.");
                warnings.Add(Messages.VALIDATION_INVALID_INSTANCEID);
                rasd.InstanceID = new cimString(Guid.NewGuid().ToString());//ovf is valid
            }
        }
Esempio n. 7
0
        private static void ValidateCpu(RASD_Type rasd, ref List <string> warnings)
        {
            log.Info("Validating CPU");

            if (rasd.VirtualQuantity == null || rasd.VirtualQuantity.Value <= 0)
            {
                log.Warn("CPU invalid Virtual Quantity");
                warnings.Add(Messages.VALIDATION_CPU_INVALID_QUANTITY);
            }
            else if (rasd.Limit != null && rasd.VirtualQuantity.Value > rasd.Limit.Value)
            {
                log.WarnFormat("Processor quantity {0} exceeds the limit of {1}.", rasd.VirtualQuantity.Value, rasd.Limit.Value);
                warnings.Add(string.Format(Messages.VALIDATION_CPU_EXCEEDS_LIMIT, rasd.VirtualQuantity.Value, rasd.Limit.Value));
            }
            else if (rasd.InstanceID == null || rasd.InstanceID.Value.Length <= 0)
            {
                log.Info("CPU has an invalid InstanceID, creating a new one.");
                warnings.Add(Messages.VALIDATION_INVALID_INSTANCEID);//ovf is valid
                rasd.InstanceID = new cimString(Guid.NewGuid().ToString());
            }
        }
Esempio n. 8
0
 public VirtualDisk(RASD_Type virtualDiskItem)
     : base(virtualDiskItem)
 {
 }
Esempio n. 9
0
 internal HardwareItem(RASD_Type virtualCpuItem)
 {
     this._itemResource = virtualCpuItem;
 }
Esempio n. 10
0
 public OvfStorageResource(RASD_Type type, EnvelopeType envelopeType)
 {
     rasd     = type;
     envelope = envelopeType;
     file     = OVF.FindFileReferenceByRASD(envelope, rasd);
 }
Esempio n. 11
0
 public OvfNetworkResource(RASD_Type rasdType)
 {
     rasd = rasdType;
 }
Esempio n. 12
0
 private SerialPort(RASD_Type serialPortItem)
     : base(serialPortItem)
 {
 }
Esempio n. 13
0
 public VirtualNetworkCard(RASD_Type virtualNetworkCardItem)
     : base(virtualNetworkCardItem)
 {
 }
Esempio n. 14
0
        private void Init(
            int nicId,
            bool isConnected,
            string networkName,
            bool isPrimaryNetworkConnection,
            IpAddressAllocationModeType ipAddressingMode,
            string ipAddress,
            NetworkAdapterType adapterType)
        {
            cimString cimString1 = new cimString();

            cimString1.Value = networkName;
            List <XmlAttribute> xmlAttributeList = new List <XmlAttribute>();
            XmlDocument         xmlDocument      = new XmlDocument();
            XmlAttribute        attribute1       = xmlDocument.CreateAttribute("vcloud", nameof(ipAddress), "http://www.vmware.com/vcloud/v1.5");

            attribute1.Value = ipAddress;
            XmlAttribute attribute2 = xmlDocument.CreateAttribute("vcloud", "primaryNetworkConnection", "http://www.vmware.com/vcloud/v1.5");

            attribute2.Value = isPrimaryNetworkConnection.ToString();
            XmlAttribute attribute3 = xmlDocument.CreateAttribute("vcloud", nameof(ipAddressingMode), "http://www.vmware.com/vcloud/v1.5");

            attribute3.Value = ipAddressingMode.Value();
            xmlAttributeList.Add(attribute1);
            xmlAttributeList.Add(attribute2);
            xmlAttributeList.Add(attribute3);
            if (cimString1.AnyAttr == null)
            {
                cimString1.AnyAttr = xmlAttributeList.ToArray();
            }
            else
            {
                List <XmlAttribute> list = ((IEnumerable <XmlAttribute>)cimString1.AnyAttr).ToList <XmlAttribute>();
                list.AddRange((IEnumerable <XmlAttribute>)xmlAttributeList);
                cimString1.AnyAttr = list.ToArray();
            }
            cimString cimString2 = new cimString();

            cimString2.Value = "";
            cimString cimString3 = new cimString();

            cimString3.Value = "";
            cimString cimString4 = new cimString();

            cimString4.Value = nicId.ToString();
            cimBoolean cimBoolean = new cimBoolean();

            cimBoolean.Value = isConnected;
            ResourceType1 resourceType1 = new ResourceType1();

            resourceType1.Value = "10";
            cimString cimString5 = new cimString();

            cimString5.Value = adapterType.Value();
            RASD_Type itemResource = this.GetItemResource();

            itemResource.ElementName         = cimString2;
            itemResource.InstanceID          = cimString3;
            itemResource.ResourceType        = resourceType1;
            itemResource.ResourceSubType     = cimString5;
            itemResource.AddressOnParent     = cimString4;
            itemResource.AutomaticAllocation = cimBoolean;
            itemResource.Connection          = new cimString[1]
            {
                cimString1
            };
        }
Esempio n. 15
0
        public DiskElements CreateDiskModels(IList <Disk> diskModels)
        {
            var diskFiles  = new List <File_Type>();
            var disks      = new List <VirtualDiskDesc_Type>();
            var diskDrives = new List <RASD_Type>();

            int ideDiskCount  = 0;
            int scsiDiskCount = 0;

            for (var i = 0; i < diskModels.Count; i++)
            {
                var diskModel = diskModels[i];
                var diskFile  = new File_Type {
                    href = diskModel.Path, id = "diskFile" + i, sizeSpecified = true, size = diskModel.FileSize
                };
                var disk = new VirtualDiskDesc_Type
                {
                    fileRef  = diskFile.id,
                    diskId   = "diskId" + i,
                    capacity = diskModels[i].CapacityMb.ToString(),
                    format   = formatStringLookup[diskModels[i].Format],
                    capacityAllocationUnits = "byte * 2^20"
                };

                string parent;
                int    addressOnParent;
                if (diskModel.ControllerType == ControllerType.IDE)
                {
                    parent          = "ide" + ideDiskCount / 2;
                    addressOnParent = ideDiskCount % 2;
                    ideDiskCount++;
                }
                else
                {
                    parent          = "scsi0";
                    addressOnParent = scsiDiskCount;
                    scsiDiskCount++;
                }

                var diskDrive = new RASD_Type
                {
                    AddressOnParent = new cimString {
                        Value = addressOnParent.ToString()
                    },
                    AutomaticAllocation = new cimBoolean {
                        Value = false
                    },
                    AutomaticDeallocation = new cimBoolean {
                        Value = false
                    },
                    InstanceID = new cimString {
                        Value = disk.diskId
                    },
                    ElementName = new cimString {
                        Value = "Disk " + disk.diskId
                    },
                    ResourceType = new ResourceType {
                        Value = "17"
                    },
                    HostResource = new[] { new cimString {
                                               Value = "ovf:/disk/" + disk.diskId
                                           } },
                    Parent = new cimString {
                        Value = parent
                    }
                };

                diskFiles.Add(diskFile);
                disks.Add(disk);
                diskDrives.Add(diskDrive);
            }

            return(new DiskElements(diskFiles, disks, diskDrives));
        }
Esempio n. 16
0
 internal VirtualMedia(RASD_Type virtualMediaItem)
     : base(virtualMediaItem)
 {
 }
Esempio n. 17
0
 internal VirtualCpu(RASD_Type virtualCPUItem)
     : base(virtualCPUItem)
 {
 }
Esempio n. 18
0
 internal VirtualMemory(RASD_Type virtualMemoryItem)
     : base(virtualMemoryItem)
 {
 }