예제 #1
0
 def _register_ml2_agents(self):
     callback = agents_db.AgentExtRpcCallback()
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': L2_AGENT},
                           time=timeutils.strtime())
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': L2_AGENT_2},
                           time=timeutils.strtime())
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': L2_AGENT_3},
                           time=timeutils.strtime())
예제 #2
0
 def _register_ml2_agents(self):
     callback = agents_db.AgentExtRpcCallback()
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': L2_AGENT},
                           time=timeutils.strtime())
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': L2_AGENT_2},
                           time=timeutils.strtime())
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': L2_AGENT_3},
                           time=timeutils.strtime())
예제 #3
0
    def _register_l3_agents(self):
        callback = agents_db.AgentExtRpcCallback()
        callback.report_state(self.adminContext,
                              agent_state={'agent_state': FIRST_L3_AGENT},
                              time=timeutils.strtime())
        agent_db = self.plugin.get_agents_db(self.adminContext,
                                             filters={'host': [HOST]})
        self.agent_id1 = agent_db[0].id

        callback.report_state(self.adminContext,
                              agent_state={'agent_state': SECOND_L3_AGENT},
                              time=timeutils.strtime())
        agent_db = self.plugin.get_agents_db(self.adminContext,
                                             filters={'host': [HOST]})
        self.agent_id2 = agent_db[0].id
예제 #4
0
    def _register_l3_agents(self):
        callback = agents_db.AgentExtRpcCallback()
        callback.report_state(self.adminContext,
                              agent_state={'agent_state': FIRST_L3_AGENT},
                              time=timeutils.strtime())
        agent_db = self.plugin.get_agents_db(self.adminContext,
                                             filters={'host': [HOST]})
        self.agent_id1 = agent_db[0].id

        callback.report_state(self.adminContext,
                              agent_state={'agent_state': SECOND_L3_AGENT},
                              time=timeutils.strtime())
        agent_db = self.plugin.get_agents_db(self.adminContext,
                                             filters={'host': [HOST]})
        self.agent_id2 = agent_db[0].id
예제 #5
0
    def _register_l3_dvr_agents(self):
        callback = agents_db.AgentExtRpcCallback()
        callback.report_state(self.adminContext,
                              agent_state={'agent_state': DVR_L3_AGENT},
                              time=timeutils.strtime())
        agent_db = self.plugin.get_agents_db(self.adminContext,
                                             filters={'host': [HOST_DVR]})
        self.l3_dvr_agent = agent_db[0]

        callback.report_state(self.adminContext,
                              agent_state={'agent_state': DVR_SNAT_L3_AGENT},
                              time=timeutils.strtime())
        agent_db = self.plugin.get_agents_db(self.adminContext,
                                             filters={'host': [HOST_DVR_SNAT]})
        self.l3_dvr_snat_id = agent_db[0].id
        self.l3_dvr_snat_agent = agent_db[0]
예제 #6
0
    def _register_l3_dvr_agents(self):
        callback = agents_db.AgentExtRpcCallback()
        callback.report_state(self.adminContext,
                              agent_state={'agent_state': DVR_L3_AGENT},
                              time=timeutils.strtime())
        agent_db = self.plugin.get_agents_db(self.adminContext,
                                             filters={'host': [HOST_DVR]})
        self.l3_dvr_agent = agent_db[0]

        callback.report_state(self.adminContext,
                              agent_state={'agent_state': DVR_SNAT_L3_AGENT},
                              time=timeutils.strtime())
        agent_db = self.plugin.get_agents_db(self.adminContext,
                                             filters={'host': [HOST_DVR_SNAT]})
        self.l3_dvr_snat_id = agent_db[0].id
        self.l3_dvr_snat_agent = agent_db[0]
예제 #7
0
 def report_state(self, context, agent_state, use_call=False):
     msg = self.make_msg('report_state',
                         agent_state={'agent_state': agent_state},
                         time=timeutils.strtime())
     if use_call:
         return self.call(context, msg, topic=self.topic)
     else:
         return self.cast(context, msg, topic=self.topic)
예제 #8
0
파일: rpc.py 프로젝트: fortara/neutron
 def report_state(self, context, agent_state, use_call=False):
     cctxt = self.client.prepare()
     kwargs = {
         'agent_state': {'agent_state': agent_state},
         'time': timeutils.strtime(),
     }
     method = cctxt.call if use_call else cctxt.cast
     return method(context, 'report_state', **kwargs)
예제 #9
0
파일: rpc.py 프로젝트: TrevorV/neutron
 def report_state(self, context, agent_state, use_call=False):
     msg = self.make_msg('report_state',
                         agent_state={'agent_state':
                                      agent_state},
                         time=timeutils.strtime())
     if use_call:
         return self.call(context, msg, topic=self.topic)
     else:
         return self.cast(context, msg, topic=self.topic)
 def _register_agent_states(self):
     """Register two L3 agents and two DHCP agents."""
     l3_hosta = {
         'binary': 'neutron-l3-agent',
         'host': L3_HOSTA,
         'topic': topics.L3_AGENT,
         'configurations': {'use_namespaces': True,
                            'router_id': None,
                            'handle_internal_only_routers':
                            True,
                            'gateway_external_network_id':
                            None,
                            'interface_driver': 'interface_driver',
                            },
         'agent_type': constants.AGENT_TYPE_L3}
     l3_hostb = copy.deepcopy(l3_hosta)
     l3_hostb['host'] = L3_HOSTB
     dhcp_hosta = {
         'binary': 'neutron-dhcp-agent',
         'host': DHCP_HOSTA,
         'topic': 'DHCP_AGENT',
         'configurations': {'dhcp_driver': 'dhcp_driver',
                            'use_namespaces': True,
                            },
         'agent_type': constants.AGENT_TYPE_DHCP}
     dhcp_hostc = copy.deepcopy(dhcp_hosta)
     dhcp_hostc['host'] = DHCP_HOSTC
     callback = agents_db.AgentExtRpcCallback()
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': l3_hosta},
                           time=timeutils.strtime())
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': l3_hostb},
                           time=timeutils.strtime())
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': dhcp_hosta},
                           time=timeutils.strtime())
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': dhcp_hostc},
                           time=timeutils.strtime())
     return [l3_hosta, l3_hostb, dhcp_hosta, dhcp_hostc]
예제 #11
0
 def _report_state(self):
     if not self.needs_resync:
         agent_state = {
             'ip': self.conf.lbaas_proxy_ip,
             'time': timeutils.strtime(),
             'status': 'ACTIVE' if self.haproxy_active() else 'DOWN',
         }
         try:
             self.agent_rpc.report_state(agent_state)
         except Exception:
             LOG.exception(_("Failed reporting state!"))
             self.needs_resync = True
예제 #12
0
 def get_process_by_tap_service(cls, tap_service):
     utc_now = str(timeutils.strtime())
     utc_now = utc_now[:19]
     tap_service = tap_service["tap_service"]
     dev_name = taas_constants.TAP_SERVICE_PREFIX + tap_service["name"][:9]
     if not os.path.exists("/var/pcaps/"):
         os.makedirs("/var/pcaps/")
     filename = "/var/pcaps/%s.pcap" % (
         tap_service["name"] + "_" +
         utc_now.replace("-", "").replace(":", ""))
     LOG.info("device_name is %s, filename is %s" % (dev_name, filename))
     return cls(dev_name, filename)
예제 #13
0
 def _report_state(self):
     if not self.needs_resync:
         agent_state = {
             'ip': self.conf.lbaas_proxy_ip,
             'time': timeutils.strtime(),
             'status': 'ACTIVE' if self.haproxy_active() else 'DOWN',
         }
         try:
             self.agent_rpc.report_state(agent_state)
         except Exception:
             LOG.exception(_("Failed reporting state!"))
             self.needs_resync = True
