本文整理汇总了Python中quantum.openstack.common.jsonutils.dumps函数的典型用法代码示例。如果您正苦于以下问题:Python dumps函数的具体用法?Python dumps怎么用?Python dumps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dumps函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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")
示例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")
示例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")
示例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")
示例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"
示例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"
示例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
示例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
示例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
示例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)
示例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)
示例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)
示例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")
示例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