私はvSphere APIを使用して、vCenter内のすべてのVMを取得しています。しかし、私はバッチ/ページングで要求を述べている公式の文書やコード例は見つけられませんでした。私のコードは以下の通りです:vSphere API経由でバッチ処理を行う方法はありますか?
VimClient client = new VimClient();
client.Connect(host, CommunicationProtocol.Https, 443);
client.Login(userName, password);
IList<EntityViewBase> vms = client.FindEntityViews(typeof(VirtualMachine), null, null, null);
私はReSharperで逆コンパイルされたソースコードをチェックしました。興味深いことに、null可能なパラメータ "beginEntity"があります。取得するエンティティの数を指定する方法はありません。バッチをサポートしてくれることは全く期待できませんか?
public List<EntityViewBase> FindEntityViews(Type viewType, ManagedObjectReference beginEntity, NameValueCollection filter, string[] properties)
{
IList<ViewBase> viewBaseList = (IList<ViewBase>) null;
ManagedObjectReference beginEntity1 = beginEntity ?? this._serviceContent.RootFolder;
string[] strArray = (string[]) null;
if (filter != null && filter.Count > 0)
{
string[] propertyList = new string[filter.Count];
filter.AllKeys.CopyTo((Array) propertyList, 0);
strArray = VimClient.ValidatePropertyPathList(viewType, propertyList);
}
ObjectContent[] objectContentArray = new PropertyCollector(this, this._serviceContent.PropertyCollector).RetrieveProperties(new PropertyFilterSpec[1]
{
EntityViewBase.GetSearchFilterSpec(this, beginEntity1, new PropertySpec()
{
All = new bool?(false),
Type = viewType.Name,
PathSet = strArray
})
});
List<ManagedObjectReference> managedObjectReferenceList = new List<ManagedObjectReference>();
if (objectContentArray != null)
{
foreach (ObjectContent objectContent in objectContentArray)
{
if (beginEntity == null || !objectContent.Obj.Value.Equals(beginEntity.Value) || !objectContent.Obj.Type.Equals(beginEntity.Type))
{
if (filter != null && filter.Count > 0)
{
DynamicProperty[] propSet = objectContent.PropSet;
if (propSet != null)
{
Dictionary<string, object> dictionary = new Dictionary<string, object>();
foreach (DynamicProperty dynamicProperty in propSet)
dictionary.Add(dynamicProperty.Name, dynamicProperty.Val);
if (dictionary.Count > 0 && VimClient.MatchProperyList(filter, viewType, (IDictionary<string, object>) dictionary))
managedObjectReferenceList.Add(objectContent.Obj);
}
}
else
managedObjectReferenceList.Add(objectContent.Obj);
}
}
}
if (managedObjectReferenceList.Count > 0)
viewBaseList = (IList<ViewBase>) this.GetViewsByMorefs((IEnumerable<ManagedObjectReference>) managedObjectReferenceList, properties);
List<EntityViewBase> entityViewBaseList = (List<EntityViewBase>) null;
if (viewBaseList != null)
{
entityViewBaseList = new List<EntityViewBase>();
foreach (ViewBase viewBase in (IEnumerable<ViewBase>) viewBaseList)
{
EntityViewBase entityViewBase = viewBase as EntityViewBase;
entityViewBaseList.Add(entityViewBase);
}
}
return entityViewBaseList;
}
public List<ViewBase> GetViewsByMorefs(IEnumerable<ManagedObjectReference> moRefs, params string[] properties)
{
Dictionary<string, PropertyFilterSpec> propertyFilterSpecList = new Dictionary<string, PropertyFilterSpec>();
foreach (ManagedObjectReference moRef in moRefs)
{
if (propertyFilterSpecList.ContainsKey(moRef.Type.ToLower()))
{
PropertyFilterSpec propertyFilterSpec = propertyFilterSpecList[moRef.Type.ToLower()];
propertyFilterSpec.ObjectSet = new List<ObjectSpec>((IEnumerable<ObjectSpec>) propertyFilterSpec.ObjectSet)
{
new ObjectSpec() { Obj = moRef }
}.ToArray();
}
else
{
PropertyFilterSpec resultPropertyFilterSpec;
Dictionary<string, List<string>> currentAllowedPropertyPath;
DynamicPropertyFilterSpecGenerator.Generate(moRef, properties, out resultPropertyFilterSpec, out currentAllowedPropertyPath);
propertyFilterSpecList.Add(moRef.Type.ToLower(), resultPropertyFilterSpec);
}
}
PropertyFilterSpec[] propertyFilterSpecArray = new PropertyFilterSpec[propertyFilterSpecList.Values.Count];
propertyFilterSpecList.Values.CopyTo(propertyFilterSpecArray, 0);
ObjectContent[] objectContent = new PropertyCollector(this, this._serviceContent.PropertyCollector).RetrieveProperties(propertyFilterSpecArray);
List<ViewBase> viewsByMorefs = this.GetViewsByMorefs(moRefs, objectContent, propertyFilterSpecList);
return viewsByMorefs;
}
private List<ViewBase> GetViewsByMorefs(IEnumerable<ManagedObjectReference> moRefs, ObjectContent[] objectContent, Dictionary<string, PropertyFilterSpec> propertyFilterSpecList)
{
List<ViewBase> viewBaseList = new List<ViewBase>();
List<string> stringList = new List<string>();
foreach (ManagedObjectReference moRef in moRefs)
stringList.Add(moRef.Value);
Dictionary<string, ObjectContent> objectContentList = new Dictionary<string, ObjectContent>();
foreach (ObjectContent objectContent1 in objectContent)
objectContentList.Add(objectContent1.Obj.Value, objectContent1);
Dictionary<string, ViewBase> generatedManagedObjectList = new Dictionary<string, ViewBase>();
foreach (ObjectContent objectContent1 in objectContent)
{
if (stringList.Contains(objectContent1.Obj.Value))
{
ConstructorInfo constructor = ViewBase.GetViewType(objectContent1.Obj.Type).GetConstructor(new Type[2]
{
typeof (VimClient),
typeof (ManagedObjectReference)
});
if (constructor != null)
{
ViewBase currentObject = (ViewBase) constructor.Invoke(new object[2]
{
(object) this,
(object) objectContent1.Obj
});
ViewBase.SetViewData(currentObject, (string) null, (Dictionary<string, List<string>>) null, objectContentList, generatedManagedObjectList);
viewBaseList.Add(currentObject);
}
}
}
return viewBaseList;
}
'RetrievePropertiesEx'と' ContinueRetrievePropertiesEx'は私にとってうまくいきます!しかし、私は 'VimClient.ValidatePropertyPathList'のような非公開のメソッドをたくさん使っている私自身の' FindEntityViews'メソッドを実装する必要があります。これに関する推奨事項はありますか? –