Compare commits

..

2 Commits

Author SHA1 Message Date
Emilia Allison e458ecc0c1
create resource nest 2024-02-12 13:19:03 -05:00
Emilia Allison f55cfef16c
old idk 2024-02-12 12:08:03 -05:00
6 changed files with 49 additions and 8 deletions

View File

@ -152,6 +152,21 @@ class AdgClient:
raise Exception("Failed to create deadock resolver",
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:
MAX_ATTEMPTS = 100
databases = self.get_databases()

View File

@ -15,6 +15,7 @@ class Cache:
if name in self._cache:
return path.abspath(path.join(self.dir, self._cache[name]))
print(f"Trying to fetch driver: {name}")
try:
driver = fetch.get_driver_by_exact_name(name)
file = fetch.download_driver(driver, self.dir)

View File

@ -1,5 +1,6 @@
import requests
from os import path
from adg_control import ADG_DIR
class DriverUrl:
@ -35,7 +36,7 @@ def get_driver_by_exact_name(name: str) -> DriverUrl:
try:
res = next(driver for driver in drivers if driver.name == name)
except StopIteration:
raise Exception("Driver not found")
raise Exception("Driver not found", name)
return res
@ -98,6 +99,8 @@ def download_driver(driver: DriverUrl, dir: str):
for chunk in res.iter_content(chunk_size=128):
file.write(chunk)
return file_name
def read_credentials() -> (str, str):
token = ""

View File

@ -1,14 +1,17 @@
from adg_control import AdgClient, ADG_EXE, ADG_DIR
from parser import Parser
from cache import Cache
from sys import argv
def main():
parser = Parser("./test")
print(argv[1])
parser = Parser(argv[1])
client = AdgClient(ADG_EXE, ADG_DIR)
cache = Cache()
for command in parser.commands:
print(command.type)
command.execute(client, cache)

View File

@ -10,7 +10,8 @@ class CommandType(StrEnum):
NORMAL = auto(),
NEWSYSTEM = auto(),
HOTEL = auto(),
DEADLOCK = auto()
DEADLOCK = auto(),
RESOURCENEST = auto(),
class Command():
@ -28,6 +29,8 @@ class Command():
self._init_hotel(**kwargs)
elif self.type == CommandType.DEADLOCK:
self._init_deadlock(**kwargs)
elif self.type == CommandType.RESOURCENEST:
self._init_resourcenest(**kwargs)
except KeyError as e:
raise Exception("Required argument not found!", e)
@ -43,6 +46,8 @@ class Command():
self._execute_hotel(client, cache)
case CommandType.DEADLOCK:
self._execute_deadlock(client, cache)
case CommandType.RESOURCENEST:
self._execute_resourcenest(client, cache)
def _init_newdb(self, **kwargs):
self.name = kwargs["name"]
@ -99,6 +104,15 @@ class Command():
if "host_name" in kwargs:
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):
client.create_database(self.name)
@ -116,6 +130,7 @@ class Command():
else:
abs_path = cache.get(self.device)
package_path = ntpath.relpath(abs_path, start=ADG_DIR)
print(abs_path, package_path)
client.create_normal_resource(
self.name,
@ -149,6 +164,15 @@ class Command():
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():
def __init__(self, path: str):

5
test
View File

@ -1,5 +0,0 @@
newdb;name=horsedb
newsystem;
normal;name=PlateOrient 1.1;location=0;envelope=1;device=HRB.PlateOrient
hotel;name=PlateHotel 1.1;location=100;envelope=1;rows=8;storage_type=random
deadlock;name = Deadlock Resolver 1.1;location=70;envelope=1