• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python jsonutils.dumps函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中quantum.openstack.common.jsonutils.dumps函数的典型用法代码示例。如果您正苦于以下问题:Python dumps函数的具体用法?Python dumps怎么用?Python dumps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了dumps函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: plug_interface

def plug_interface(controller, network, port, type, attachment=None):
    uri = "/ws.v1/lswitch/" + network + "/lport/" + port + "/attachment"

    lport_obj = {}
    if attachment:
        lport_obj["vif_uuid"] = attachment

    lport_obj["type"] = type
    try:
        resp_obj = do_single_request("PUT",
                                     uri,
                                     jsonutils.dumps(lport_obj),
                                     controller=controller)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port or Network not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port, net_id=network)
    except NvpApiClient.Conflict as e:
        LOG.error("Conflict while making attachment to port, "
                  "Error: %s" % str(e))
        raise exception.AlreadyAttached(att_id=attachment,
                                        port_id=port,
                                        net_id=network,
                                        att_port_id="UNKNOWN")
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()

    result = jsonutils.dumps(resp_obj)
    return result
开发者ID:LuizOz,项目名称:quantum,代码行数:28,代码来源:nvplib.py


示例2: test_list_credentials

    def test_list_credentials(self):
        """ Test list credentials """

        # Create Credential before listing
        LOG.debug("test_list_credentials - START")
        req_body1 = jsonutils.dumps(self.test_credential_data)
        create_response1 = self.test_app.post(self.credential_path, req_body1, content_type=self.contenttype)
        req_body2 = jsonutils.dumps(
            {"credential": {"credential_name": "cred9", "user_name": "newUser2", "password": "newPasswd2"}}
        )
        create_response2 = self.test_app.post(self.credential_path, req_body2, content_type=self.contenttype)
        index_response = self.test_app.get(self.credential_path)
        index_resp_body = wsgi.Serializer().deserialize(index_response.body, self.contenttype)
        self.assertEqual(200, index_response.status_int)
        # CLean Up - Deletion of the Credentials
        resp_body1 = wsgi.Serializer().deserialize(create_response1.body, self.contenttype)
        delete_path1_temp = self.cred_second_path + resp_body1["credentials"]["credential"]["id"]
        delete_path1 = str(delete_path1_temp)
        resp_body2 = wsgi.Serializer().deserialize(create_response2.body, self.contenttype)
        list_all_credential = [resp_body1["credentials"]["credential"], resp_body2["credentials"]["credential"]]
        self.assertTrue(index_resp_body["credentials"][0] in list_all_credential)
        self.assertTrue(index_resp_body["credentials"][1] in list_all_credential)
        delete_path2_temp = self.cred_second_path + resp_body2["credentials"]["credential"]["id"]
        delete_path2 = str(delete_path2_temp)
        self.tearDownCredential(delete_path1)
        self.tearDownCredential(delete_path2)
        LOG.debug("test_list_credentials - END")
开发者ID:nibalizer,项目名称:quantum,代码行数:27,代码来源:test_cisco_extension.py


示例3: test_list_qoss

    def test_list_qoss(self):
        """ Test list qoss """

        LOG.debug("test_list_qoss - START")
        req_body1 = jsonutils.dumps(self.test_qos_data)
        create_resp1 = self.test_app.post(self.qos_path, req_body1, content_type=self.contenttype)
        req_body2 = jsonutils.dumps({"qos": {"qos_name": "cisco_test_qos2", "qos_desc": {"PPS": 50, "TTL": 5}}})
        create_resp2 = self.test_app.post(self.qos_path, req_body2, content_type=self.contenttype)
        index_response = self.test_app.get(self.qos_path)
        index_resp_body = wsgi.Serializer().deserialize(index_response.body, self.contenttype)
        self.assertEqual(200, index_response.status_int)

        # Clean Up - Delete the qos's
        resp_body1 = wsgi.Serializer().deserialize(create_resp1.body, self.contenttype)
        qos_path1_temp = self.qos_second_path + resp_body1["qoss"]["qos"]["id"]
        qos_path1 = str(qos_path1_temp)
        resp_body2 = wsgi.Serializer().deserialize(create_resp2.body, self.contenttype)
        list_all_qos = [resp_body1["qoss"]["qos"], resp_body2["qoss"]["qos"]]
        self.assertTrue(index_resp_body["qoss"][0] in list_all_qos)
        self.assertTrue(index_resp_body["qoss"][1] in list_all_qos)
        qos_path2_temp = self.qos_second_path + resp_body2["qoss"]["qos"]["id"]
        qos_path2 = str(qos_path2_temp)
        self.tearDownQos(qos_path1)
        self.tearDownQos(qos_path2)
        LOG.debug("test_list_qoss - END")
