コード例 #1
0
ファイル: rpc.py プロジェクト: Apsu/quantum
 def report_state(self, context, agent_state):
     return self.call(context,
                      self.make_msg('report_state',
                                    agent_state={'agent_state':
                                                 agent_state},
                                    time=timeutils.strtime()),
                      topic=self.topic)
コード例 #2
0
 def report_state(self, context, agent_state):
     return self.call(context,
                      self.make_msg(
                          'report_state',
                          agent_state={'agent_state': agent_state},
                          time=timeutils.strtime()),
                      topic=self.topic)
コード例 #3
0
ファイル: rpc.py プロジェクト: DestinyOneSystems/quantum
 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)
コード例 #4
0
 def _register_agent_states(self):
     """Register two L3 agents and two DHCP agents."""
     l3_hosta = {
         'binary': 'quantum-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': 'quantum-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]
コード例 #5
0
 def _register_agent_states(self):
     """Register two L3 agents and two DHCP agents."""
     l3_hosta = {
         'binary': 'quantum-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': 'quantum-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]
コード例 #6
0
ファイル: test_agent_ext_plugin.py プロジェクト: Apsu/quantum
 def _register_one_dhcp_agent(self):
     """Register one DHCP agent."""
     dhcp_host = {
         'binary': 'quantum-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]
コード例 #7
0
 def _register_one_dhcp_agent(self):
     """Register one DHCP agent."""
     dhcp_host = {
         'binary': 'quantum-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]
コード例 #8
0
 def _register_one_agent_state(self, agent_state):
     callback = agents_db.AgentExtRpcCallback()
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': agent_state},
                           time=timeutils.strtime())
コード例 #9
0
ファイル: jsonutils.py プロジェクト: kumarcv/openstack-nf
def to_primitive(value, convert_instances=False, level=0):
    """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.

    """
    nasty = [inspect.ismodule, inspect.isclass, inspect.ismethod,
             inspect.isfunction, inspect.isgeneratorfunction,
             inspect.isgenerator, inspect.istraceback, inspect.isframe,
             inspect.iscode, inspect.isbuiltin, inspect.isroutine,
             inspect.isabstract]
    for test in nasty:
        if test(value):
            return unicode(value)

    # value of itertools.count doesn't get caught by inspects
    # above and results in infinite loop when list(value) is called.
    if type(value) == itertools.count:
        return unicode(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 > 3:
        return '?'

    # The try block may not be necessary after the class check above,
    # but just in case ...
    try:
        # 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 isinstance(value, (list, tuple)):
            o = []
            for v in value:
                o.append(to_primitive(v, convert_instances=convert_instances,
                                      level=level))
            return o
        elif isinstance(value, dict):
            o = {}
            for k, v in value.iteritems():
                o[k] = to_primitive(v, convert_instances=convert_instances,
                                    level=level)
            return o
        elif isinstance(value, datetime.datetime):
            return timeutils.strtime(value)
        elif hasattr(value, 'iteritems'):
            return to_primitive(dict(value.iteritems()),
                                convert_instances=convert_instances,
                                level=level + 1)
        elif hasattr(value, '__iter__'):
            return to_primitive(list(value),
                                convert_instances=convert_instances,
                                level=level)
        elif convert_instances and hasattr(value, '__dict__'):
            # Likely an instance of something. Watch for cycles.
            # Ignore class member vars.
            return to_primitive(value.__dict__,
                                convert_instances=convert_instances,
                                level=level + 1)
        else:
            return value
    except TypeError, e:
        # Class objects are tricky since they may define something like
        # __iter__ defined but it isn't callable as list().
        return unicode(value)
コード例 #10
0
ファイル: jsonutils.py プロジェクト: soheilhy/quantum
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 value.iteritems())
        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 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)
        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)
コード例 #11
0
ファイル: jsonutils.py プロジェクト: zhangheng1442/openstack
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.

    """
    nasty = [inspect.ismodule, inspect.isclass, inspect.ismethod,
             inspect.isfunction, inspect.isgeneratorfunction,
             inspect.isgenerator, inspect.istraceback, inspect.isframe,
             inspect.iscode, inspect.isbuiltin, inspect.isroutine,
             inspect.isabstract]
    for test in nasty:
        if test(value):
            return unicode(value)

    # value of itertools.count doesn't get caught by inspects
    # above and results in infinite loop when list(value) is called.
    if type(value) == itertools.count:
        return unicode(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)
        # 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 isinstance(value, (list, tuple)):
            return [recursive(v) for v in value]
        elif isinstance(value, dict):
            return dict((k, recursive(v)) for k, v in value.iteritems())
        elif convert_datetime and isinstance(value, datetime.datetime):
            return timeutils.strtime(value)
        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)
        else:
            return value
    except TypeError:
        # Class objects are tricky since they may define something like
        # __iter__ defined but it isn't callable as list().
        return unicode(value)
コード例 #12
0
 def _register_one_agent_state(self, agent_state):
     callback = agents_db.AgentExtRpcCallback()
     callback.report_state(self.adminContext,
                           agent_state={'agent_state': agent_state},
                           time=timeutils.strtime())