def fromxml(self, xml): if isinstance(xml, str): xml = xml.decode('utf-8') doc = dom.parseString(xml.encode('utf-8')) xml_strip(doc) root = doc.documentElement self.id = root.getAttribute("id") self.name = root.getAttribute("name") for ch in root.firstChild.childNodes: self.meta[ch.nodeName] = self._walk_decode(ch) for ch in root.childNodes[1].childNodes: self.body[ch.nodeName] = self._walk_decode(ch)
def fromxml (self, xml): if isinstance(xml, str): xml = xml.decode('utf-8') doc = dom.parseString(xml.encode('utf-8')) xml_strip(doc) root = doc.documentElement self.id = root.getAttribute("id") self.name = root.getAttribute("name") for ch in root.firstChild.childNodes: self.meta[ch.nodeName] = self._walk_decode(ch) for ch in root.childNodes[1].childNodes: self.body[ch.nodeName] = self._walk_decode(ch)
def test_list_role_params(self): xmlfile = get_xml_file("list_role_params_response.xml") xml = parseString(open(xmlfile, "r").read()) xml = xml_strip(xml) parameters = self._queryenv._read_list_role_params_response(xml) self.assertFalse(parameters is None) #self.assertTrue(parametres.has_key("external_ips_to_allow_access_from")) self.assertEqual(parameters["external_ips_to_allow_access_from"].strip(), '')
def test_list_role_params(self): xmlfile = get_xml_file("list_role_params_response.xml") xml = parseString(open(xmlfile, "r").read()) xml = xml_strip(xml) parameters = self._queryenv._read_list_role_params_response(xml) self.assertFalse(parameters is None) #self.assertTrue(parametres.has_key("external_ips_to_allow_access_from")) self.assertEqual( parameters["external_ips_to_allow_access_from"].strip(), '')
def test_get_service_configuration_response(self): xmlfile = get_xml_file("get-service-configuration_response.xml") xml = xml_strip(parseString(open(xmlfile, "r").read())) ret = self._queryenv._read_get_service_configuration_response(xml, 'app') self.assertFalse(ret is None) self.assertTrue(type(ret.settings) is dict) self.assertTrue(len(ret.settings)) self.assertTrue('__defaults__' in ret.settings) self.assertTrue(type(ret.name) is type("")) self.assertEqual(ret.name, "app-test")
def test_get_service_configuration_response(self): xmlfile = get_xml_file("get-service-configuration_response.xml") xml = xml_strip(parseString(open(xmlfile, "r").read())) ret = self._queryenv._read_get_service_configuration_response( xml, 'app') self.assertFalse(ret is None) self.assertTrue(type(ret.settings) is dict) self.assertTrue(len(ret.settings)) self.assertTrue('__defaults__' in ret.settings) self.assertTrue(type(ret.name) is type("")) self.assertEqual(ret.name, "app-test")
def test_read_list_scripts_response(self): xmlfile = get_xml_file("list_scripts_response.xml") xml = parseString(open(xmlfile, "r").read()) xml = xml_strip(xml) scripts = self._queryenv._read_list_scripts_response(xml) script = scripts[0] self.assertFalse(scripts is None) self.assertEqual(len(scripts), 1) self.assertTrue(script.asynchronous) self.assertEqual(script.exec_timeout, 100) self.assertEqual(script.name, 'script_name') self.assertEqual(script.body.strip(), '')
def test_read_list_virtualhosts_response(self): xmlfile = get_xml_file("list_virtualhosts_response.xml") xml = parseString(open(xmlfile, "r").read()) xml = xml_strip(xml) vhosts = self._queryenv._read_list_virtualhosts_response(xml) vhost = vhosts[0] self.assertFalse(vhosts is None) self.assertEqual(len(vhosts), 2) self.assertEqual(vhost.hostname, 'gpanel.net') self.assertEqual(vhost.type, 'apache') self.assertEqual(vhost.raw, ''' ''') self.assertTrue(vhosts[1].https)
def test_read_list_ebs_mountpoints_response(self): xmlfile = get_xml_file("list_ebs_mountpoints_response.xml") xml = parseString(open(xmlfile, "r").read()) xml = xml_strip(xml) mountpoints = self._queryenv._read_list_ebs_mountpoints_response(xml) mountpoint = mountpoints[0] volumes = mountpoint.volumes volume = volumes[0] self.assertFalse(mountpoints is None) self.assertEqual(len(mountpoints), 2) self.assertEqual(mountpoint.name, "some_name_for_LVM") self.assertEqual(mountpoint.dir, "/mnt/storage1") self.assertTrue(mountpoint.create_fs) self.assertFalse(mountpoint.is_array) self.assertFalse(volumes is None) self.assertEqual(volume.volume_id, "vol-123451") self.assertEqual(volume.device, "/dev/sdb")
def test_list_roles(self): xmlfile = get_xml_file("list_roles_response.xml") xml = parseString(open(xmlfile, "r").read()) #print open(xmlfile, "r").read() xml = xml_strip(xml) roles = self._queryenv._read_list_roles_response(xml) role = roles[0] self.assertFalse(roles is None) self.assertEqual(len(roles), 2) self.assertEqual(role.behaviour, ['app', "mysql"]) self.assertEqual(role.name, "lamp-custom") hosts = role.hosts host = hosts[0] self.assertFalse(hosts is None) self.assertEqual(host.internal_ip, "211.31.14.198") self.assertEqual(host.external_ip, "211.31.14.198") self.assertTrue(host.replication_master) self.assertEqual(host.index, 1)
def test_get_https_certificate_response(self): xmlfile = get_xml_file("get_https_certificate_response.xml") xml = parseString(open(xmlfile, "r").read()) xml = xml_strip(xml) cert = self._queryenv._read_get_https_certificate_response(xml) self.assertFalse(cert is (None, None)) self.assertEqual( cert[0], """-----BEGIN CERTIFICATE----- MIICATCCAWoCCQDVWoPxl2kzdzANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0 cyBQdHkgTHRkMB4XDTEwMDYwNDEyMDcyNloXDTExMDYwNDEyMDcyNlowRTELMAkG A1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0 IFdpZGdpdHMgUHR5IEx0ZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA5DeJ DnVd/Jgb3bPh296l78V/T7kRG8IAejawlR25ikUXpG9DoaV05nDwDR+e3Hm/wvmY 7EwqOiVFtFc1Uoc6av34zIroEcGmwi+nnUAptpHOC/863VhuSehKf7lWkUbLz8OS NAJOj5c6jxKfasnkqxYEakhvXCe/N4NQWdnSaVUCAwEAATANBgkqhkiG9w0BAQUF AAOBgQAJ318EcccEM34pFsF5thGQfYU4yrTb2P+Xyg/bhNgByCc+agWh9MAXBF1G EEH5rvsHc1ocVXi69a45D+m0pV5ZJwSIrwo6ssViMpWmUfIStkmYm7qsRbNnIWkZ TuMUjy2djQJdeAadKNinJ5YXk2iU7XvxTzaqZAzdpv2/9G5Nbg== -----END CERTIFICATE----- """) self.assertEqual( cert[1], """-----BEGIN RSA PRIVATE KEY----- MIICXgIBAAKBgQDkN4kOdV38mBvds+Hb3qXvxX9PuREbwgB6NrCVHbmKRRekb0Oh pXTmcPANH57ceb/C+ZjsTCo6JUW0VzVShzpq/fjMiugRwabCL6edQCm2kc4L/zrd WG5J6Ep/uVaRRsvPw5I0Ak6PlzqPEp9qyeSrFgRqSG9cJ783g1BZ2dJpVQIDAQAB AoGBAKNtDY24CIUBHDtoPF4qE6QfRur9OT4qcBMUpOEztxFIJwUO1FymUo9O4uhS 830pBmSGPrdAV6Dp3f+lz754riBj1Hzk5kQuF6rAxoBspbqXQB30Pz1r6qWt9Sf2 DZqQ9278UZEtUQq90QzEjh3xAV5BxG1Qv+d3yyIVy1K5Pt7BAkEA957XKSdGpQW5 c2V6rUnfvLi/WeIx8xFFL1ohnPSBLhvP8Hc4zJGVVBnuX9RKEVVLCizRBLFK93uI nh0aGSa9hQJBAOvwmamWMkFH4aYymqZY5CRooxCG6Wv8MTQBhgGaLyGYX/CaHpRf Y5RCEWnXZJr/rAwnowLr8kh/MiZGIBWVHZECQQDBeSRYDU4PRke+OD4AA8aC6D7q defdKVNLSjsVLZ15b1WrZxvECsQIcDJmQbKVlHULQDUYW4Zdk/IMyGRJ3pEZAkEA jWaz4RQX6FHZJY7cameJy1w+phAE4ufQ4TcshddO+dZlYUAspYWJm3gBEaq6K76g 8OPsaTrZCKPafV+3qNemUQJACZ7FDJKmO9SLccpYIDTcMIhqgu2QseZwjJPjAMbg 0xHR3hyeMnkrjP9amXrbAxOwndCD10I6Tuw4Qj7t20p+hw== -----END RSA PRIVATE KEY----- """)
def test_get_https_certificate_response(self): xmlfile = get_xml_file("get_https_certificate_response.xml") xml = parseString(open(xmlfile, "r").read()) xml = xml_strip(xml) cert = self._queryenv._read_get_https_certificate_response(xml) self.assertFalse(cert is (None,None)) self.assertEqual(cert[0], """-----BEGIN CERTIFICATE----- MIICATCCAWoCCQDVWoPxl2kzdzANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB VTETMBEGA1UECBMKU29tZS1TdG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hvP8Hc4zJGVVBnuX9RKEVVLCizRBLFK93uI nh0aGSa9hQJBAOvwmamWMkFH4aYymqZY5CRooxCG6Wv8MTQBhgGaLyGYX/CaHpRf Y5RCEWnXZJr/rAwnowLr8kh/MiZGIBWVHZECQQDBeSRYDU4PRke+OD4AA8aC6D7q defdKVNLSjsVLZ15b1WrZxvECsQIcDJmQbKVlHULQDUYW4Zdk/IMyGRJ3pEZAkEA jWaz4RQX6FHZJY7cameJy1w+phAE4ufQ4TcshddO+dZlYUAspYWJm3gBEaq6K76g 8OPsaTrZCKPafV+3qNemUQJACZ7FDJKmO9SLccpYIDTcMIhqgu2QseZwjJPjAMbg 0xHR3hyeMnkrjP9amXrbAxOwndCD10I6Tuw4Qj7t20p+hw== -----END RSA PRIVATE KEY----- """)
if isinstance(e, urllib2.HTTPError): resp_body = e.read() if e.fp is not None else "" raise GoGridError( "Request failed. %s. URL: %s. Service message: %s" % (e, self.url, resp_body)) else: raise GoGridError("Cannot connect to GoGrid service. %s" % (e, )) else: try: xml = parseString(r.read()) except (Exception, BaseException), e: raise GoGridError("Response couldn't be parsed as XML. %s" % (e, )) else: return resp_reader(xml_strip(xml)) def list_servers(self, num_items=None, page=None, server_type=None, is_sandbox=None): p = dict() for k, v in locals().items(): if v: if k == "is_sandbox": k = "isSandbox" v = "true" elif k == "server_type": k = "server.type" p[k] = v
try: r = urllib2.urlopen(self._url + uri, urlencode(post_data)) except urllib2.URLError, e: if isinstance(e, urllib2.HTTPError): resp_body = e.read() if e.fp is not None else "" raise GoGridError("Request failed. %s. URL: %s. Service message: %s" % (e, self.url, resp_body)) else: raise GoGridError("Cannot connect to GoGrid service. %s" % (e,)) else: try: xml = parseString(r.read()) except (Exception, BaseException), e: raise GoGridError("Response couldn't be parsed as XML. %s" % (e,)) else: return resp_reader(xml_strip(xml)) def list_servers(self, num_items=None, page=None, server_type=None, is_sandbox=None): p = dict() for k, v in locals().items(): if v: if k == "is_sandbox": k = "isSandbox" v = "true" elif k == "server_type": k = "server.type" p[k] = v return self._request("/grid/server/list", p, self._list_servers_reader)
def test_get_latest_version_response(self): xmlfile = get_xml_file("get_latest_version_response.xml") xml = xml_strip(parseString(open(xmlfile, "r").read())) version = self._queryenv._read_get_latest_version_response(xml) self.assertFalse(version is None) self.assertEqual(version, "2009-03-05")
def test__read_list_farm_role_params_response(self): xmlfile = get_xml_file("list_farm_role_params_response.xml") xml = parseString(open(xmlfile, "r").read()) xml = xml_strip(xml) params = self._queryenv._read_list_farm_role_params_response(xml) print params