예제 #14
0
    def _register_agent_states(self, lbaas_agents=False):
        """Register two L3 agents and two DHCP agents."""
        l3_hosta = {
            'binary': 'neutron-l3-agent',
            'host': L3_HOSTA,
            'topic': topics.L3_AGENT,
            'configurations': {'use_namespaces': True,
                               'router_id': None,
                               'handle_internal_only_routers':
                               True,
                               'gateway_external_network_id':
                               None,
                               'interface_driver': 'interface_driver',
                               },
            'agent_type': constants.AGENT_TYPE_L3}
        l3_hostb = copy.deepcopy(l3_hosta)
        l3_hostb['host'] = L3_HOSTB
        dhcp_hosta = {
            'binary': 'neutron-dhcp-agent',
            'host': DHCP_HOSTA,
            'topic': 'DHCP_AGENT',
            'configurations': {'dhcp_driver': 'dhcp_driver',
                               'use_namespaces': True,
                               },
            'agent_type': constants.AGENT_TYPE_DHCP}
        dhcp_hostc = copy.deepcopy(dhcp_hosta)
        dhcp_hostc['host'] = DHCP_HOSTC
        lbaas_hosta = {
            'binary': 'neutron-loadbalancer-agent',
            'host': LBAAS_HOSTA,
            'topic': 'LOADBALANCER_AGENT',
            'configurations': {'device_drivers': ['haproxy_ns']},
            'agent_type': constants.AGENT_TYPE_LOADBALANCER}
        lbaas_hostb = copy.deepcopy(lbaas_hosta)
        lbaas_hostb['host'] = LBAAS_HOSTB
        callback = agents_db.AgentExtRpcCallback()
        callback.report_state(self.adminContext,
                              agent_state={'agent_state': l3_hosta},
                              time=timeutils.strtime())
        callback.report_state(self.adminContext,
                              agent_state={'agent_state': l3_hostb},
                              time=timeutils.strtime())
        callback.report_state(self.adminContext,
                              agent_state={'agent_state': dhcp_hosta},
                              time=timeutils.strtime())
        callback.report_state(self.adminContext,
                              agent_state={'agent_state': dhcp_hostc},
                              time=timeutils.strtime())

        res = [l3_hosta, l3_hostb, dhcp_hosta, dhcp_hostc]
        if lbaas_agents:
            callback.report_state(self.adminContext,
                                  agent_state={'agent_state': lbaas_hosta},
                                  time=timeutils.strtime())
            callback.report_state(self.adminContext,
                                  agent_state={'agent_state': lbaas_hostb},
                                  time=timeutils.strtime())
            res += [lbaas_hosta, lbaas_hostb]

        return res
예제 #15
0
 def _register_l3_agent(self, host):
     agent = {
         'binary': 'neutron-l3-agent',
         'host': host,
         'topic': topics.L3_AGENT,
         'configurations': {},
         'agent_type': n_constants.AGENT_TYPE_L3,
         'start_flag': True
     }
     callback = agents_db.AgentExtRpcCallback()
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': agent},
                           time=timeutils.strtime())
예제 #16
0
 def _register_l3_agent(self, host):
     agent = {
         'binary': 'neutron-l3-agent',
         'host': host,
         'topic': topics.L3_AGENT,
         'configurations': {},
         'agent_type': n_constants.AGENT_TYPE_L3,
         'start_flag': True
     }
     callback = agents_db.AgentExtRpcCallback()
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': agent},
                           time=timeutils.strtime())
예제 #17
0
 def to_dict(self):
     ret_dict = super(LoadBalancer, self).to_dict()
     if self.provider:
         ret_dict['provider'] = self.provider.to_dict()
     else:
         ret_dict['provider'] = None
     ret_dict['listeners'] = [listener.to_dict()
         for listener in self.listeners]
     ret_dict['listener_ids'] = [listener.id
         for listener in self.listeners]
     ret_dict['created_at'] = timeutils.strtime(ret_dict['created_at'])
     if not self.vip_subnet_id:
         ret_dict.pop('vip_subnet_id', None)
     return ret_dict
예제 #18
0
 def _register_one_dhcp_agent(self):
     """Register one DHCP agent."""
     dhcp_host = {
         'binary': 'neutron-dhcp-agent',
         'host': DHCP_HOST1,
         'topic': 'DHCP_AGENT',
         'configurations': {'dhcp_driver': 'dhcp_driver',
                            'use_namespaces': True,
                            },
         'agent_type': constants.AGENT_TYPE_DHCP}
     callback = agents_db.AgentExtRpcCallback()
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': dhcp_host},
                           time=timeutils.strtime())
     return [dhcp_host]
예제 #19
0
 def _register_one_dhcp_agent(self):
     """Register one DHCP agent."""
     dhcp_host = {
         'binary': 'neutron-dhcp-agent',
         'host': DHCP_HOST1,
         'topic': 'DHCP_AGENT',
         'configurations': {'dhcp_driver': 'dhcp_driver',
                            'use_namespaces': True,
                            },
         'agent_type': constants.AGENT_TYPE_DHCP}
     callback = agents_db.AgentExtRpcCallback()
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': dhcp_host},
                           time=timeutils.strtime())
     return [dhcp_host]
예제 #20
0
 def _register_one_l3_agent(self, host=L3_HOSTA, internal_only=True,
                            ext_net_id='', ext_bridge=''):
     l3 = {
         'binary': 'neutron-l3-agent',
         'host': host,
         'topic': topics.L3_AGENT,
         'configurations': {'use_namespaces': True,
                            'router_id': None,
                            'handle_internal_only_routers': internal_only,
                            'external_network_bridge': ext_bridge,
                            'gateway_external_network_id': ext_net_id,
                            'interface_driver': 'interface_driver',
                            },
         'agent_type': constants.AGENT_TYPE_L3}
     callback = agents_db.AgentExtRpcCallback()
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': l3},
                           time=timeutils.strtime())
예제 #21
0
 def _register_one_l3_agent(self, host=L3_HOSTA, internal_only=True,
                            ext_net_id='', ext_bridge=''):
     l3 = {
         'binary': 'neutron-l3-agent',
         'host': host,
         'topic': topics.L3_AGENT,
         'configurations': {'use_namespaces': True,
                            'router_id': None,
                            'handle_internal_only_routers': internal_only,
                            'external_network_bridge': ext_bridge,
                            'gateway_external_network_id': ext_net_id,
                            'interface_driver': 'interface_driver',
                            },
         'agent_type': constants.AGENT_TYPE_L3}
     callback = agents_db.AgentExtRpcCallback()
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': l3},
                           time=timeutils.strtime())
예제 #22
0
    def to_dict(self):
        ret_dict = super(Pool, self).to_dict()
        if self.healthmonitor and self.healthmonitor!=None:
            ret_dict['healthmonitor'] = self.healthmonitor.to_dict()
        else:
            ret_dict.pop('healthmonitor', None)
        ret_dict['members'] = [member.to_dict() for member in self.members]
        if self.session_persistence:
            ret_dict['session_persistence'] = self.session_persistence.to_dict()
        else:
            ret_dict.pop('session_persistence', None)
        ret_dict['created_at'] = timeutils.strtime(ret_dict['created_at'])
        if not self.subnet_id:
            ret_dict.pop('subnet_id', None)

        ret_dict.pop('l7policy', None)

        return ret_dict
예제 #23
0
 def to_dict(self):
     ret_dict = super(Listener, self).to_dict()
     if self.default_pool :
        ret_dict['default_pool'] = self.default_pool.to_dict()
     ret_dict['l7policy_ids'] = []
     ret_dict['l7_policies'] = []
     for l7_policy in self.l7_policies:
         ret_dict['l7policy_ids'].append(l7_policy.id)
         ret_dict['l7_policies'].append(l7_policy.to_dict())
     #ret_dict['sni_container_ids'] = [container.tls_container_id
     #    for container in self.sni_containers]
     #if self.default_tls_container:
     #    ret_dict['default_tls_container_id'] = self.default_tls_container.tls_container_id
     #else:
     #    ret_dict['default_tls_container_id'] = None
     #ret_dict['sni_containers'] = []
     #for sni in self.sni_containers:
     #    ret_dict['sni_containers'].append(sni.to_dict())
     ret_dict['created_at'] = timeutils.strtime(ret_dict['created_at'])
     return ret_dict
