コード例 #1
0
        private void getVMs(ManagedObjectReference hmor, String canName)
        {
            DynamicProperty[]        dsArr         = getDynamicProarray(hmor, "datastore");
            ManagedObjectReference[] dataStoresMOR =
                ((ManagedObjectReference[])(dsArr[0]).val);
            //ManagedObjectReference[] dataStoresMOR = ds.managedObjectReference;
            Boolean vmfsFlag = false;

            try{
                for (int j = 0; j < dataStoresMOR.Length; j++)
                {
                    DynamicProperty[] infoArr   = getDynamicProarray(dataStoresMOR[j], "info");
                    String            infoClass = infoArr[0].val.GetType().ToString();
                    if (infoClass.Equals("VimApi.VmfsDatastoreInfo"))
                    {
                        VmfsDatastoreInfo       vds      = (VmfsDatastoreInfo)(infoArr[0]).val;
                        HostVmfsVolume          hvms     = vds.vmfs;
                        String                  vmfsName = vds.name;
                        HostScsiDiskPartition[] hdp      = hvms.extent;
                        for (int k = 0; k < hdp.Length; k++)
                        {
                            if (hdp[k].diskName.Equals(canName))
                            {
                                DynamicProperty[] vmArr
                                    = getDynamicProarray(dataStoresMOR[j], "vm");
                                ManagedObjectReference[] vmsMOR =
                                    ((ManagedObjectReference[])(vmArr[0]).val);
                                //   ManagedObjectReference[] vmsMOR = vms.managedObjectReference;

                                if (vmsMOR != null)
                                {
                                    for (int l = 0; l < vmsMOR.Length; l++)
                                    {
                                        vmfsFlag = true;
                                        DynamicProperty[] nameArr =
                                            getDynamicProarray(vmsMOR[l], "name");
                                        String vmname = nameArr[0].val.ToString();
                                        Console.WriteLine(" " + vmname);
                                    }
                                }
                            }
                        }
                    }
                }
                if (!vmfsFlag)
                {
                    Console.WriteLine(" None\n");
                }
            }
            catch (Exception e) {
                Console.WriteLine("error" + e);
                e.StackTrace.ToString();
            }
        }
コード例 #2
0
        public void GetCommonProperties(Dictionary <string, object> properties)
        {
            for (int index = 0; index < 3; ++index)
            {
                if (properties == null)
                {
                    Datastore.tracer.TraceInformation("Datastore properties were null.");
                }
                else if (properties.Count != Datastore.VCProperties.Length)
                {
                    IEnumerable <string> strings = ((IEnumerable <string>)Datastore.VCProperties).Where <string>((Func <string, bool>)(p => !properties.ContainsKey(p)));
                    if (strings != null)
                    {
                        Datastore.tracer.TraceInformation("Did not get all the expected properties for datastore {0}. We are missing: {1}", (object)(properties.ContainsKey("summary.name") ? (string)properties["summary.name"] : "unknown"), (object)string.Join(", ", strings));
                        if (strings.Count <string>() == 1 && strings.Contains <string>("summary.uncommitted"))
                        {
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
                Thread.Sleep(1000);
                Datastore.tracer.TraceInformation("Getting datastore properties.");
                properties = this.GetProperties(Datastore.VCProperties);
            }
            if (properties.ContainsKey("summary.name"))
            {
                this._dsProperties.Name = (string)properties["summary.name"];
            }
            if (properties.ContainsKey("host"))
            {
                DatastoreHostMount[] property = (DatastoreHostMount[])properties["host"];
                if (property.Length != 0)
                {
                    this._dsProperties.Url = property[0].mountInfo.path;
                }
            }
            if (properties.ContainsKey("summary.capacity"))
            {
                this._dsProperties.Capacity = (long)properties["summary.capacity"];
            }
            if (properties.ContainsKey("summary.freeSpace"))
            {
                this._dsProperties.FreeSpace = (long)properties["summary.freeSpace"];
            }
            long num = 0;

            if (properties.ContainsKey("summary.uncommitted"))
            {
                num = (long)properties["summary.uncommitted"];
            }
            this._dsProperties.ProvisionedSpace = this._dsProperties.Capacity - this._dsProperties.FreeSpace + num;
            if (properties.ContainsKey("summary.type"))
            {
                this._dsProperties.Type = (string)properties["summary.type"];
            }
            if (properties.ContainsKey("info"))
            {
                DatastoreInfo property1 = properties["info"] as DatastoreInfo;
                if (property1 != null)
                {
                    this._dsProperties.MaxFileSize = property1.maxFileSize;
                }
                VmfsDatastoreInfo property2 = properties["info"] as VmfsDatastoreInfo;
                if (property2 != null && property2.vmfs != null)
                {
                    this._dsProperties.Version = property2.vmfs.version;
                }
            }
            this._dsProperties.RemoteId = Datastore.GetRemoteId(this._dsProperties.Url);
            this.Name = this._dsProperties.Name;
        }