create resource nest
This commit is contained in:
parent
f55cfef16c
commit
e458ecc0c1
|
@ -152,6 +152,21 @@ class AdgClient:
|
||||||
raise Exception("Failed to create deadock resolver",
|
raise Exception("Failed to create deadock resolver",
|
||||||
res.stdout, res.args)
|
res.stdout, res.args)
|
||||||
|
|
||||||
|
def create_resource_nest(self, name: str, child_nest_name: str, location: int, envelope: int, system: str = ""):
|
||||||
|
if not system:
|
||||||
|
system = self.system_name
|
||||||
|
|
||||||
|
res = self._run(["crn",
|
||||||
|
"-s", f"{system}",
|
||||||
|
"-n", f"{name}",
|
||||||
|
"-c", f"{child_nest_name}",
|
||||||
|
"-l", f"{location}",
|
||||||
|
"-e", f"{envelope}"])
|
||||||
|
|
||||||
|
if res.returncode > 0:
|
||||||
|
raise Exception("Failed to create resource nest",
|
||||||
|
res.stdout, res.args)
|
||||||
|
|
||||||
def _create_unique_database_name(self, prefix: str) -> str:
|
def _create_unique_database_name(self, prefix: str) -> str:
|
||||||
MAX_ATTEMPTS = 100
|
MAX_ATTEMPTS = 100
|
||||||
databases = self.get_databases()
|
databases = self.get_databases()
|
||||||
|
|
1
cache.py
1
cache.py
|
@ -15,6 +15,7 @@ class Cache:
|
||||||
if name in self._cache:
|
if name in self._cache:
|
||||||
return path.abspath(path.join(self.dir, self._cache[name]))
|
return path.abspath(path.join(self.dir, self._cache[name]))
|
||||||
|
|
||||||
|
print(f"Trying to fetch driver: {name}")
|
||||||
try:
|
try:
|
||||||
driver = fetch.get_driver_by_exact_name(name)
|
driver = fetch.get_driver_by_exact_name(name)
|
||||||
file = fetch.download_driver(driver, self.dir)
|
file = fetch.download_driver(driver, self.dir)
|
||||||
|
|
5
main.py
5
main.py
|
@ -1,14 +1,17 @@
|
||||||
from adg_control import AdgClient, ADG_EXE, ADG_DIR
|
from adg_control import AdgClient, ADG_EXE, ADG_DIR
|
||||||
from parser import Parser
|
from parser import Parser
|
||||||
from cache import Cache
|
from cache import Cache
|
||||||
|
from sys import argv
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = Parser("./test")
|
print(argv[1])
|
||||||
|
parser = Parser(argv[1])
|
||||||
client = AdgClient(ADG_EXE, ADG_DIR)
|
client = AdgClient(ADG_EXE, ADG_DIR)
|
||||||
cache = Cache()
|
cache = Cache()
|
||||||
|
|
||||||
for command in parser.commands:
|
for command in parser.commands:
|
||||||
|
print(command.type)
|
||||||
command.execute(client, cache)
|
command.execute(client, cache)
|
||||||
|
|
||||||
|
|
||||||
|
|
25
parser.py
25
parser.py
|
@ -10,7 +10,8 @@ class CommandType(StrEnum):
|
||||||
NORMAL = auto(),
|
NORMAL = auto(),
|
||||||
NEWSYSTEM = auto(),
|
NEWSYSTEM = auto(),
|
||||||
HOTEL = auto(),
|
HOTEL = auto(),
|
||||||
DEADLOCK = auto()
|
DEADLOCK = auto(),
|
||||||
|
RESOURCENEST = auto(),
|
||||||
|
|
||||||
|
|
||||||
class Command():
|
class Command():
|
||||||
|
@ -28,6 +29,8 @@ class Command():
|
||||||
self._init_hotel(**kwargs)
|
self._init_hotel(**kwargs)
|
||||||
elif self.type == CommandType.DEADLOCK:
|
elif self.type == CommandType.DEADLOCK:
|
||||||
self._init_deadlock(**kwargs)
|
self._init_deadlock(**kwargs)
|
||||||
|
elif self.type == CommandType.RESOURCENEST:
|
||||||
|
self._init_resourcenest(**kwargs)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
raise Exception("Required argument not found!", e)
|
raise Exception("Required argument not found!", e)
|
||||||
|
|
||||||
|
@ -43,6 +46,8 @@ class Command():
|
||||||
self._execute_hotel(client, cache)
|
self._execute_hotel(client, cache)
|
||||||
case CommandType.DEADLOCK:
|
case CommandType.DEADLOCK:
|
||||||
self._execute_deadlock(client, cache)
|
self._execute_deadlock(client, cache)
|
||||||
|
case CommandType.RESOURCENEST:
|
||||||
|
self._execute_resourcenest(client, cache)
|
||||||
|
|
||||||
def _init_newdb(self, **kwargs):
|
def _init_newdb(self, **kwargs):
|
||||||
self.name = kwargs["name"]
|
self.name = kwargs["name"]
|
||||||
|
@ -99,6 +104,15 @@ class Command():
|
||||||
if "host_name" in kwargs:
|
if "host_name" in kwargs:
|
||||||
self.host_name = kwargs["host_name"]
|
self.host_name = kwargs["host_name"]
|
||||||
|
|
||||||
|
def _init_resourcenest(self, **kwargs):
|
||||||
|
print(kwargs)
|
||||||
|
self.name = kwargs["name"]
|
||||||
|
self.child_nest_name = kwargs["child_nest_name"]
|
||||||
|
self.location = kwargs["location"]
|
||||||
|
self.envelope = kwargs["envelope"]
|
||||||
|
if "system" in kwargs:
|
||||||
|
self.system = kwargs["system"]
|
||||||
|
|
||||||
def _execute_newdb(self, client: AdgClient, cache: Cache):
|
def _execute_newdb(self, client: AdgClient, cache: Cache):
|
||||||
client.create_database(self.name)
|
client.create_database(self.name)
|
||||||
|
|
||||||
|
@ -150,6 +164,15 @@ class Command():
|
||||||
system=self.system if hasattr(self, "system") else ""
|
system=self.system if hasattr(self, "system") else ""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _execute_resourcenest(self, client: AdgClient, cache: Cache):
|
||||||
|
client.create_resource_nest(
|
||||||
|
self.name,
|
||||||
|
self.child_nest_name,
|
||||||
|
self.location,
|
||||||
|
self.envelope,
|
||||||
|
system=self.system if hasattr(self, "system") else ""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Parser():
|
class Parser():
|
||||||
def __init__(self, path: str):
|
def __init__(self, path: str):
|
||||||
|
|
Loading…
Reference in New Issue