本文整理匯總了Python中marklogic.connection.Connection類的典型用法代碼示例。如果您正苦於以下問題:Python Connection類的具體用法?Python Connection怎麽用?Python Connection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Connection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: instance_init
def instance_init(cls,host):
"""
Performs first-time initialization of a newly installed server.
:param host: The name or IP address of the host to initialize
"""
conn = Connection(host, None)
uri = "{0}://{1}:8001/admin/v1/init".format(conn.protocol,conn.host)
logger = logging.getLogger("marklogic")
logger.debug("Initializing {0}".format(host))
# This call is a little odd; we special case the 400 error that
# occurs if the host has alreadya been initialized.
try:
response = conn.post(uri,
content_type='application/x-www-form-urlencoded')
except UnexpectedManagementAPIResponse:
response = conn.response
if response.status_code == 400:
err = json.loads(response.text)
if "errorResponse" in err:
if "messageCode" in err["errorResponse"]:
if err["errorResponse"]["messageCode"] == "MANAGE-ALREADYINIT":
return Host(host)
raise
if response.status_code != 202:
raise UnexpectedManagementAPIResponse(response.text)
return Host(host)._set_just_initialized()
示例2: instance_admin
def instance_admin(cls,host,realm,admin,password):
"""
Initializes the security database of a newly initialized server.
:param host: The name or IP address of the host to initialize
:param realm: The security realm to install
:param admin: The name of the admin user
:param password: The password of the admin user
"""
conn = Connection(host, None)
payload = {
'admin-username': admin,
'admin-password': password,
'realm': realm
}
uri = "{0}://{1}:8001/admin/v1/instance-admin".format(
conn.protocol, conn.host)
logger = logging.getLogger("marklogic")
logger.debug("Initializing security for {0}".format(host))
# N.B. Can't use conn.post here because we don't need auth yet
response = requests.post(uri, json=payload,
headers={'content-type': 'application/json',
'accept': 'application/json'})
if response.status_code != 202:
raise UnexpectedManagementAPIResponse(response.text)
# From now on connections require auth...
conn = Connection(host, HTTPDigestAuth(admin, password))
data = json.loads(response.text)
conn.wait_for_restart(data["restart"]["last-startup"][0]["value"])
示例3: _get_server_config
def _get_server_config(self):
"""
Obtain the server configuration. This is the data necessary for
the first part of the handshake necessary to join a host to a
cluster. The returned data is not intended for introspection.
:return: The config. This is always XML.
"""
connection = Connection(self.host_name(), None)
uri = "http://{0}:8001/admin/v1/server-config".format(connection.host)
response = connection.get(uri, accept="application/xml")
if response.status_code != 200:
raise UnexpectedManagementAPIResponse(response.text)
return response.text # this is always XML
示例4: test_create
def test_create(self):
pem = ("-----BEGIN CERTIFICATE-----\n"
"MIIC3TCCAkYCCQCJtpKDQbobyTANBgkqhkiG9w0BAQsFADCBsjELMAkGA1UEBhMC\n"
"VVMxCzAJBgNVBAgMAlRYMQ8wDQYDVQQHDAZBdXN0aW4xHjAcBgNVBAoMFU1hcmtM\n"
"b2dpYyBDb3Jwb3JhdGlvbjEXMBUGA1UECwwOVFggRW5naW5lZXJpbmcxITAfBgNV\n"
"BAMMGE1hcmtMb2dpYyBUWCBFbmdpbmVlcmluZzEpMCcGCSqGSIb3DQEJARYabm9y\n"
"bWFuLndhbHNoQG1hcmtsb2dpYy5jb20wHhcNMTQwODI3MTkyMzQyWhcNMTUwODI3\n"
"MTkyMzQyWjCBsjELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAlRYMQ8wDQYDVQQHDAZB\n"
"dXN0aW4xHjAcBgNVBAoMFU1hcmtMb2dpYyBDb3Jwb3JhdGlvbjEXMBUGA1UECwwO\n"
"VFggRW5naW5lZXJpbmcxITAfBgNVBAMMGE1hcmtMb2dpYyBUWCBFbmdpbmVlcmlu\n"
"ZzEpMCcGCSqGSIb3DQEJARYabm9ybWFuLndhbHNoQG1hcmtsb2dpYy5jb20wgZ8w\n"
"DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJSo3wFMDvTV7Q+4NDDMu9aJZ6uK4l8b\n"
"ACIk5/Ug+MoST+CuIfeBlb2Y6dxNCwkADwVPpykslDcHYFygxFIcnHHVhgqZ0xzu\n"
"LPXBagXmHyj+mb6im1tkbqAxQ7gj/SDeCnQYRIwNRlGgWZJFViaYJH3CC8G/f16F\n"
"IhDyQS3h28W3AgMBAAEwDQYJKoZIhvcNAQELBQADgYEAWbidV4huPlf8Ac0c3Cbs\n"
"Nx2xogODSjNPKqwug0Y3jKx33uxeY7i9oParWSnVFkG0JYUZEfrO5fmtS6JSA1Lk\n"
"e3BioC9xgclEYFiDoZSARasL8hdNvu7v+EYZEnS43rR4M7CQiq/Tf50o4VjiVM9S\n"
"I0Bo+VZSaShQKipBEHS8sP8=\n"
"-----END CERTIFICATE-----\n")
connection = Connection.make_connection(tc.hostname, tc.admin, tc.password)
cert = Authority.create(connection, pem)
self.assertIsNotNone(cert)
self.assertEqual('true', cert.enabled())
self.assertIsNotNone(cert.properties())
cert.delete(connection)
示例5: test_load
def test_load(self):
connection = Connection.make_connection(tc.hostname, tc.admin, tc.password)
server = HttpServer("Manage", "Default")
self.assertEqual(server.server_name(), "Manage")
self.assertIsNotNone(server.read(connection))
self.assertEqual("http", server.server_type())
示例6: test_lookup
def test_lookup(self):
connection = Connection.make_connection(tc.hostname, tc.admin, tc.password)
server = Server.lookup(connection, "Manage")
self.assertIsNotNone(server)
self.assertEqual(server.server_name(), "Manage")
示例7: test_list
def test_list(self):
connection = Connection.make_connection(tc.hostname, tc.admin, tc.password)
names = Role.list(connection)
self.assertGreater(len(names), 65)
self.assertIn("admin", names)
示例8: test_lookup
def test_lookup(self):
connection = Connection.make_connection(tc.hostname, tc.admin, tc.password)
role = Role.lookup(connection, "admin")
self.assertIsNotNone(role)
self.assertEqual(role.role_name(), "admin")
示例9: test_template
def test_template(self):
connection = Connection.make_connection(tc.hostname, tc.admin, tc.password)
req = Request(countryName="US", stateOrProvinceName="TX",
localityName="Austin", organizationName="MarkLogic",
emailAddress="[email protected]",
version=0)
temp = Template("Test Template", "Test description", req)
self.assertEqual("Test Template", temp.template_name())
temp.create(connection)
names = Template.list(connection)
self.assertGreater(len(names), 0)
self.assertIn(temp.template_id(), names)
temp.set_template_name("New Name")
temp.set_template_description("New Description")
temp.update(connection)
self.assertIsNotNone(temp)
newtemp = Template.lookup(connection, temp.template_id())
self.assertEqual(temp.template_name(), newtemp.template_name())
temp.delete(connection)
self.assertIsNotNone(temp)
示例10: test_list
def test_list(self):
connection = Connection.make_connection(tc.hostname, tc.admin, tc.password)
privileges = Privilege.list(connection)
self.assertGreater(len(privileges), 300)
self.assertIn("execute|manage-admin", privileges)
示例11: test_lookup
def test_lookup(self):
connection = Connection.make_connection(tc.hostname, tc.admin, tc.password)
privilege = Privilege.lookup(connection, "manage-admin", "execute")
self.assertIsNotNone(privilege)
self.assertEqual(privilege.privilege_name(), "manage-admin")
示例12: test_lookup
def test_lookup(self):
connection = Connection.make_connection(tc.hostname, tc.admin, tc.password)
user = User.lookup(connection, "nobody")
self.assertIsNotNone(user)
self.assertEqual(user.user_name(), "nobody")
示例13: test_list
def test_list(self):
connection = Connection.make_connection(tc.hostname, tc.admin, tc.password)
users = User.list(connection)
self.assertGreater(len(users), 2)
self.assertIn("nobody", users)
示例14: test_lookup_action
def test_lookup_action(self):
connection = Connection.make_connection(tc.hostname, tc.admin, tc.password)
privilege = Privilege.lookup(connection, kind="execute", \
action="http://marklogic.com/xdmp/privileges/admin-module-write")
self.assertIsNotNone(privilege)
self.assertEqual(privilege.privilege_name(), "admin-module-write")
示例15: test_lookup
def test_lookup(self):
connection = Connection.make_connection(tc.hostname, tc.admin, tc.password)
names = Authority.list(connection)
auth = Authority.lookup(connection, names[0])
self.assertIsNotNone(auth)
self.assertEqual(auth.certificate_id(), names[0])