CloudLink: Przykład skryptu w języku Python przy użyciu interfejsu API Rest Cloudlink do pobierania kopii zapasowej Cloudlink

Samenvatting: Ten plik służy wyłącznie celom edukacyjnym i informacyjnym. Może być używany jako odniesienie podczas pisania skryptów automatyzacji CloudLink w języku Python. Firma Dell nie ponosi odpowiedzialności za wykonywanie tego pliku w środowisku klienta firmy Dell. Ten skrypt pokazuje sposób pobierania pliku kopii zapasowej Cloudlink za pomocą skryptu w języku Python przy użyciu wywołań Cloudlink RestAPI. Ten skrypt dotyczy linii CloudLink 8.x. Skrypt nie zmienia stanu żadnego /, po prostu pobiera plik kopii zapasowej. Dostęp do węzła CloudLink (wskazywanego przez adres IP) jest przyznawany przy użyciu poświadczeń użytkownika secadmin Cloudlink. ...

Dit artikel is van toepassing op Dit artikel is niet van toepassing op Dit artikel is niet gebonden aan een specifiek product. Niet alle productversies worden in dit artikel vermeld.

Instructies

# Copyright Dell © 2025

# This file is for education / information purposes only.
# Can be used as a reference when writing Cloudlink automation scripts with Python language.
# Dell takes no responsibility for this file being executed in Dell Customer's environment

# The script shows a way to download Cloudlink backup file with a Python script using Cloudlink RestAPI calls.
# Ten skrypt ma zastosowanie do linii Cloudlink 8.x.
# The script doesn't alter state of any system, just downloads the backup file.
# Access to the Cloudlink node (indicated by IP address) is granted with credentials of a Cloudlink secadmin user.

import requests
import base64
import urllib3
import os

# Suppress only the single InsecureRequestWarning from urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

auth_url = "https://<cloudlink node ip>/cloudlink/oauth/token?grant_type=password&username=secadmin&password=<the password>&scope=all"

auth_response = requests.post(auth_url,timeout=1800, verify=False)

if auth_response.status_code == 200:
    # Parse the JSON response
    data = auth_response.json()
else:
    print(f"Error: {auth_response.status_code}")
    exit()

print("Auth token: "+data.get("access_token"))
access_token = data.get('access_token')

# Define the API endpoint
url = "https://<clc ip>:443/cloudlink/rest/backup"

# Define the headers (if needed)
headers = {
    "Authorization": "Bearer "+access_token,
    "Content-Type": "application/json"
}

# Make a GET request
response = requests.get(url, headers=headers, verify=False)

# Check the response status code
if response.status_code == 200:
    # Parse the JSON response
    data = response.json()
    print(data.get('file_name'))
else:
    print(f"Error: {response.status_code}")
    exit()

file_name = data.get('file_name')
file_content_base64 = data.get('file_content')

# Decode the base64 string to binary data
file_content_binary = base64.b64decode(file_content_base64)

# Save the binary data to a file
with open(str(file_name), "wb") as binary_file:
    binary_file.write(file_content_binary)

print("Backup has been saved to "+os.getcwd()+"\\"+str(file_name))

 

Artikeleigenschappen
Artikelnummer: 000330399
Artikeltype: How To
Laatst aangepast: 10 jun. 2025
Versie:  1
Vind antwoorden op uw vragen via andere Dell gebruikers
Support Services
Controleer of uw apparaat wordt gedekt door Support Services.