开发者ID:nibalizer,项目名称:quantum,代码行数:25,代码来源:test_cisco_extension.py


示例4: test_update_qos

    def test_update_qos(self):

        """ Test update qos """

        LOG.debug("test_update_qos - START")
        req_body = jsonutils.dumps(self.test_qos_data)
        index_response = self.test_app.post(self.qos_path, req_body,
                                            content_type=self.contenttype)
        resp_body = wsgi.Serializer().deserialize(index_response.body,
                                                  self.contenttype)
        rename_req_body = jsonutils.dumps({
            'qos': {
                'qos_name': 'cisco_rename_qos',
                'qos_desc': {
                    'PPS': 50,
                    'TTL': 5,
                },
            },
        })
        rename_path_temp = (self.qos_second_path +
                            resp_body['qoss']['qos']['id'])
        rename_path = str(rename_path_temp)
        rename_response = self.test_app.put(rename_path, rename_req_body,
                                            content_type=self.contenttype)
        self.assertEqual(200, rename_response.status_int)
        rename_resp_dict = wsgi.Serializer().deserialize(rename_response.body,
                                                         self.contenttype)
        self.assertEqual(rename_resp_dict['qoss']['qos']['name'],
                         'cisco_rename_qos')
        self.tearDownQos(rename_path)
        LOG.debug("test_update_qos - END")
开发者ID:Frostman,项目名称:quantum,代码行数:31,代码来源:test_cisco_extension.py


示例5: test_update_credential

    def test_update_credential(self):

        """ Test update credential """

        LOG.debug("test_update_credential - START")
        req_body = jsonutils.dumps(self.test_credential_data)

        index_response = self.test_app.post(
            self.credential_path, req_body,
            content_type=self.contenttype)
        resp_body = wsgi.Serializer().deserialize(
            index_response.body, self.contenttype)
        rename_req_body = jsonutils.dumps({
            'credential': {
                'credential_name': 'cred3',
                'user_name': 'RenamedUser',
                'password': 'Renamedpassword',
            },
        })
        rename_path_temp = (self.cred_second_path +
                            resp_body['credentials']['credential']['id'])
        rename_path = str(rename_path_temp)
        rename_response = self.test_app.put(rename_path, rename_req_body,
                                            content_type=self.contenttype)
        rename_resp_dict = wsgi.Serializer().deserialize(rename_response.body,
                                                         self.contenttype)
        self.assertEqual(rename_resp_dict['credentials']['credential']['name'],
                         'cred3')
        self.assertEqual(
            rename_resp_dict['credentials']['credential']['password'],
            self.test_credential_data['credential']['password'])
        self.assertEqual(200, rename_response.status_int)
        # Clean Up - Delete the Credentials
        self.tearDownCredential(rename_path)
        LOG.debug("test_update_credential - END")
开发者ID:Frostman,项目名称:quantum,代码行数:35,代码来源:test_cisco_extension.py


示例6: __call__

    def __call__(self, target, creds):
        """
        Check http: rules by calling to a remote server.

        This example implementation simply verifies that the response
        is exactly 'True'.
        """

        url = ("http:" + self.match) % target
        data = {"target": jsonutils.dumps(target), "credentials": jsonutils.dumps(creds)}
        post_data = urllib.urlencode(data)
        f = urllib2.urlopen(url, post_data)
        return f.read() == "True"
开发者ID:habuka036,项目名称:quantum,代码行数:13,代码来源:policy.py


示例7: _check_http

    def _check_http(self, match, target_dict, cred_dict):
        """Check http: rules by calling to a remote server.

        This example implementation simply verifies that the response is
        exactly 'True'. A custom brain using response codes could easily
        be implemented.

        """
        url = match % target_dict
        data = {"target": jsonutils.dumps(target_dict), "credentials": jsonutils.dumps(cred_dict)}
        post_data = urllib.urlencode(data)
        f = urllib2.urlopen(url, post_data)
        return f.read() == "True"
开发者ID:xchenum,项目名称:quantum-bug,代码行数:13,代码来源:policy.py


示例8: _pack_json_msg

    def _pack_json_msg(self, msg):
        """Qpid cannot serialize dicts containing strings longer than 65535
           characters.  This function dumps the message content to a JSON
           string, which Qpid is able to handle.

        :param msg: May be either a Qpid Message object or a bare dict.
        :returns: A Qpid Message with its content field JSON encoded.
        """
        try:
            msg.content = jsonutils.dumps(msg.content)
        except AttributeError:
            # Need to have a Qpid message so we can set the content_type.
            msg = qpid_messaging.Message(jsonutils.dumps(msg))
        msg.content_type = JSON_CONTENT_TYPE
        return msg
开发者ID:Apsu,项目名称:quantum,代码行数:15,代码来源:impl_qpid.py


示例9: _bands_handler

 def _bands_handler(req, res):
     #NOTE: This only handles JSON responses.
     # You can use content type header to test for XML.
     data = jsonutils.loads(res.body)
     data['FOXNSOX:big_bands'] = 'Pig Bands!'
     res.body = jsonutils.dumps(data)
     return res
开发者ID:FreescaleSemiconductor,项目名称:quantum,代码行数:7,代码来源:foxinsocks.py


示例10: _goose_handler

 def _goose_handler(req, res):
     #NOTE: This only handles JSON responses.
     # You can use content type header to test for XML.
     data = jsonutils.loads(res.body)
     data['FOXNSOX:googoose'] = req.GET.get('chewing')
     res.body = jsonutils.dumps(data)
     return res
开发者ID:FreescaleSemiconductor,项目名称:quantum,代码行数:7,代码来源:foxinsocks.py


示例11: test_returns_404_for_non_existent_resource

    def test_returns_404_for_non_existent_resource(self):
        action_name = "add_tweedle"
        action_params = dict(name="Beetle")
        req_body = jsonutils.dumps({action_name: action_params})

        response = self.extension_app.post("/asdf/1/action", req_body, content_type="application/json", status="*")
        self.assertEqual(404, response.status_int)
开发者ID:cuiwow,项目名称:quantum,代码行数:7,代码来源:test_extensions.py


示例12: test_handler_invalid_data

    def test_handler_invalid_data(self):
        network_id = 'cccccccc-cccc-cccc-cccc-cccccccccccc'
        ip_address = '192.168.x.x'
        lease_remaining = 120

        json_rep = jsonutils.dumps(
            dict(network_id=network_id,
                 lease_remaining=lease_remaining,
                 ip_address=ip_address))

        handler = mock.Mock()
        mock_sock = mock.Mock()
        mock_sock.recv.return_value = json_rep

        relay = dhcp_agent.DhcpLeaseRelay(handler)

        with mock.patch('quantum.openstack.common.'
                        'uuidutils.is_uuid_like') as validate:
            validate.return_value = False

            with mock.patch.object(dhcp_agent.LOG, 'warn') as log:

                relay._handler(mock_sock, mock.Mock())
                mock_sock.assert_has_calls(
                    [mock.call.recv(1024), mock.call.close()])
                self.assertFalse(handler.called)
                self.assertTrue(log.called)
开发者ID:ericwanghp,项目名称:quantum,代码行数:27,代码来源:test_dhcp_agent.py


示例13: __init__

    def __init__(self, session, callback, node_name, node_opts, link_name, link_opts):
        """Declare a queue on an amqp session.

        'session' is the amqp session to use
        'callback' is the callback to call when messages are received
        'node_name' is the first part of the Qpid address string, before ';'
        'node_opts' will be applied to the "x-declare" section of "node"
                    in the address string.
        'link_name' goes into the "name" field of the "link" in the address
                    string
        'link_opts' will be applied to the "x-declare" section of "link"
                    in the address string.
        """
        self.callback = callback
        self.receiver = None
        self.session = None

        addr_opts = {
            "create": "always",
            "node": {"type": "topic", "x-declare": {"durable": True, "auto-delete": True}},
            "link": {
                "name": link_name,
                "durable": True,
                "x-declare": {"durable": False, "auto-delete": True, "exclusive": False},
            },
        }
        addr_opts["node"]["x-declare"].update(node_opts)
        addr_opts["link"]["x-declare"].update(link_opts)

        self.address = "%s ; %s" % (node_name, jsonutils.dumps(addr_opts))

        self.reconnect(session)
开发者ID:xchenum,项目名称:quantum-bug,代码行数:32,代码来源:impl_qpid.py


示例14: test_update_qos

    def test_update_qos(self):
        """ Test update qos """

        LOG.debug("test_update_qos - START")
        req_body = jsonutils.dumps(self.test_qos_data)
        index_response = self.test_app.post(self.qos_path, req_body, content_type=self.contenttype)
        resp_body = wsgi.Serializer().deserialize(index_response.body, self.contenttype)
        rename_req_body = jsonutils.dumps({"qos": {"qos_name": "cisco_rename_qos", "qos_desc": {"PPS": 50, "TTL": 5}}})
        rename_path_temp = self.qos_second_path + resp_body["qoss"]["qos"]["id"]
        rename_path = str(rename_path_temp)
        rename_response = self.test_app.put(rename_path, rename_req_body, content_type=self.contenttype)
        self.assertEqual(200, rename_response.status_int)
        rename_resp_dict = wsgi.Serializer().deserialize(rename_response.body, self.contenttype)
        self.assertEqual(rename_resp_dict["qoss"]["qos"]["name"], "cisco_rename_qos")
        self.tearDownQos(rename_path)
        LOG.debug("test_update_qos - END")
开发者ID:nibalizer,项目名称:quantum,代码行数:16,代码来源:test_cisco_extension.py


示例15: create_port

def create_port(tenant, network, port_init_state, **params):
    # Check initial state -- this throws an exception if the port state is
    # invalid
    check_port_state(port_init_state)

    controller = params["controller"]

    ls_uuid = network

    admin_status = True
    if port_init_state == "DOWN":
        admin_status = False
    lport_obj = {"admin_status_enabled": admin_status}

    path = "/ws.v1/lswitch/" + ls_uuid + "/lport"
    try:
        resp_obj = do_single_request("POST",
                                     path,
                                     jsonutils.dumps(lport_obj),
                                     controller=controller)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Network not found, Error: %s" % str(e))
        raise exception.NetworkNotFound(net_id=network)
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()

    result = jsonutils.loads(resp_obj)
    result['port-op-status'] = get_port_status(controller, ls_uuid,
                                               result['uuid'])
    return result
开发者ID:LuizOz,项目名称:quantum,代码行数:30,代码来源:nvplib.py


示例16: update_port

def update_port(network, port_id, **params):
    controller = params["controller"]
    lport_obj = {}

    if "state" in params:
        state = params["state"]
        check_port_state(state)
        admin_status = True
        if state == "DOWN":
            admin_status = False
        lport_obj["admin_status_enabled"] = admin_status

    uri = "/ws.v1/lswitch/" + network + "/lport/" + port_id
    try:
        resp_obj = do_single_request("PUT",
                                     uri,
                                     jsonutils.dumps(lport_obj),
                                     controller=controller)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port or Network not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port_id, net_id=network)
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()

    obj = jsonutils.loads(resp_obj)
    obj["port-op-status"] = get_port_status(controller, network, obj["uuid"])
    return obj
开发者ID:LuizOz,项目名称:quantum,代码行数:27,代码来源:nvplib.py


示例17: format

    def format(self, record):
        message = {
            "message": record.getMessage(),
            "asctime": self.formatTime(record, self.datefmt),
            "name": record.name,
            "msg": record.msg,
            "args": record.args,
            "levelname": record.levelname,
            "levelno": record.levelno,
            "pathname": record.pathname,
            "filename": record.filename,
            "module": record.module,
            "lineno": record.lineno,
            "funcname": record.funcName,
            "created": record.created,
            "msecs": record.msecs,
            "relative_created": record.relativeCreated,
            "thread": record.thread,
            "thread_name": record.threadName,
            "process_name": record.processName,
            "process": record.process,
            "traceback": None,
        }

        if hasattr(record, "extra"):
            message["extra"] = record.extra

        if record.exc_info:
            message["traceback"] = self.formatException(record.exc_info)

        return jsonutils.dumps(message)
开发者ID:polalis,项目名称:quantum,代码行数:31,代码来源:log.py


示例18: lease_update

    def lease_update(cls):
        network_id = os.environ.get(cls.QUANTUM_NETWORK_ID_KEY)
        dhcp_relay_socket = os.environ.get(cls.QUANTUM_RELAY_SOCKET_PATH_KEY)

        action = sys.argv[1]
        if action not in ("add", "del", "old"):
            sys.exit()

        mac_address = sys.argv[2]
        ip_address = sys.argv[3]

        if action == "del":
            lease_remaining = 0
        else:
            lease_remaining = int(os.environ.get("DNSMASQ_TIME_REMAINING", 0))

        data = dict(
            network_id=network_id, mac_address=mac_address, ip_address=ip_address, lease_remaining=lease_remaining
        )

        if os.path.exists(dhcp_relay_socket):
            sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            sock.connect(dhcp_relay_socket)
            sock.send(jsonutils.dumps(data))
            sock.close()
开发者ID:lucian,项目名称:quantum,代码行数:25,代码来源:dhcp.py


示例19: test_handler_invalid_data

    def test_handler_invalid_data(self):
        network_id = 'cccccccc-cccc-cccc-cccc-cccccccccccc'
        ip_address = '192.168.x.x'
        lease_remaining = 120

        json_rep = jsonutils.dumps(
            dict(network_id=network_id,
                 lease_remaining=lease_remaining,
                 ip_address=ip_address))

        handler = mock.Mock()
        mock_sock = mock.Mock()
        mock_sock.recv.return_value = json_rep

        relay = dhcp_agent.DhcpLeaseRelay(handler)

        with mock.patch.object(relay, '_validate_field') as validate:
            validate.side_effect = ValueError

            with mock.patch.object(dhcp_agent.LOG, 'warn') as log:

                relay._handler(mock_sock, mock.Mock())
                mock_sock.assert_has_calls(
                    [mock.call.recv(1024), mock.call.close()])
                self.assertFalse(handler.called)
                self.assertTrue(log.called)
开发者ID:riverbedstingray,项目名称:quantum,代码行数:26,代码来源:test_dhcp_agent.py


示例20: format

    def format(self, record):
        message = {'message': record.getMessage(),
                   'asctime': self.formatTime(record, self.datefmt),
                   'name': record.name,
                   'msg': record.msg,
                   'args': record.args,
                   'levelname': record.levelname,
                   'levelno': record.levelno,
                   'pathname': record.pathname,
                   'filename': record.filename,
                   'module': record.module,
                   'lineno': record.lineno,
                   'funcname': record.funcName,
                   'created': record.created,
                   'msecs': record.msecs,
                   'relative_created': record.relativeCreated,
                   'thread': record.thread,
                   'thread_name': record.threadName,
                   'process_name': record.processName,
                   'process': record.process,
                   'traceback': None}

        if hasattr(record, 'extra'):
            message['extra'] = record.extra

        if record.exc_info:
            message['traceback'] = self.formatException(record.exc_info)

        return jsonutils.dumps(message)
开发者ID:kumarcv,项目名称:openstack-nf,代码行数:29,代码来源:log.py



注:本文中的quantum.openstack.common.jsonutils.dumps函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python jsonutils.loads函数代码示例发布时间:2022-05-26
下一篇:
Python importutils.import_object函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap