From a8834fcd46339e17fc8add82b5803a1ce53d3d60 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Tue, 26 May 2020 12:04:56 +0200 Subject: [PATCH] Add pyVmomi stubs (#3921) --- third_party/2and3/pyVmomi/__init__.pyi | 0 third_party/2and3/pyVmomi/vim/__init__.pyi | 67 ++++++++++++++++++++ third_party/2and3/pyVmomi/vim/event.pyi | 14 ++++ third_party/2and3/pyVmomi/vim/fault.pyi | 2 + third_party/2and3/pyVmomi/vim/option.pyi | 7 ++ third_party/2and3/pyVmomi/vim/view.pyi | 15 +++++ third_party/2and3/pyVmomi/vmodl/__init__.pyi | 8 +++ third_party/2and3/pyVmomi/vmodl/fault.pyi | 1 + third_party/2and3/pyVmomi/vmodl/query.pyi | 41 ++++++++++++ 9 files changed, 155 insertions(+) create mode 100644 third_party/2and3/pyVmomi/__init__.pyi create mode 100644 third_party/2and3/pyVmomi/vim/__init__.pyi create mode 100644 third_party/2and3/pyVmomi/vim/event.pyi create mode 100644 third_party/2and3/pyVmomi/vim/fault.pyi create mode 100644 third_party/2and3/pyVmomi/vim/option.pyi create mode 100644 third_party/2and3/pyVmomi/vim/view.pyi create mode 100644 third_party/2and3/pyVmomi/vmodl/__init__.pyi create mode 100644 third_party/2and3/pyVmomi/vmodl/fault.pyi create mode 100644 third_party/2and3/pyVmomi/vmodl/query.pyi diff --git a/third_party/2and3/pyVmomi/__init__.pyi b/third_party/2and3/pyVmomi/__init__.pyi new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/third_party/2and3/pyVmomi/vim/__init__.pyi b/third_party/2and3/pyVmomi/vim/__init__.pyi new file mode 100644 index 000000000000..21e330dabc90 --- /dev/null +++ b/third_party/2and3/pyVmomi/vim/__init__.pyi @@ -0,0 +1,67 @@ +from datetime import datetime +from enum import Enum +from typing import Any, List + +from . import event +from . import fault +from . import view +from ..vmodl.query import PropertyCollector +from .event import EventManager +from .option import OptionManager +from .view import ViewManager + +class ManagedObject: ... + +class ManagedEntity(ManagedObject): + _moId: str + obj: None + name: str + +class ServiceInstanceContent: + setting: OptionManager + propertyCollector: PropertyCollector + rootFolder: Folder + viewManager: ViewManager + perfManager: PerformanceManager + eventManager: EventManager + +class ServiceInstance: + content: ServiceInstanceContent + def CurrentTime(self) -> Any: ... + +class PerformanceManager: + class MetricId: + def __init__(self, counterId: Any, instance: Any): ... + + class PerfCounterInfo: + key: int + groupInfo: Any + nameInfo: Any + rollupType: Any + class QuerySpec: + entity: ManagedEntity + metricId: List[PerformanceManager.MetricId] + intervalId: int + maxSample: int + startTime: datetime + + class EntityMetricBase: + value: Any + entity: ManagedEntity + + def QueryPerfCounterByLevel(self, collection_level: int) -> List[PerformanceManager.PerfCounterInfo]: ... + + def QueryPerf(self, querySpec: List[PerformanceManager.QuerySpec]) -> List[PerformanceManager.EntityMetricBase]: ... + +class ClusterComputeResource(ManagedEntity): ... +class ComputeResource(ManagedEntity): ... +class Datacenter(ManagedEntity): ... +class Datastore(ManagedEntity): ... +class Folder(ManagedEntity): ... +class HostSystem(ManagedEntity): ... +class VirtualMachine(ManagedEntity): ... + +class VirtualMachinePowerState(Enum): + poweredOff: int + poweredOn: int + suspended: int diff --git a/third_party/2and3/pyVmomi/vim/event.pyi b/third_party/2and3/pyVmomi/vim/event.pyi new file mode 100644 index 000000000000..bea8dc668311 --- /dev/null +++ b/third_party/2and3/pyVmomi/vim/event.pyi @@ -0,0 +1,14 @@ +from datetime import datetime +from typing import List + +class Event: + createdTime: datetime + +class EventFilterSpec: + class ByTime: + def __init__(self, beginTime: datetime): ... + time: EventFilterSpec.ByTime + +class EventManager: + latestEvent: Event + def QueryEvents(self, filer: EventFilterSpec) -> List[Event]: ... diff --git a/third_party/2and3/pyVmomi/vim/fault.pyi b/third_party/2and3/pyVmomi/vim/fault.pyi new file mode 100644 index 000000000000..d7fa9ffc6f45 --- /dev/null +++ b/third_party/2and3/pyVmomi/vim/fault.pyi @@ -0,0 +1,2 @@ +class InvalidName(Exception): ... +class RestrictedByAdministrator(Exception): ... diff --git a/third_party/2and3/pyVmomi/vim/option.pyi b/third_party/2and3/pyVmomi/vim/option.pyi new file mode 100644 index 000000000000..8b2ca7c9c82f --- /dev/null +++ b/third_party/2and3/pyVmomi/vim/option.pyi @@ -0,0 +1,7 @@ +from typing import Any, List + +class OptionManager: + def QueryOptions(self, name: str) -> List[OptionValue]: ... + +class OptionValue: + value: Any diff --git a/third_party/2and3/pyVmomi/vim/view.pyi b/third_party/2and3/pyVmomi/vim/view.pyi new file mode 100644 index 000000000000..c9e40afca305 --- /dev/null +++ b/third_party/2and3/pyVmomi/vim/view.pyi @@ -0,0 +1,15 @@ +from typing import List, Type + +from pyVmomi.vim import ManagedEntity + +class ContainerView: + def Destroy(self) -> None: ... + +class ViewManager: + # Doc says the `type` parameter of CreateContainerView is a `List[str]`, + # but in practice it seems to be `List[Type[ManagedEntity]]` + # Source: https://pubs.vmware.com/vi-sdk/visdk250/ReferenceGuide/vim.view.ViewManager.html + @staticmethod + def CreateContainerView( + container: ManagedEntity, type: List[Type[ManagedEntity]], recursive: bool + ) -> ContainerView: ... diff --git a/third_party/2and3/pyVmomi/vmodl/__init__.pyi b/third_party/2and3/pyVmomi/vmodl/__init__.pyi new file mode 100644 index 000000000000..a2b8e59317f6 --- /dev/null +++ b/third_party/2and3/pyVmomi/vmodl/__init__.pyi @@ -0,0 +1,8 @@ +from typing import Any + +from . import fault +from . import query + +class DynamicProperty: + name: str + val: Any diff --git a/third_party/2and3/pyVmomi/vmodl/fault.pyi b/third_party/2and3/pyVmomi/vmodl/fault.pyi new file mode 100644 index 000000000000..8a28698d2aba --- /dev/null +++ b/third_party/2and3/pyVmomi/vmodl/fault.pyi @@ -0,0 +1 @@ +class InvalidArgument(Exception): ... diff --git a/third_party/2and3/pyVmomi/vmodl/query.pyi b/third_party/2and3/pyVmomi/vmodl/query.pyi new file mode 100644 index 000000000000..0e38e25d11f5 --- /dev/null +++ b/third_party/2and3/pyVmomi/vmodl/query.pyi @@ -0,0 +1,41 @@ +from typing import Any, List, Optional, Type + +from pyVmomi.vim import ManagedEntity +from pyVmomi.vim.view import ContainerView +from pyVmomi.vmodl import DynamicProperty + +class PropertyCollector: + class PropertySpec: + type: Type[ManagedEntity] + pathSet: List[str] + + class TraversalSpec: + path: str + skip: bool + type: Type[ContainerView] + + class RetrieveOptions: + maxObjects: int + + class ObjectSpec: + skip: bool + selectSet: List[PropertyCollector.TraversalSpec] + obj: Any + + class FilterSpec: + propSet: List[PropertyCollector.PropertySpec] + objectSet: List[PropertyCollector.ObjectSpec] + + class ObjectContent: + obj: ManagedEntity + propSet: List[DynamicProperty] + + class RetrieveResult: + objects: List[PropertyCollector.ObjectContent] + token: Optional[str] + + def RetrievePropertiesEx( + self, specSet: List[PropertyCollector.FilterSpec], options: PropertyCollector.RetrieveOptions + ) -> PropertyCollector.RetrieveResult: ... + + def ContinueRetrievePropertiesEx(self, token: str) -> PropertyCollector.RetrieveResult: ...