def __restcall(self, url, method='GET', fields=None, **kwargs): """ Uses urllib to read a data from a webservice, if self.xml_file_data = None, else returns the local file contents :type url: str :param url: url to call :param kwargs: :return: response data :rtype: str """ request_headers = generateRequestHeaders( default_headers = { 'Content-type': 'application/json', 'Accept': 'application/json' }) (data, response_headers, code) = httpRequest(url, method=method, headers=request_headers, fields=fields, timeout=self.timeout) return data
def __restcall(self, url, method='GET', fields=None, **kwargs): """ Uses urllib to read a data from a webservice, if self.xml_file_data = None, else returns the local file contents :type url: str :param url: url to call :param kwargs: :return: response data :rtype: str """ request_headers = generateRequestHeaders(default_headers={ 'Content-type': 'application/json', 'Accept': 'application/json' }) (data, response_headers, code) = httpRequest(url, method=method, headers=request_headers, fields=fields, timeout=self.timeout) return data
codes = OrderedDict() for host in appliances: logger.debug("Querying host: %s" % host) url = host request_headers = generateRequestHeaders( default_headers={ 'Content-type': 'text/xml', 'Accept': 'text/xml' }, auth_headers=generateBasicAuthHeader( self.config['USER'], self.config['PASS'])) logger.debug("request_headers: %s" % request_headers) (response, response_headers, code) = httpRequest(url, method='POST', headers=request_headers, fields=request, timeout=5000, verifySsl=self.config['VERIFY_SSL']) logger.debug("response: %s" % response) data[host] = response logger.debug("code: %s" % code) codes[host] = code logger.debug(data) for k in data: thisreply = None try: thisreply = xml2dict.parse(data[k]) if thisreply['rpc-reply'].has_key('execute-result'): if thisreply['rpc-reply']['execute-result'][ '@code'] != 'ok':
try: data = OrderedDict() codes = OrderedDict() for host in appliances: logging.debug("Querying host: %s" % host) url = host request_headers = generateRequestHeaders( default_headers={ 'Content-type': 'text/xml', 'Accept': 'text/xml' }, auth_headers=generateBasicAuthHeader(self.config['USER'], self.config['PASS']) ) logging.debug("request_headers: %s" % request_headers) (response, response_headers, code) = httpRequest(url, method='POST', headers=request_headers, fields=request, timeout=5000, verifySsl=self.config['VERIFY_SSL']) logging.debug("response: %s" % response) data[host] = response logging.debug("code: %s" % code) codes[host] = code logging.debug(data) for k in data: thisreply = None try: thisreply = xml2dict.parse(data[k]) if thisreply['rpc-reply'].has_key('execute-result'): if thisreply['rpc-reply']['execute-result']['@code'] != 'ok': logging.warn("Device: %s: %s %s" % (k, thisreply['rpc-reply']['execute-result']['@code'], "Request that failed: %s" % request))