ADD: Some change for multiple tenant
This commit is contained in:
parent
426059daa4
commit
3f8b1fadd3
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
config.py
|
config.py
|
||||||
|
config.yaml
|
||||||
__pycache__**
|
__pycache__**
|
||||||
res.xml
|
res.xml
|
||||||
.venv**
|
.venv**
|
19
app.py
19
app.py
|
@ -1,19 +1,16 @@
|
||||||
import config
|
import yaml
|
||||||
import cloud
|
#import cloud
|
||||||
import cloudad
|
|
||||||
|
|
||||||
c = cloud.cloud(config.API_TOKEN)
|
y = yaml.safe_load(open("config.yaml", "r"))
|
||||||
a = cloudad.AD()
|
|
||||||
#r = a.getUserInfo("M-kab4", "sAMAccountName", ['sAMAccountName', "cn", "mail", "Enabled"])
|
|
||||||
#print(a.isDisabled("Esina.Svetlana1", "sAMAccountName"))
|
|
||||||
|
|
||||||
for r in c.getUserList():
|
print(dict(y[0]).keys())
|
||||||
print(r["name"], a.isDisabled(r["name"], "sAMAccountName"), a.isEnabled(r["name"], "sAMAccountName"))
|
|
||||||
|
for config in y:
|
||||||
|
print(config["SITE"])
|
||||||
|
# c = cloud.cloud(config.API_TOKEN)
|
||||||
|
|
||||||
|
|
||||||
# print(c.getVMList())
|
# print(c.getVMList())
|
||||||
|
|
||||||
# print(c.getUserList())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
21
cloud.py
21
cloud.py
|
@ -1,21 +1,25 @@
|
||||||
import config
|
|
||||||
import requests
|
import requests
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
|
|
||||||
class cloud:
|
class cloud:
|
||||||
def __init__(self, API_KEY: str):
|
def __init__(self, API_KEY: str, API_VERSION: str, SITE: str, TENANT: str):
|
||||||
'''
|
'''
|
||||||
Запрос списка машин с перечнем атрибутов: Имя, ОС, IP-адрес, Состояние
|
Запрос списка машин с перечнем атрибутов: Имя, ОС, IP-адрес, Состояние
|
||||||
На входе нужен Access Token получить который можно при помощи функции getAccessToken(API Token)
|
На входе нужен Access Token получить который можно при помощи функции getAccessToken(API Token)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
url = "https://" + config.SITE + "/oauth/tenant/" + config.TENANT + "/token"
|
self.API_KEY = API_KEY
|
||||||
|
self.API_VERSION = API_VERSION
|
||||||
|
self.SITE = SITE
|
||||||
|
self.TENANT = TENANT
|
||||||
|
|
||||||
|
url = "https://" + self.SITE + "/oauth/tenant/" + self.TENANT + "/token"
|
||||||
headers = {
|
headers = {
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
"Content-Length": "71"
|
"Content-Length": "71"
|
||||||
}
|
}
|
||||||
data = "grant_type=refresh_token&refresh_token=" + config.API_TOKEN
|
data = "grant_type=refresh_token&refresh_token=" + self.API_TOKEN
|
||||||
|
|
||||||
try:
|
try:
|
||||||
token = requests.post(url=url, headers=headers, data=data).json()['access_token']
|
token = requests.post(url=url, headers=headers, data=data).json()['access_token']
|
||||||
|
@ -27,10 +31,10 @@ class cloud:
|
||||||
'''
|
'''
|
||||||
Запрос списка машин с перечнем атрибутов: Имя, ОС, IP-адрес, Состояние
|
Запрос списка машин с перечнем атрибутов: Имя, ОС, IP-адрес, Состояние
|
||||||
'''
|
'''
|
||||||
url = "https://" + config.SITE + "/api/query/?type=vm&fields=name,detectedGuestOs,ipAddress,status&filter=isVAppTemplate==false"
|
url = "https://" + self.SITE + "/api/query/?type=vm&fields=name,detectedGuestOs,ipAddress,status&filter=isVAppTemplate==false"
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Accept": "application/*;version=" + config.API_VERSION,
|
"Accept": "application/*;version=" + self.API_VERSION,
|
||||||
"Authorization": "Bearer " + self.__access_token
|
"Authorization": "Bearer " + self.__access_token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +48,7 @@ class cloud:
|
||||||
"status": e.attributes['status'].value}
|
"status": e.attributes['status'].value}
|
||||||
for e in dom.getElementsByTagName("VMRecord")]
|
for e in dom.getElementsByTagName("VMRecord")]
|
||||||
|
|
||||||
|
|
||||||
def getUserList(self) -> list:
|
def getUserList(self) -> list:
|
||||||
'''
|
'''
|
||||||
Запрос списка пользователей
|
Запрос списка пользователей
|
||||||
|
@ -56,10 +61,10 @@ class cloud:
|
||||||
.....
|
.....
|
||||||
}]
|
}]
|
||||||
'''
|
'''
|
||||||
url = "https://" + config.SITE + "/api/query?type=user&fields=name,fullName,isEnabled"
|
url = "https://" + self.SITE + "/api/query?type=user&fields=name,fullName,isEnabled"
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Accept": "application/*;version=" + config.API_VERSION,
|
"Accept": "application/*;version=" + self.API_VERSION,
|
||||||
"Authorization": "Bearer " + self.__access_token
|
"Authorization": "Bearer " + self.__access_token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user