예제 #24
0
    def to_dict(self):
        ret_dict = super(L7Policy, self).to_dict()
        ret_dict['rules'] = [rule.to_dict() for rule in self.rules]
        if self.redirect_pool and (self.redirect_pool.listener is None):
            ret_dict['pool'] = self.redirect_pool.to_dict()
        else:
            ret_dict.pop('pool', None)
        if self.action == constants.L7_POLICY_ACTION_REJECT:
            ret_dict.pop('redirect_pool', None)
            ret_dict.pop('redirect_pool_id', None)
            ret_dict.pop('redirect_url', None)
            ret_dict.pop('redirect_url_code', None)
            ret_dict.pop('redirect_url_drop_query', None)
        if self.action == constants.L7_POLICY_ACTION_REDIRECT_TO_URL:
            ret_dict.pop('redirect_pool', None)
            ret_dict.pop('redirect_pool_id', None)
        if self.action == constants.L7_POLICY_ACTION_REDIRECT_TO_POOL:
            ret_dict.pop('redirect_url', None)
            ret_dict.pop('redirect_url_code', None)
            ret_dict.pop('redirect_url_drop_query', None)

        ret_dict['created_at'] = timeutils.strtime(ret_dict['created_at'])
        return ret_dict
예제 #25
0
def _uos_extend_timestamp(res, db):
    res['created_at'] = timeutils.strtime(db['created_at'])
예제 #26
0
 def _register_one_dhcp_agent(self):
     """Register one DHCP agent."""
     dhcp_host = {
         "binary": "neutron-dhcp-agent",
         "host": DHCP_HOST1,
         "topic": "DHCP_AGENT",
         "configurations": {"dhcp_driver": "dhcp_driver", "use_namespaces": True},
         "agent_type": constants.AGENT_TYPE_DHCP,
     }
     callback = agents_db.AgentExtRpcCallback()
     callback.report_state(self.adminContext, agent_state={"agent_state": dhcp_host}, time=timeutils.strtime())
     return [dhcp_host]
예제 #27
0
    def _register_agent_states(self, lbaas_agents=False):
        """Register two L3 agents and two DHCP agents."""
        l3_hosta = {
            "binary": "neutron-l3-agent",
            "host": L3_HOSTA,
            "topic": topics.L3_AGENT,
            "configurations": {
                "use_namespaces": True,
                "router_id": None,
                "handle_internal_only_routers": True,
                "gateway_external_network_id": None,
                "interface_driver": "interface_driver",
            },
            "agent_type": constants.AGENT_TYPE_L3,
        }
        l3_hostb = copy.deepcopy(l3_hosta)
        l3_hostb["host"] = L3_HOSTB
        dhcp_hosta = {
            "binary": "neutron-dhcp-agent",
            "host": DHCP_HOSTA,
            "topic": "DHCP_AGENT",
            "configurations": {"dhcp_driver": "dhcp_driver", "use_namespaces": True},
            "agent_type": constants.AGENT_TYPE_DHCP,
        }
        dhcp_hostc = copy.deepcopy(dhcp_hosta)
        dhcp_hostc["host"] = DHCP_HOSTC
        lbaas_hosta = {
            "binary": "neutron-loadbalancer-agent",
            "host": LBAAS_HOSTA,
            "topic": "LOADBALANCER_AGENT",
            "configurations": {"device_drivers": ["haproxy_ns"]},
            "agent_type": constants.AGENT_TYPE_LOADBALANCER,
        }
        lbaas_hostb = copy.deepcopy(lbaas_hosta)
        lbaas_hostb["host"] = LBAAS_HOSTB
        callback = agents_db.AgentExtRpcCallback()
        callback.report_state(self.adminContext, agent_state={"agent_state": l3_hosta}, time=timeutils.strtime())
        callback.report_state(self.adminContext, agent_state={"agent_state": l3_hostb}, time=timeutils.strtime())
        callback.report_state(self.adminContext, agent_state={"agent_state": dhcp_hosta}, time=timeutils.strtime())
        callback.report_state(self.adminContext, agent_state={"agent_state": dhcp_hostc}, time=timeutils.strtime())

        res = [l3_hosta, l3_hostb, dhcp_hosta, dhcp_hostc]
        if lbaas_agents:
            callback.report_state(self.adminContext, agent_state={"agent_state": lbaas_hosta}, time=timeutils.strtime())
            callback.report_state(self.adminContext, agent_state={"agent_state": lbaas_hostb}, time=timeutils.strtime())
            res += [lbaas_hosta, lbaas_hostb]

        return res
