class and cli renaming
This commit is contained in:
parent
019f8a5e32
commit
915bcf1dca
|
@ -72,6 +72,7 @@ def main():
|
||||||
|
|
||||||
spr_addc = spr_action.add_parser("addclass", help="add a class")
|
spr_addc = spr_action.add_parser("addclass", help="add a class")
|
||||||
spr_addc.add_argument("cls", help="name of class to add")
|
spr_addc.add_argument("cls", help="name of class to add")
|
||||||
|
spr_addc.add_argument("-r", "--rename", help="rename class")
|
||||||
|
|
||||||
spr_delc = spr_action.add_parser("delclass", help="delete a class")
|
spr_delc = spr_action.add_parser("delclass", help="delete a class")
|
||||||
spr_delc.add_argument("cls", help="name of class to delete")
|
spr_delc.add_argument("cls", help="name of class to delete")
|
||||||
|
@ -130,7 +131,8 @@ def main():
|
||||||
print(r.get(args.host.rstrip("/") + "/api/class").text)
|
print(r.get(args.host.rstrip("/") + "/api/class").text)
|
||||||
|
|
||||||
elif args.action == "addclass":
|
elif args.action == "addclass":
|
||||||
r.put(args.host.rstrip("/") + "/api/class/" + args.cls).raise_for_status()
|
r.put(args.host.rstrip("/") + "/api/class/" + args.cls,
|
||||||
|
params={"rename": args.rename} if args.rename else None).raise_for_status()
|
||||||
|
|
||||||
elif args.action == "delclass":
|
elif args.action == "delclass":
|
||||||
r.delete(args.host.rstrip("/") + "/api/class/" + args.cls).raise_for_status()
|
r.delete(args.host.rstrip("/") + "/api/class/" + args.cls).raise_for_status()
|
||||||
|
|
|
@ -219,10 +219,16 @@ class ClassesApi(object):
|
||||||
clslist.sort()
|
clslist.sort()
|
||||||
yield yamldump({"classes": clslist})
|
yield yamldump({"classes": clslist})
|
||||||
|
|
||||||
def PUT(self, cls):
|
def PUT(self, cls, rename=None):
|
||||||
with self.nodes.db.transaction() as c:
|
with self.nodes.db.transaction() as c:
|
||||||
if cls not in c.root.classes:
|
print(cls, rename)
|
||||||
|
if rename:
|
||||||
|
clsobj = c.root.classes[rename]
|
||||||
|
self.nodes.rename_cls(c, clsobj, cls)
|
||||||
|
elif cls not in c.root.classes:
|
||||||
c.root.classes[cls] = NClass(cls)
|
c.root.classes[cls] = NClass(cls)
|
||||||
|
else:
|
||||||
|
raise cherrypy.HTTPError(500, "Nothing to do")
|
||||||
|
|
||||||
def DELETE(self, cls):
|
def DELETE(self, cls):
|
||||||
with self.nodes.db.transaction() as c:
|
with self.nodes.db.transaction() as c:
|
||||||
|
|
|
@ -66,3 +66,13 @@ class NodeOps(object):
|
||||||
del c.root.nodes[node.fqdn]
|
del c.root.nodes[node.fqdn]
|
||||||
node.fqdn = newname
|
node.fqdn = newname
|
||||||
c.root.nodes[node.fqdn] = node
|
c.root.nodes[node.fqdn] = node
|
||||||
|
|
||||||
|
def rename_cls(self, c, cls, newname):
|
||||||
|
# check new name isnt taken
|
||||||
|
if newname in c.root.classes:
|
||||||
|
raise Exception(f"{newname} already exists")
|
||||||
|
|
||||||
|
# move in root
|
||||||
|
del c.root.classes[cls.name]
|
||||||
|
cls.name = newname
|
||||||
|
c.root.classes[cls.name] = cls
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -4,7 +4,7 @@ from setuptools import setup
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
__version__ = "0.0.2"
|
__version__ = "0.0.3"
|
||||||
with open(os.path.join(os.path.dirname(__file__), "requirements.txt")) as f:
|
with open(os.path.join(os.path.dirname(__file__), "requirements.txt")) as f:
|
||||||
__requirements__ = [line.strip() for line in f.readlines() if not line.startswith("-")]
|
__requirements__ = [line.strip() for line in f.readlines() if not line.startswith("-")]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue