요청하신 페이지는 현재 사용 중인 언어로 제공되지 않습니다. Chrome에 내장된 번역 기능을 사용하면 어떤 웹페이지라도 원하는 언어로 즉시 번역할 수 있습니다.

Elastifile REST API using Python

 

This article is for those who are interesting on working with python to run REST API commands against the Elastifile system.

In the code below you can find a general process and some functions.
In addition to that, there is a description of each function in the comments.

You can always refer to 'REST API Docs' for more details under the following link from your Elastifile web interface:

REST API Docs Menu

 

#! /usr/bin/python
import requests, json, time
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

user = 'admin'
password = 'changeme'

SECURITY_PREFIX = b')]}\',\n'
login = {'user': {'login': user, 'password': password}}
headers = {'Content-type': 'application/json'}

ems_ip = '10.11.209.29'
dc_name = 'api'
size ='1000' #GB

size= int(size)*1024*1024*1024

# Creating a session against the Elastifile Management Server
response = requests.post ('https://{}/api/sessions'.format(ems_ip), data=json.dumps(login), headers=headers, timeout=10, verify=False)
cookies= response.cookies

# Creating a new data container
dc_payload = {'name':dc_name, 'soft_quota':size, 'hard_quota':size, 'policy_id':'1', 'dir_permissions':'755'}
new_dc = requests.post ('https://{}/api/data_containers'.format (ems_ip), data=json.dumps(dc_payload), headers=headers, timeout=10, cookies=cookies, verify= False)
time.sleep(20)
new_dc_output = json.loads(new_dc.content[len(SECURITY_PREFIX):])

# Creating a new export to the data container
export_payload = {'name':'root', 'path':'/', 'user_mapping':'remap_all', 'data_container_id':new_dc_output['id'], 'uid':'0', 'gid':'0'}
new_export = requests.post ('https://{}/api/exports'.format(ems_ip), data=json.dumps(export_payload), headers=headers, timeout=10, cookies=cookies, verify= False)

# Listing the data containers in the system
r = requests.get ('https://{}/api/data_containers'.format(ems_ip), cookies=cookies, verify= False)
content= r.content

data_containers = json.loads(content[len(SECURITY_PREFIX):])
for dc in range(0,len(data_containers)):
    print (str(data_containers[dc]['name']))

 

Was this helpful?

How can we improve it?
true
Search
Clear search
Close search
Main menu
6087395565989946071
true
Search Help Center
true
true
true
false
false