本文整理匯總了Python中ansible.module_utils.urls.fetch_url方法的典型用法代碼示例。如果您正苦於以下問題:Python urls.fetch_url方法的具體用法?Python urls.fetch_url怎麽用?Python urls.fetch_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ansible.module_utils.urls
的用法示例。
在下文中一共展示了urls.fetch_url方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def create(module, base_url, headers, index_set_id):
url = base_url
payload = {}
for key in ['title', 'description', 'remove_matches_from_default_stream', 'matching_type', 'rules']:
if module.params[key] is not None and module.params[key] != "":
payload[key] = module.params[key]
payload['index_set_id'] = index_set_id
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), method='POST', data=module.jsonify(payload))
if info['status'] != 201:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例2: create_rule
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def create_rule(module, base_url, headers):
url = "/".join([base_url, module.params['stream_id'], "rules"])
payload = {}
for key in ['field', 'type', 'value', 'inverted', 'description']:
if module.params[key] is not None:
payload[key] = module.params[key]
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), method='POST', data=module.jsonify(payload))
if info['status'] != 201:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例3: list
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def list(module, base_url, headers, stream_id):
if stream_id is not None:
url = "/".join([base_url, stream_id])
else:
url = base_url
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), method='GET')
if info['status'] != 200:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例4: default_index_set
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def default_index_set(module, endpoint, base_url, headers):
url = "https://%s/api/system/indices/index_sets?skip=0&limit=0&stats=false" % (endpoint)
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), method='GET')
if info['status'] != 200:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
indices = json.loads(content)
except AttributeError:
content = info.pop('body', '')
default_index_set_id = ""
if indices is not None:
default_index_set_id = indices['index_sets'][0]['id']
return default_index_set_id
示例5: list_configurations
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def list_configurations(module, configuration_url, headers, configuration_id, query):
if configuration_id is not None and configuration_id != "":
url = "/".join([configuration_url, configuration_id])
elif query == "yes" and configuration_id == "":
url = "/".join([configuration_url, "0"])
else:
url = configuration_url
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), method='GET')
if info['status'] != 200:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例6: update_snippet
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def update_snippet(module, configuration_url, headers, configuration_id, snippet_id):
url = "/".join([configuration_url, configuration_id, "snippets", snippet_id])
payload = {}
for key in ['backend', 'snippet_name', 'snippet_source']:
if module.params[key] is not None:
payload[key] = module.params[key]
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), method='PUT', data=module.jsonify(payload))
if info['status'] != 202:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例7: create
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def create(module, pipeline_url, headers):
url = pipeline_url
payload = {}
for key in ['title', 'description', 'source']:
if module.params[key] is not None:
payload[key] = module.params[key]
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), timeout=20, method='POST', data=module.jsonify(payload))
if info['status'] != 200:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例8: create_connection
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def create_connection(module, connection_url, headers):
url = "/".join([connection_url, "to_pipeline"])
payload = {}
for key in ['pipeline_id', 'stream_ids']:
if module.params[key] is not None:
payload[key] = module.params[key]
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), method='POST', data=module.jsonify(payload))
if info['status'] != 200:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例9: parse_rule
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def parse_rule(module, rule_url, headers):
url = "/".join([rule_url, "parse"])
payload = {}
for key in ['source']:
if module.params[key] is not None:
payload[key] = module.params[key]
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), timeout=20, method='POST', data=module.jsonify(payload))
if info['status'] != 200:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例10: create_rule
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def create_rule(module, rule_url, headers):
url = rule_url
payload = {}
for key in ['title', 'description', 'source']:
if module.params[key] is not None:
payload[key] = module.params[key]
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), timeout=20, method='POST', data=module.jsonify(payload))
if info['status'] != 200:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例11: update_connection
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def update_connection(module, connection_url, headers):
url = "/".join([connection_url, "to_pipeline"])
payload = {}
for key in ['pipeline_id', 'stream_ids']:
if module.params[key] is not None:
payload[key] = module.params[key]
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), method='POST', data=module.jsonify(payload))
if info['status'] != 200:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例12: update_rule
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def update_rule(module, rule_url, headers):
url = "/".join([rule_url, module.params['rule_id']])
payload = {}
for key in ['title', 'description', 'source']:
if module.params[key] is not None:
payload[key] = module.params[key]
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), method='PUT', timeout=20, data=module.jsonify(payload))
if info['status'] != 200:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例13: list
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def list(module, pipeline_url, headers, pipeline_id, query):
if pipeline_id is not None and pipeline_id != "":
url = "/".join([pipeline_url, pipeline_id])
elif query == "yes" and pipeline_id == "":
url = "/".join([pipeline_url, "0"])
else:
url = pipeline_url
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), timeout=20, method='GET')
if info['status'] != 200:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例14: list_rules
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def list_rules(module, rule_url, headers, rule_id, query):
if rule_id is not None and rule_id != "":
url = "/".join([rule_url, rule_id])
elif query == "yes" and rule_id == "":
url = "/".join([rule_url, "0"])
else:
url = rule_url
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), timeout=20, method='GET')
if info['status'] != 200:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url
示例15: update
# 需要導入模塊: from ansible.module_utils import urls [as 別名]
# 或者: from ansible.module_utils.urls import fetch_url [as 別名]
def update(module, base_url, headers):
url = "/".join([base_url, module.params['id']])
payload = {}
for key in ['title', 'description', 'index_prefix', 'field_type_refresh_interval', 'writable', 'default',
'index_analyzer', 'shards', 'replicas', 'rotation_strategy_class', 'retention_strategy_class',
'rotation_strategy', 'retention_strategy', 'index_optimization_max_num_segments',
'index_optimization_disabled']:
if module.params[key] is not None:
payload[key] = module.params[key]
response, info = fetch_url(module=module, url=url, headers=json.loads(headers), method='PUT', data=module.jsonify(payload))
if info['status'] != 200:
module.fail_json(msg="Fail: %s" % ("Status: " + str(info['msg']) + ", Message: " + str(info['body'])))
try:
content = to_text(response.read(), errors='surrogate_or_strict')
except AttributeError:
content = info.pop('body', '')
return info['status'], info['msg'], content, url