Skip to content

Commit

Permalink
Add pyVmomi stubs (python#3921)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreYang committed May 26, 2020
1 parent 448c4e1 commit a8834fc
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 0 deletions.
Empty file.
67 changes: 67 additions & 0 deletions 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
14 changes: 14 additions & 0 deletions 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]: ...
2 changes: 2 additions & 0 deletions third_party/2and3/pyVmomi/vim/fault.pyi
@@ -0,0 +1,2 @@
class InvalidName(Exception): ...
class RestrictedByAdministrator(Exception): ...
7 changes: 7 additions & 0 deletions 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
15 changes: 15 additions & 0 deletions 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: ...
8 changes: 8 additions & 0 deletions 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
1 change: 1 addition & 0 deletions third_party/2and3/pyVmomi/vmodl/fault.pyi
@@ -0,0 +1 @@
class InvalidArgument(Exception): ...
41 changes: 41 additions & 0 deletions 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: ...

0 comments on commit a8834fc

Please sign in to comment.