-
Notifications
You must be signed in to change notification settings - Fork 3
/
__main__.py
83 lines (67 loc) · 2.7 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
import argparse
import sys
import gevent
import yaml
import cvm.constants as const
from cvm.clients import (ESXiAPIClient, VCenterAPIClient, VNCAPIClient,
VRouterAPIClient)
from cvm.controllers import (VmReconfiguredHandler, VmRemovedHandler,
VmRenamedHandler, VmwareController)
from cvm.database import Database
from cvm.monitors import VMwareMonitor
from cvm.services import (VirtualMachineInterfaceService,
VirtualMachineService, VirtualNetworkService)
def load_config(config_file):
with open(config_file, 'r') as ymlfile:
cfg = yaml.load(ymlfile)
esxi_cfg = cfg['esxi']
vcenter_cfg = cfg['vcenter']
vnc_cfg = cfg['vnc']
return esxi_cfg, vcenter_cfg, vnc_cfg
def main(args):
esxi_cfg, vcenter_cfg, vnc_cfg = load_config(args.config_file)
esxi_api_client = ESXiAPIClient(esxi_cfg)
event_history_collector = esxi_api_client.create_event_history_collector(const.EVENTS_TO_OBSERVE)
esxi_api_client.add_filter(event_history_collector, ['latestPage'])
esxi_api_client.make_wait_options(120)
vcenter_api_client = VCenterAPIClient(vcenter_cfg)
vnc_api_client = VNCAPIClient(vnc_cfg)
database = Database()
vm_service = VirtualMachineService(
esxi_api_client=esxi_api_client,
vnc_api_client=vnc_api_client,
database=database
)
vn_service = VirtualNetworkService(
vcenter_api_client=vcenter_api_client,
vnc_api_client=vnc_api_client,
database=database
)
vmi_service = VirtualMachineInterfaceService(
vcenter_api_client=vcenter_api_client,
vnc_api_client=vnc_api_client,
vrouter_api_client=VRouterAPIClient(),
database=database,
esxi_api_client=esxi_api_client
)
vm_renamed_handler = VmRenamedHandler(vm_service, vmi_service)
vm_reconfigured_handler = VmReconfiguredHandler(vm_service, vmi_service)
vm_removed_handler = VmRemovedHandler(vm_service, vmi_service)
handlers = [vm_renamed_handler, vm_reconfigured_handler, vm_removed_handler]
vmware_controller = VmwareController(vm_service, vn_service, vmi_service, handlers)
vmware_monitor = VMwareMonitor(esxi_api_client, vmware_controller)
greenlets = [
gevent.spawn(vmware_monitor.start()),
]
gevent.joinall(greenlets)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-c", action="store", dest="config_file",
default='/etc/contrail/contrail-vcenter-manager/config.yaml')
parsed_args = parser.parse_args()
try:
main(parsed_args)
sys.exit(0)
except KeyboardInterrupt:
sys.exit(0)