예제 #28
0
def to_primitive(value, convert_instances=False, convert_datetime=True,
                 level=0, max_depth=3):
    """Convert a complex object into primitives.

    Handy for JSON serialization. We can optionally handle instances,
    but since this is a recursive function, we could have cyclical
    data structures.

    To handle cyclical data structures we could track the actual objects
    visited in a set, but not all objects are hashable. Instead we just
    track the depth of the object inspections and don't go too deep.

    Therefore, convert_instances=True is lossy ... be aware.

    """
    # handle obvious types first - order of basic types determined by running
    # full tests on nova project, resulting in the following counts:
    # 572754 <type 'NoneType'>
    # 460353 <type 'int'>
    # 379632 <type 'unicode'>
    # 274610 <type 'str'>
    # 199918 <type 'dict'>
    # 114200 <type 'datetime.datetime'>
    #  51817 <type 'bool'>
    #  26164 <type 'list'>
    #   6491 <type 'float'>
    #    283 <type 'tuple'>
    #     19 <type 'long'>
    if isinstance(value, _simple_types):
        return value

    if isinstance(value, datetime.datetime):
        if convert_datetime:
            return timeutils.strtime(value)
        else:
            return value

    # value of itertools.count doesn't get caught by nasty_type_tests
    # and results in infinite loop when list(value) is called.
    if type(value) == itertools.count:
        return six.text_type(value)

    # FIXME(vish): Workaround for LP bug 852095. Without this workaround,
    #              tests that raise an exception in a mocked method that
    #              has a @wrap_exception with a notifier will fail. If
    #              we up the dependency to 0.5.4 (when it is released) we
    #              can remove this workaround.
    if getattr(value, '__module__', None) == 'mox':
        return 'mock'

    if level > max_depth:
        return '?'

    # The try block may not be necessary after the class check above,
    # but just in case ...
    try:
        recursive = functools.partial(to_primitive,
                                      convert_instances=convert_instances,
                                      convert_datetime=convert_datetime,
                                      level=level,
                                      max_depth=max_depth)
        if isinstance(value, dict):
            return dict((k, recursive(v)) for k, v in six.iteritems(value))
        elif isinstance(value, (list, tuple)):
            return [recursive(lv) for lv in value]

        # It's not clear why xmlrpclib created their own DateTime type, but
        # for our purposes, make it a datetime type which is explicitly
        # handled
        if isinstance(value, xmlrpclib.DateTime):
            value = datetime.datetime(*tuple(value.timetuple())[:6])

        if convert_datetime and isinstance(value, datetime.datetime):
            return timeutils.strtime(value)
        elif isinstance(value, gettextutils.Message):
            return value.data
        elif hasattr(value, 'iteritems'):
            return recursive(dict(value.iteritems()), level=level + 1)
        elif hasattr(value, '__iter__'):
            return recursive(list(value))
        elif convert_instances and hasattr(value, '__dict__'):
            # Likely an instance of something. Watch for cycles.
            # Ignore class member vars.
            return recursive(value.__dict__, level=level + 1)
        elif netaddr and isinstance(value, netaddr.IPAddress):
            return six.text_type(value)
        else:
            if any(test(value) for test in _nasty_type_tests):
                return six.text_type(value)
            return value
    except TypeError:
        # Class objects are tricky since they may define something like
        # __iter__ defined but it isn't callable as list().
        return six.text_type(value)
예제 #29
0
def _uos_extend_timestamp(res, db):
    res['created_at'] = timeutils.strtime(db['created_at'])