mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
Update f5 module_utils from downstream (#44092)
Upstreaming fixes and features for f5 module_utils as part of 2.7 dev cycle
This commit is contained in:
parent
cda3b53035
commit
96a6011b3f
3 changed files with 104 additions and 42 deletions
|
@ -19,7 +19,10 @@ from ansible.module_utils.urls import urllib_error
|
|||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.six import PY3
|
||||
|
||||
import json as _json
|
||||
try:
|
||||
import json as _json
|
||||
except ImportError:
|
||||
import simplejson as _json
|
||||
|
||||
try:
|
||||
from library.module_utils.network.f5.common import F5ModuleError
|
||||
|
@ -174,6 +177,18 @@ class Response(object):
|
|||
def json(self):
|
||||
return _json.loads(self._content)
|
||||
|
||||
@property
|
||||
def ok(self):
|
||||
if self.status is not None and int(self.status) > 400:
|
||||
return False
|
||||
try:
|
||||
response = self.json()
|
||||
if 'code' in response and response['code'] > 400:
|
||||
return False
|
||||
except ValueError:
|
||||
pass
|
||||
return True
|
||||
|
||||
|
||||
class iControlRestSession(object):
|
||||
"""Represents a session that communicates with a BigIP.
|
||||
|
@ -385,11 +400,33 @@ def download_file(client, url, dest):
|
|||
def upload_file(client, url, dest):
|
||||
"""Upload a file to an arbitrary URL.
|
||||
|
||||
This method is responsible for correctly chunking an upload request to an
|
||||
arbitrary file worker URL.
|
||||
|
||||
Arguments:
|
||||
client (object): The F5RestClient connection object.
|
||||
url (string): The URL to upload a file to.
|
||||
dest (string): The file to be uploaded.
|
||||
|
||||
Examples:
|
||||
The ``dest`` may be either an absolute or relative path. The basename
|
||||
of the path is used as the remote file name upon upload. For instance,
|
||||
in the example below, ``BIGIP-13.1.0.8-0.0.3.iso`` would be the name
|
||||
of the remote file.
|
||||
|
||||
The specified URL should be the full URL to where you want to upload a
|
||||
file. BIG-IP has many different URLs that can be used to handle different
|
||||
types of files. This is why a full URL is required.
|
||||
|
||||
>>> from ansible.module_utils.network.f5.icontrol import upload_client
|
||||
>>> url = 'https://{0}:{1}/mgmt/cm/autodeploy/software-image-uploads'.format(
|
||||
... self.client.provider['server'],
|
||||
... self.client.provider['server_port']
|
||||
... )
|
||||
>>> dest = '/path/to/BIGIP-13.1.0.8-0.0.3.iso'
|
||||
>>> upload_file(self.client, url, dest)
|
||||
True
|
||||
|
||||
Returns:
|
||||
bool: True on success. False otherwise.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue