ADD: Some change for multiple tenant

This commit is contained in:
Сергей Филимонов 2025-02-05 22:55:03 +07:00
parent 426059daa4
commit 3f8b1fadd3
5 changed files with 31 additions and 23 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
config.py
config.yaml
__pycache__**
res.xml
.venv**

View File

19
app.py
View File

@ -1,19 +1,16 @@
import config
import cloud
import cloudad
import yaml
#import cloud
c = cloud.cloud(config.API_TOKEN)
a = cloudad.AD()
#r = a.getUserInfo("M-kab4", "sAMAccountName", ['sAMAccountName', "cn", "mail", "Enabled"])
#print(a.isDisabled("Esina.Svetlana1", "sAMAccountName"))
y = yaml.safe_load(open("config.yaml", "r"))
for r in c.getUserList():
print(r["name"], a.isDisabled(r["name"], "sAMAccountName"), a.isEnabled(r["name"], "sAMAccountName"))
print(dict(y[0]).keys())
for config in y:
print(config["SITE"])
# c = cloud.cloud(config.API_TOKEN)
# print(c.getVMList())
# print(c.getUserList())

View File

@ -1,21 +1,25 @@
import config
import requests
import xml.dom.minidom
class cloud:
def __init__(self, API_KEY: str):
def __init__(self, API_KEY: str, API_VERSION: str, SITE: str, TENANT: str):
'''
Запрос списка машин с перечнем атрибутов: Имя, ОС, IP-адрес, Состояние
На входе нужен 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 = {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
"Content-Length": "71"
}
data = "grant_type=refresh_token&refresh_token=" + config.API_TOKEN
data = "grant_type=refresh_token&refresh_token=" + self.API_TOKEN
try:
token = requests.post(url=url, headers=headers, data=data).json()['access_token']
@ -27,10 +31,10 @@ class cloud:
'''
Запрос списка машин с перечнем атрибутов: Имя, ОС, 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 = {
"Accept": "application/*;version=" + config.API_VERSION,
"Accept": "application/*;version=" + self.API_VERSION,
"Authorization": "Bearer " + self.__access_token
}
@ -44,6 +48,7 @@ class cloud:
"status": e.attributes['status'].value}
for e in dom.getElementsByTagName("VMRecord")]
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 = {
"Accept": "application/*;version=" + config.API_VERSION,
"Accept": "application/*;version=" + self.API_VERSION,
"Authorization": "Bearer " + self.__access_token
}

5
test.py Normal file
View File

@ -0,0 +1,5 @@
import yaml
y = yaml.safe_load(open("config.yaml", 'r'))
print(y)