def create_via_v3_post(ip, endpoint, password, body): # Make the API call parameters = RequestParameters(uri=create_v3_url(ip, f"{endpoint}"), username="******", password=password, method="post", payload=json.dumps(body), files=None) rest_client = RESTClient(parameters) resp = rest_client.request() INFO(f"create_via_v3_post: {ip}, {endpoint}") return resp
def update_via_v3_put(ip, endpoint, password, entity_uuid, body): # Make the API call parameters = RequestParameters(uri=create_v3_url( ip, f"{endpoint}/{entity_uuid}"), username="******", password=password, method="put", payload=json.dumps(body), files=None) rest_client = RESTClient(parameters) resp = rest_client.request() INFO(f"update_via_v3_put: {ip}, {endpoint}, {entity_uuid}") # Return the response return resp
def body_via_v3_get(ip, endpoint, password, entity_uuid): # Make the API call parameters = RequestParameters(uri=create_v3_url( ip, f"{endpoint}/{entity_uuid}"), username="******", password=password, method="get", payload=None, files=None) rest_client = RESTClient(parameters) resp = rest_client.request() INFO(f"body_via_v3_get: {ip}, {endpoint}, {entity_uuid}") # Return the response return resp
def create_via_v3_post(ip, endpoint, password, body): """Create a new entity via a v3 post call, return the response""" # Make the API call parameters = RequestParameters( uri=create_v3_url(ip, f"{endpoint}"), username="******", password=password, method="post", payload=json.dumps(body), files=None, ) rest_client = RESTClient(parameters) resp = rest_client.request() print(f"create_via_v3_post: {ip}, {endpoint}") return resp
def del_via_v3_delete(ip, endpoint, password, entity_uuid): """Delete a given entity with a DELETE""" # Make the API call parameters = RequestParameters(uri=create_v3_url( ip, f"{endpoint}/{entity_uuid}"), username="******", password=password, method="delete", payload=None, files=None) rest_client = RESTClient(parameters) resp = rest_client.request() INFO(f"del_via_v3_delete: {ip}, {endpoint}, {entity_uuid}") # Return the response return resp
def upload_bp_via_v3_post(ip, password, body, filename): # Create the file dictionary files = {"file": open(f"blueprints/{filename}", "rb")} # Make the API call parameters = RequestParameters(uri=create_v3_url(ip, "blueprints/import_file"), username="******", password=password, method="post", payload=body, files=files) rest_client = RESTClient(parameters) resp = rest_client.request() INFO(f"upload_bp_via_v3_post: {ip}, {body}") return resp
def update_via_v1_put(ip, endpoint, password, entity, body): """Update a given entity with a PUT""" # Make the API call parameters = RequestParameters( uri=create_v1_url(ip, f"{endpoint}/{entity}"), username="******", password=password, method="put", payload=json.dumps(body), files=None, ) rest_client = RESTClient(parameters) resp = rest_client.request() print(f"update_via_v1_put: {ip}, {endpoint}, {entity}") # Return the response return resp
def body_via_v3_post(ip, endpoint, password, payload): # Determine payload if payload is None: payload = {"length": 100} # Make the API call parameters = RequestParameters(uri=create_v3_url(ip, f"{endpoint}/list"), username="******", password=password, method="post", payload=json.dumps(payload), files=None) rest_client = RESTClient(parameters) resp = rest_client.request() INFO(f"body_via_v3_post: {ip}, {endpoint}") # Return the response return resp
def uuid_via_v3_post(ip, endpoint, password, entity_name): # Make the API call parameters = RequestParameters(uri=create_v3_url(ip, f"{endpoint}/list"), username="******", password=password, method="post", payload="{\"length\": 100}", files=None) rest_client = RESTClient(parameters) resp = rest_client.request() INFO(f"uuid_via_v3_post: {ip}, {endpoint}, {entity_name}") # Return UUID for entity in resp.json["entities"]: if entity_name == "": return entity["metadata"]["uuid"] elif entity["status"]["name"] == entity_name: return entity["metadata"]["uuid"]
def upload_icon_via_v3_post(ip, password, body, icon): # Create the file dictionary files = { "image": (icon["name"], open(f"images/{icon['file']}", "rb"), "image/png") } # Make the API call parameters = RequestParameters(uri=create_v3_url(ip, "app_icons/upload"), username="******", password=password, method="post", payload=body, files=files) rest_client = RESTClient(parameters) resp = rest_client.request() INFO(f"upload_icon_via_v3_post: {ip}, {body}") return resp
def uuid_via_v3_post(ip, endpoint, password, entity_name): """Return the UUID of a desired entity. If entity_name is empty assume a single entity in response and send first UUID""" # Make the API call parameters = RequestParameters( uri=create_v3_url(ip, f"{endpoint}/list"), username="******", password=password, method="post", payload='{"length": 100}', files=None, ) rest_client = RESTClient(parameters) resp = rest_client.request() print(f"uuid_via_v3_post: {ip}, {endpoint}, {entity_name}") # Return UUID for entity in resp.json["entities"]: if entity_name == "": return entity["metadata"]["uuid"] elif entity["status"]["name"] == entity_name: return entity["metadata"]["uuid"]