# Path: networking_vsphere/_i18n.py
# DOMAIN = "networking_vsphere"
# _C = _translators.contextual_form
# _P = _translators.plural_form
# _LI = _translators.log_info
# _LW = _translators.log_warning
# _LE = _translators.log_error
# _LC = _translators.log_critical
# def get_available_languages():
# 
# Path: networking_vsphere/agent/agent.py
# LOG = log.getLogger(__name__)
# class Agent(driver.NetworkDriverCallback):
#     def __init__(self):
#     def _stop_managers(self):
#     def _initialize_managers(self):
#     def _start_managers(self):
#     def set_node_state(self, is_up):
# 
# Path: networking_vsphere/common/config.py
# VMWARE_OPTS = [
#     cfg.StrOpt('vcenter_id',
#                default=None,
#                help='Unique ID of the vCenter Server on which this OVSvApp is'
#                     'hosted'),
#     cfg.StrOpt('vcenter_ip',
#                default=None,
#                help='vCenter server IP.'),
#     cfg.StrOpt('vcenter_username',
#                default=None,
#                help='vCenter server user name.'),
#     cfg.StrOpt('vcenter_password',
#                default=None,
#                help='vCenter server password.',
#                secret=True),
#     cfg.BoolOpt('cert_check',
#                 default=False,
#                 help='Enable SSL certificate check for vCenter.'),
#     cfg.StrOpt('cert_path',
#                default=None,
#                help='Certificate chain path containing cacert of vCenters.'),
#     cfg.IntOpt('https_port',
#                default=443,
#                help='Customized https_port for vCenter communication.'),
#     cfg.StrOpt('wsdl_location',
#                default=None,
#                help='vCenter server wsdl location.'),
#     cfg.StrOpt('vcenter_api_retry_count',
#                default=5,
#                help='Number of retries while connecting to vcenter server.'),
#     cfg.StrOpt('esx_hostname',
#                default=None,
#                help='ESX host name where this OVSvApp is hosted.'),
#     cfg.BoolOpt('esx_maintenance_mode',
#                 default=False,
#                 help='Set host into maintenance mode.'),
#     cfg.MultiStrOpt('cluster_dvs_mapping',
#                     default=[''],
#                     help='vCenter cluster to DVS mapping.')
# ]
# OVSVAPP_OPTS = [
#     cfg.StrOpt('tenant_network_types',
#                default=[p_const.TYPE_VLAN],
#                help='Network type for tenant networks'),
#     cfg.StrOpt('integration_bridge',
#                default='br-int',
#                help='Integration Bridge.'),
#     cfg.ListOpt('bridge_mappings',
#                 default=[],
#                 help='Bridge mappings.'),
#     cfg.StrOpt('agent_driver',
#                default='networking_vsphere.agent.ovsvapp_agent'
#                        '.OVSvAppAgent',
#                help='OVSvApp Agent implementation.'),
#     cfg.StrOpt('network_manager',
#                default='networking_vsphere.drivers.manager.'
#                        'VcenterManager',
#                help='Driver Manager implementation for '
#                     'NetworkDriver.'),
#     cfg.IntOpt('report_interval',
#                default=30,
#                help='Seconds between nodes reporting state to server.'),
#     cfg.IntOpt('polling_interval',
#                default=2,
#                help='The number of seconds the agent will wait between '
#                     'polling for local device changes.'),
#     cfg.IntOpt('veth_mtu',
#                default=1500,
#                help='MTU size of veth interfaces.'),
#     cfg.ListOpt('tunnel_types',
#                 default=[p_const.TYPE_VXLAN],
#                 help='Tunnel network types supported by the OVSvApp Agent.'),
#     cfg.IntOpt('vxlan_udp_port',
#                default=p_const.VXLAN_UDP_PORT,
#                help='The UDP port to use for VXLAN tunnels.'),
#     cfg.BoolOpt('tunnel_csum',
#                 default=False,
#                 help='Set or un-set the tunnel header checksum on '
#                      'outgoing IP packet carrying GRE/VXLAN tunnel.'),
#     cfg.IntOpt('dont_fragment',
#                default=True,
#                help='Do not fragment.'),
#     cfg.StrOpt('tunnel_bridge',
#                default='br-tun',
#                help='Tunnel Bridge for tunneling.'),
#     cfg.StrOpt('local_ip',
#                default='',
#                help='Local IP address of VXLAN tunnel endpoint.'),
#     cfg.StrOpt('monitoring_ip',
#                default='',
#                help='IP address for monitoring OVS Status.')
# ]
# SECURITYGROUP_OPTS = [
#     cfg.StrOpt('security_bridge_mapping',
#                default='br-sec',
#                help='<security_bridge>:<phy_interface>'),
#     cfg.BoolOpt('defer_apply',
#                 default=True,
#                 help='Enable defer_apply on security bridge.'),
#     cfg.StrOpt('ovsvapp_firewall_driver',
#                default='networking_vsphere.drivers.ovs_firewall.'
#                        'OVSFirewallDriver',
#                help='DriverManager implementation for '
#                     'OVS based Firewall.')
# ]
# def register_options():


import signal
import sys
import eventlet
from neutron.common import config as common_config
from oslo_config import cfg
from oslo_log import log
from networking_vsphere._i18n import _, _LE, _LI
from networking_vsphere.agent import agent
from networking_vsphere.common import config as ovsvapp_config
from networking_vsphere.common import utils
eventlet.monkey_patch()


LOG = log.getLogger(__name__)

agent_obj = None


def run():
    signal.signal(signal.SIGTERM, signal_handler)
    signal.signal(signal.SIGINT, signal_handler)
    try:
        global agent_obj
        ovsvapp_config.register_options()
        LOG.info(_LI("Loading agent: %s."), cfg.CONF.OVSVAPP.agent_driver)
        agent_obj = utils.load_object(cfg.CONF.OVSVAPP.agent_driver,
                                      agent.Agent)
        agent_obj.start()
    except Exception as e:
        LOG.exception(_LE("Error in OVSvApp agent service."))
        if agent_obj:
            agent_obj.stop()
        sys.exit(_("ERROR: %s.") % e)


def signal_handler(signum, frame):
    signals_to_names = {}
    for n in dir(signal):
        if n.startswith('SIG') and not n.startswith('SIG_'):
            signals_to_names[getattr(signal, n)] = n

# Path: networking_vsphere/_i18n.py
# DOMAIN = "networking_vsphere"
# _C = _translators.contextual_form
# _P = _translators.plural_form
# _LI = _translators.log_info
# _LW = _translators.log_warning
# _LE = _translators.log_error
# _LC = _translators.log_critical
# def get_available_languages():
# 
# Path: networking_vsphere/agent/agent.py
# LOG = log.getLogger(__name__)
# class Agent(driver.NetworkDriverCallback):
#     def __init__(self):
#     def _stop_managers(self):
#     def _initialize_managers(self):
#     def _start_managers(self):
#     def set_node_state(self, is_up):
# 
# Path: networking_vsphere/common/config.py
# VMWARE_OPTS = [
#     cfg.StrOpt('vcenter_id',
#                default=None,
#                help='Unique ID of the vCenter Server on which this OVSvApp is'
#                     'hosted'),
#     cfg.StrOpt('vcenter_ip',
#                default=None,
#                help='vCenter server IP.'),
#     cfg.StrOpt('vcenter_username',
#                default=None,
#                help='vCenter server user name.'),
#     cfg.StrOpt('vcenter_password',
#                default=None,
#                help='vCenter server password.',
#                secret=True),
#     cfg.BoolOpt('cert_check',
#                 default=False,
#                 help='Enable SSL certificate check for vCenter.'),
#     cfg.StrOpt('cert_path',
#                default=None,
#                help='Certificate chain path containing cacert of vCenters.'),
#     cfg.IntOpt('https_port',
#                default=443,
#                help='Customized https_port for vCenter communication.'),
#     cfg.StrOpt('wsdl_location',
#                default=None,
#                help='vCenter server wsdl location.'),
#     cfg.StrOpt('vcenter_api_retry_count',
#                default=5,
#                help='Number of retries while connecting to vcenter server.'),
#     cfg.StrOpt('esx_hostname',
#                default=None,
#                help='ESX host name where this OVSvApp is hosted.'),
#     cfg.BoolOpt('esx_maintenance_mode',
#                 default=False,
#                 help='Set host into maintenance mode.'),
#     cfg.MultiStrOpt('cluster_dvs_mapping',
#                     default=[''],
#                     help='vCenter cluster to DVS mapping.')
# ]
# OVSVAPP_OPTS = [
#     cfg.StrOpt('tenant_network_types',
#                default=[p_const.TYPE_VLAN],
#                help='Network type for tenant networks'),
#     cfg.StrOpt('integration_bridge',
#                default='br-int',
#                help='Integration Bridge.'),
#     cfg.ListOpt('bridge_mappings',
#                 default=[],
#                 help='Bridge mappings.'),
#     cfg.StrOpt('agent_driver',
#                default='networking_vsphere.agent.ovsvapp_agent'
#                        '.OVSvAppAgent',
#                help='OVSvApp Agent implementation.'),
#     cfg.StrOpt('network_manager',
#                default='networking_vsphere.drivers.manager.'
#                        'VcenterManager',
#                help='Driver Manager implementation for '
#                     'NetworkDriver.'),
#     cfg.IntOpt('report_interval',
#                default=30,
#                help='Seconds between nodes reporting state to server.'),
#     cfg.IntOpt('polling_interval',
#                default=2,
#                help='The number of seconds the agent will wait between '
#                     'polling for local device changes.'),
#     cfg.IntOpt('veth_mtu',
#                default=1500,
#                help='MTU size of veth interfaces.'),
#     cfg.ListOpt('tunnel_types',
#                 default=[p_const.TYPE_VXLAN],
#                 help='Tunnel network types supported by the OVSvApp Agent.'),
#     cfg.IntOpt('vxlan_udp_port',
#                default=p_const.VXLAN_UDP_PORT,
#                help='The UDP port to use for VXLAN tunnels.'),
#     cfg.BoolOpt('tunnel_csum',
#                 default=False,
#                 help='Set or un-set the tunnel header checksum on '
#                      'outgoing IP packet carrying GRE/VXLAN tunnel.'),
#     cfg.IntOpt('dont_fragment',
#                default=True,
#                help='Do not fragment.'),
#     cfg.StrOpt('tunnel_bridge',
#                default='br-tun',
#                help='Tunnel Bridge for tunneling.'),
#     cfg.StrOpt('local_ip',
#                default='',
#                help='Local IP address of VXLAN tunnel endpoint.'),
#     cfg.StrOpt('monitoring_ip',
#                default='',
#                help='IP address for monitoring OVS Status.')
# ]
# SECURITYGROUP_OPTS = [
#     cfg.StrOpt('security_bridge_mapping',
#                default='br-sec',
#                help='<security_bridge>:<phy_interface>'),
#     cfg.BoolOpt('defer_apply',
#                 default=True,
#                 help='Enable defer_apply on security bridge.'),
#     cfg.StrOpt('ovsvapp_firewall_driver',
#                default='networking_vsphere.drivers.ovs_firewall.'
#                        'OVSFirewallDriver',
#                help='DriverManager implementation for '
#                     'OVS based Firewall.')
# ]
# def register_options():


# Path: networking_vsphere/service.py
import signal
import sys
import eventlet
from neutron.common import config as common_config
from oslo_config import cfg
from oslo_log import log
from networking_vsphere._i18n import _, _LE, _LI
from networking_vsphere.agent import agent
from networking_vsphere.common import config as ovsvapp_config
from networking_vsphere.common import utils

eventlet.monkey_patch()


LOG = log.getLogger(__name__)

agent_obj = None


def run():
    signal.signal(signal.SIGTERM, signal_handler)
    signal.signal(signal.SIGINT, signal_handler)
    try:
        global agent_obj
        ovsvapp_config.register_options()
        LOG.info(_LI("Loading agent: %s."), cfg.CONF.OVSVAPP.agent_driver)
        agent_obj = utils.load_object(cfg.CONF.OVSVAPP.agent_driver,
                                      agent.Agent)
        agent_obj.start()
    except Exception as e:
        LOG.exception(_LE("Error in OVSvApp agent service."))
        if agent_obj:
            agent_obj.stop()
        sys.exit(_("ERROR: %s.") % e)


def signal_handler(signum, frame):
    signals_to_names = {}
    for n in dir(signal):
        if n.startswith('SIG') and not n.startswith('SIG_'):
            signals_to_names[getattr(signal, n)] = n

    LOG.info(_LI("Caught %s, exiting."), signals_to_names[signum])