mirror of
https://github.com/ThomasGsp/HyperProxmox.git
synced 2025-02-12 19:22:30 +00:00
Some small changes
This commit is contained in:
parent
7c37b1adaf
commit
579de2599a
3 changed files with 82 additions and 17 deletions
|
@ -10,23 +10,23 @@
|
|||
from core.modules.mod_proxmox import *
|
||||
from core.modules.mod_database import *
|
||||
from core.modules.mod_analyst import *
|
||||
from core.modules.mod_crawler import *
|
||||
from core.modules.mod_access import *
|
||||
from core.libs.hcrypt import *
|
||||
from netaddr import iter_iprange
|
||||
import threading
|
||||
import time
|
||||
|
||||
import base64
|
||||
|
||||
|
||||
def RunAnalyse(clusters_conf, generalconf, delay=300):
|
||||
play = Analyse(clusters_conf, generalconf)
|
||||
play = Crawler(clusters_conf, generalconf)
|
||||
|
||||
|
||||
while True:
|
||||
play.run()
|
||||
time.sleep(delay)
|
||||
|
||||
|
||||
class Core:
|
||||
|
||||
def __init__(self, generalconf, Lredis):
|
||||
|
@ -63,7 +63,7 @@ class Core:
|
|||
# INSTANCE MANAGEMENT #
|
||||
#######################
|
||||
"""
|
||||
def insert_instance(self, target, count=1, command_id=000000):
|
||||
def insert_instance(self, target, count=1, command_id=000000, instancetype="lxc"):
|
||||
|
||||
""" Find cluster informations from node """
|
||||
lastkeyvalid = self.mongo.get_last_datekey()
|
||||
|
@ -135,12 +135,12 @@ class Core:
|
|||
|
||||
""" INSTANCE INSERTION """
|
||||
result_new = proxmox.create_instance("{0}:{1}".format(proxmox_cluster_url,
|
||||
int(proxmox_cluster_port)), target, "lxc",
|
||||
int(proxmox_cluster_port)), target, instancetype,
|
||||
data)
|
||||
""" Get first digest """
|
||||
digest_init = proxmox.get_config("{0}:{1}".format(proxmox_cluster_url,
|
||||
int(proxmox_cluster_port)),
|
||||
target, "lxc", next_instance_id)['value']['data']['digest']
|
||||
target, instancetype, next_instance_id)['value']['data']['digest']
|
||||
|
||||
|
||||
""" VERIFY THE RESULT BY PROXMOX STATUS REQUEST CODE """
|
||||
|
@ -160,7 +160,7 @@ class Core:
|
|||
""" Limit creation DDOS based on digest """
|
||||
while digest_init == proxmox.get_config("{0}:{1}".format(proxmox_cluster_url,
|
||||
int(proxmox_cluster_port)),
|
||||
target, "lxc", next_instance_id)['value']['data']['digest']:
|
||||
target, instancetype, next_instance_id)['value']['data']['digest']:
|
||||
time.sleep(5)
|
||||
|
||||
returnlistresult.append(result_new)
|
||||
|
@ -170,7 +170,7 @@ class Core:
|
|||
|
||||
return
|
||||
|
||||
def delete_instance(self, vmid):
|
||||
def delete_instance(self, vmid, instancetype="lxc"):
|
||||
|
||||
try:
|
||||
""" Find node/cluster informations from vmid """
|
||||
|
@ -194,7 +194,8 @@ class Core:
|
|||
proxmox_cluster_pwd)
|
||||
|
||||
result = proxmox.delete_instance("{0}:{1}".format(proxmox_cluster_url,
|
||||
int(proxmox_cluster_port)), instance_informations['node'], "lxc", vmid)
|
||||
int(proxmox_cluster_port)),
|
||||
instance_informations['node'], instancetype, vmid)
|
||||
|
||||
if result['result'] == "OK":
|
||||
self.mongo.delete_instance(vmid)
|
||||
|
@ -209,7 +210,7 @@ class Core:
|
|||
|
||||
return result
|
||||
|
||||
def status_instance(self, vmid, action):
|
||||
def status_instance(self, vmid, action, instancetype="lxc"):
|
||||
""" Find node/cluster informations from vmid """
|
||||
try:
|
||||
instance_informations = self.mongo.get_instance(vmid)
|
||||
|
@ -234,7 +235,7 @@ class Core:
|
|||
result = proxmox.status_instance("{0}:{1}".format(proxmox_cluster_url,
|
||||
int(proxmox_cluster_port)),
|
||||
instance_informations['node'],
|
||||
"lxc",
|
||||
instancetype,
|
||||
vmid, action)
|
||||
|
||||
except IndexError as ierror:
|
||||
|
@ -246,7 +247,7 @@ class Core:
|
|||
|
||||
return result
|
||||
|
||||
def info_instance(self, vmid):
|
||||
def info_instance(self, vmid, instancetype="lxc"):
|
||||
""" Find node/cluster informations from vmid """
|
||||
try:
|
||||
instance_informations = self.mongo.get_instance(vmid)
|
||||
|
@ -271,7 +272,7 @@ class Core:
|
|||
result = proxmox.get_config("{0}:{1}".format(proxmox_cluster_url,
|
||||
int(proxmox_cluster_port)),
|
||||
instance_informations['node'],
|
||||
"lxc",
|
||||
instancetype,
|
||||
vmid)
|
||||
|
||||
except IndexError as ierror:
|
||||
|
@ -283,7 +284,7 @@ class Core:
|
|||
|
||||
return result
|
||||
|
||||
def change_instance(self, vmid, data):
|
||||
def change_instance(self, vmid, data, instancetype="lxc"):
|
||||
""" Find node/cluster informations from vmid """
|
||||
try:
|
||||
instance_informations = self.mongo.get_instance(vmid)
|
||||
|
@ -309,7 +310,7 @@ class Core:
|
|||
result = proxmox.resize_instance("{0}:{1}".format(proxmox_cluster_url,
|
||||
int(proxmox_cluster_port)),
|
||||
instance_informations['node'],
|
||||
"lxc",
|
||||
instancetype,
|
||||
vmid, data)
|
||||
|
||||
if result['result'] == "OK":
|
||||
|
|
|
@ -49,7 +49,7 @@ class Analyse:
|
|||
self.mongo.client = self.mongo.connect()
|
||||
self.mongo.db = self.mongo.client.db
|
||||
|
||||
def run(self):
|
||||
def run(self, instancetype="lxc"):
|
||||
insert_time = time.time()
|
||||
|
||||
self.mongo.insert_datekey(insert_time, 'running')
|
||||
|
@ -77,7 +77,7 @@ class Analyse:
|
|||
if value_nodes_list["node"] not in exclude_nodes:
|
||||
""" TOTAL COUNT CPU and RAM allocate"""
|
||||
list_instances = proxmox.get_instance("{0}:{1}".format(cluster["url"], int(cluster["port"])),
|
||||
value_nodes_list["node"], "lxc")["value"]
|
||||
value_nodes_list["node"], instancetype)["value"]
|
||||
|
||||
totalcpu = 0
|
||||
totalram = 0
|
||||
|
|
64
code/scripts/main/core/modules/mod_crawler.py
Normal file
64
code/scripts/main/core/modules/mod_crawler.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
"""
|
||||
Author: Tlams
|
||||
Langage: Python
|
||||
Minimum version require: 3.4
|
||||
|
||||
Module function:
|
||||
Crawl all node to update the database statistics
|
||||
"""
|
||||
|
||||
from core.modules.mod_proxmox import *
|
||||
from core.modules.mod_database import *
|
||||
from core.libs.hcrypt import *
|
||||
import time
|
||||
import operator
|
||||
import random
|
||||
import base64
|
||||
|
||||
|
||||
class Crawler:
|
||||
def __init__(self, clusters_conf, generalconf):
|
||||
"""
|
||||
:param clusters_conf: Proxmox configurations
|
||||
:param generalconf : General configuration
|
||||
"""
|
||||
self.generalconf = generalconf
|
||||
self.clusters_conf = clusters_conf
|
||||
|
||||
""" LOAD MONGODB """
|
||||
self.mongo = MongoDB(generalconf["mongodb"]["ip"])
|
||||
self.mongo.client = self.mongo.connect()
|
||||
self.mongo.db = self.mongo.client.db
|
||||
|
||||
def run(self, instancetype="lxc"):
|
||||
insert_time = time.time()
|
||||
|
||||
self.mongo.insert_datekey(insert_time, 'running')
|
||||
|
||||
for cluster in self.clusters_conf:
|
||||
""" Decode data """
|
||||
|
||||
proxmox_cluster_user = pdecrypt(base64.b64decode(cluster["user"]),
|
||||
self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8')
|
||||
|
||||
proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster["password"]),
|
||||
self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8')
|
||||
|
||||
""" AUTH """
|
||||
proxmox = Proxmox("Analyse")
|
||||
proxmox.get_ticket("{0}:{1}".format(cluster["url"], int(cluster["port"])), proxmox_cluster_user, proxmox_cluster_pwd)
|
||||
|
||||
""" UPDATE NODES LIST """
|
||||
nodes_list = proxmox.get_nodes("{0}:{1}".format(cluster["url"], int(cluster["port"])))
|
||||
if nodes_list["result"] == "OK":
|
||||
for value_nodes_list in nodes_list["value"]["data"]:
|
||||
""" TOTAL COUNT CPU and RAM allocate"""
|
||||
list_instances = proxmox.get_instance("{0}:{1}".format(cluster["url"], int(cluster["port"])),
|
||||
value_nodes_list["node"], instancetype)["value"]
|
||||
|
||||
for key_list_instances, value_list_instances in list_instances.items():
|
||||
for instances in value_list_instances:
|
||||
instances["node"] = value_nodes_list["node"]
|
||||
print(instances)
|
||||
|
||||
return
|
Loading…
Reference in a new issue