-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_agent.py
92 lines (78 loc) · 3.24 KB
/
s_agent.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
84
85
86
87
88
89
90
91
92
import sys
from oslo_config import cfg
from oslo_log import log as logging
#import oslo_messaging
from six import moves
from neutron.common import utils
from neutron.common import config as common_config
from neutron.i18n import _LE, _LI, _LW
from neutron.agent import securitygroups_rpc as sg_rpc
from neutron.agent.linux import ip_lib
from neutron.agent.common import config as agent_conf
from neutron.common import constants as q_const
LOG = logging.getLogger(__name__)
cfg.CONF.import_group('AGENT', 'vmware_conf')
def create_agent_config_map(config):
"""Create a map of agent config parameters.
:param config: an instance of cfg.CONF
:returns: a map of agent configuration parameters
"""
try:
bridge_mappings = utils.parse_mappings(config.ML2_VMWARE.network_maps)
except ValueError as e:
raise ValueError(_("Parsing network_maps failed: %s.") % e)
kwargs = dict(
vsphere_hostname=config.ML2_VMWARE.vsphere_hostname,
vsphere_login=config.ML2_VMWARE.vsphere_login,
vsphere_password=config.ML2_VMWARE.vsphere_password,
bridge_mappings=bridge_mappings,
polling_interval=config.AGENT.polling_interval,
minimize_polling=config.AGENT.minimize_polling,
veth_mtu=config.AGENT.veth_mtu,
quitting_rpc_timeout=config.AGENT.quitting_rpc_timeout,
)
return kwargs
class SimpleAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin):
# target = oslo_messaging.Target(version='1.2')
def __init__(self, vsphere_hostname, vsphere_login, vsphere_password,
bridge_mappings, polling_interval,
veth_mtu=None,
minimize_polling=False,
quitting_rpc_timeout=None):
super(SimpleAgent, self).__init__()
self.veth_mtu = veth_mtu
self.available_local_vlans = set(moves.xrange(q_const.MIN_VLAN_TAG,
q_const.MAX_VLAN_TAG))
# TODO(ethuleau): Change ARP responder so it's not dependent on the
# ML2 l2 population mechanism driver.
self.agent_state = {
'binary': 'neutron-dvs-agent',
'host': cfg.CONF.host,
'topic': q_const.L2_AGENT_TOPIC,
'configurations': {'bridge_mappings': bridge_mappings,
'vsphere_hostname': vsphere_hostname,
'log_agent_heartbeats':
cfg.CONF.AGENT.log_agent_heartbeats},
'agent_type': 'DVS agent',
'start_flag': True}
print self.agent_state
def main():
cfg.CONF.register_opts(ip_lib.OPTS)
agent_conf.register_root_helper(cfg.CONF)
common_config.init(sys.argv[1:])
common_config.setup_logging()
utils.log_opt_values(LOG)
try:
agent_config = create_agent_config_map(cfg.CONF)
except ValueError as e:
LOG.error(_LE('%s Agent terminated!'), e)
sys.exit(1)
try:
agent = SimpleAgent(**agent_config)
except RuntimeError as e:
LOG.error(_LE("%s Agent terminated!"), e)
sys.exit(1)
'''signal.signal(signal.SIGTERM, agent._handle_sigterm)
# Start everything.
LOG.info(_LI("Agent initialized successfully, now running... "))
agent.daemon_loop()'''