[Kimchi-devel] [PATCH] [Kimchi] Customize user request log messages

Lucio Correia luciojhc at linux.vnet.ibm.com
Tue Mar 1 14:29:44 UTC 2016


Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
 control/networks.py       | 15 +++++++++++++++
 control/storagepools.py   | 16 ++++++++++++++++
 control/storagevolumes.py | 17 +++++++++++++++++
 control/templates.py      | 15 +++++++++++++++
 control/vm/hostdevs.py    | 11 +++++++++++
 control/vm/ifaces.py      | 12 ++++++++++++
 control/vm/snapshots.py   | 14 ++++++++++++++
 control/vm/storages.py    | 12 ++++++++++++
 control/vms.py            | 24 ++++++++++++++++++++++++
 9 files changed, 136 insertions(+)

diff --git a/control/networks.py b/control/networks.py
index cd1feed..a8a26b2 100644
--- a/control/networks.py
+++ b/control/networks.py
@@ -21,6 +21,19 @@ from wok.control.base import Collection, Resource
 from wok.control.utils import UrlSubNode
 
 
+NETWORKS_REQUESTS = {
+    'POST': {'default': "Create virtual network '%(name)s'"},
+}
+
+NETWORK_REQUESTS = {
+    'DELETE': {'default': "Remove virtual network '%(ident)s'"},
+    'POST': {
+        'activate': "Activate virtual network '%(ident)s'",
+        'deactivate': "Deactivate virtual network '%(ident)s'",
+    },
+}
+
+
 @UrlSubNode('networks', True)
 class Networks(Collection):
     def __init__(self, model):
@@ -28,6 +41,7 @@ class Networks(Collection):
         self.role_key = 'network'
         self.admin_methods = ['POST']
         self.resource = Network
+        self.log_map = NETWORKS_REQUESTS
 
 
 class Network(Resource):
@@ -39,6 +53,7 @@ class Network(Resource):
         self.activate = self.generate_action_handler('activate')
         self.deactivate = self.generate_action_handler('deactivate',
                                                        destructive=True)
+        self.log_map = NETWORK_REQUESTS
 
     @property
     def data(self):
diff --git a/control/storagepools.py b/control/storagepools.py
index 10b371d..2139566 100644
--- a/control/storagepools.py
+++ b/control/storagepools.py
@@ -29,6 +29,20 @@ from wok.plugins.kimchi.control.storagevolumes import StorageVolumes
 from wok.plugins.kimchi.model.storagepools import ISO_POOL_NAME
 
 
+STORAGEPOOLS_REQUESTS = {
+    'POST': {'default': "Create storage pool '%(name)s'"},
+}
+
+STORAGEPOOL_REQUESTS = {
+    'DELETE': {'default': "Remove storage pool '%(ident)s'"},
+    'PUT': {'default': "Update storage pool"},
+    'POST': {
+        'activate': "Activate storage pool '%(ident)s'",
+        'deactivate': "Deactivate storage pool '%(ident)s'",
+    },
+}
+
+
 @UrlSubNode('storagepools', True)
 class StoragePools(Collection):
     def __init__(self, model):
@@ -38,6 +52,7 @@ class StoragePools(Collection):
         self.resource = StoragePool
         isos = IsoPool(model)
         setattr(self, ISO_POOL_NAME, isos)
+        self.log_map = STORAGEPOOLS_REQUESTS
 
     def create(self, params, *args):
         try:
@@ -84,6 +99,7 @@ class StoragePool(Resource):
         self.deactivate = self.generate_action_handler('deactivate',
                                                        destructive=True)
         self.storagevolumes = StorageVolumes(self.model, ident)
+        self.log_map = STORAGEPOOL_REQUESTS
 
     @property
     def data(self):
diff --git a/control/storagevolumes.py b/control/storagevolumes.py
index d78eefb..01654cb 100644
--- a/control/storagevolumes.py
+++ b/control/storagevolumes.py
@@ -22,6 +22,21 @@ from wok.control.base import AsyncCollection, Collection, Resource
 from wok.control.utils import get_class_name, model_fn
 
 
+STORAGEVOLUMES_REQUESTS = {
+    'POST': {'default': "Create storage volume '%(name)s'"},
+}
+
+STORAGEVOLUME_REQUESTS = {
+    'DELETE': {'default': "Remove template '%(ident)s'"},
+    'PUT': {'default': "Update storage volume"},
+    'POST': {
+        'wipe': "Wipe storage volume '%(ident)s'",
+        'resize': "Resize storage volume '%(ident)s'",
+        'clone': "Clone storage volume '%(ident)s'",
+    },
+}
+
+
 class StorageVolumes(AsyncCollection):
     def __init__(self, model, pool):
         super(StorageVolumes, self).__init__(model)
@@ -29,6 +44,7 @@ class StorageVolumes(AsyncCollection):
         self.pool = pool
         self.resource_args = [self.pool, ]
         self.model_args = [self.pool, ]
+        self.log_map = STORAGEVOLUMES_REQUESTS
 
     def filter_data(self, resources, fields_filter):
         # filter directory from storage volumes
@@ -48,6 +64,7 @@ class StorageVolume(Resource):
         self.resize = self.generate_action_handler('resize', ['size'])
         self.wipe = self.generate_action_handler('wipe')
         self.clone = self.generate_action_handler_task('clone')
+        self.log_map = STORAGEVOLUME_REQUESTS
 
     @property
     def data(self):
diff --git a/control/templates.py b/control/templates.py
index aebac0c..486dca1 100644
--- a/control/templates.py
+++ b/control/templates.py
@@ -21,6 +21,19 @@ from wok.control.base import Collection, Resource
 from wok.control.utils import UrlSubNode
 
 
+TEMPLATES_REQUESTS = {
+    'POST': {'default': "Create template '%(name)s'"},
+}
+
+TEMPLATE_REQUESTS = {
+    'DELETE': {'default': "Remove template '%(ident)s'"},
+    'PUT': {'default': "Update template"},
+    'POST': {
+        'clone': "Clone template '%(ident)s'",
+    },
+}
+
+
 @UrlSubNode('templates', True)
 class Templates(Collection):
     def __init__(self, model):
@@ -28,6 +41,7 @@ class Templates(Collection):
         self.role_key = 'templates'
         self.admin_methods = ['GET', 'POST']
         self.resource = Template
+        self.log_map = TEMPLATES_REQUESTS
 
 
 class Template(Resource):
@@ -37,6 +51,7 @@ class Template(Resource):
         self.admin_methods = ['PUT', 'POST', 'DELETE']
         self.uri_fmt = "/templates/%s"
         self.clone = self.generate_action_handler('clone')
+        self.log_map = TEMPLATE_REQUESTS
 
     @property
     def data(self):
diff --git a/control/vm/hostdevs.py b/control/vm/hostdevs.py
index bae98df..11e59c2 100644
--- a/control/vm/hostdevs.py
+++ b/control/vm/hostdevs.py
@@ -21,6 +21,15 @@ from wok.control.base import Collection, Resource
 from wok.control.utils import UrlSubNode
 
 
+VMHOSTDEVS_REQUESTS = {
+    'POST': {'default': "Attach host device '%(name)s' to guest"},
+}
+
+VMHOSTDEV_REQUESTS = {
+    'DELETE': {'default': "Detach host device '%(ident)s' from guest"},
+}
+
+
 @UrlSubNode("hostdevs")
 class VMHostDevs(Collection):
     def __init__(self, model, vmid):
@@ -29,6 +38,7 @@ class VMHostDevs(Collection):
         self.vmid = vmid
         self.resource_args = [self.vmid, ]
         self.model_args = [self.vmid, ]
+        self.log_map = VMHOSTDEVS_REQUESTS
 
 
 class VMHostDev(Resource):
@@ -37,6 +47,7 @@ class VMHostDev(Resource):
         self.vmid = vmid
         self.ident = ident
         self.model_args = [self.vmid, self.ident]
+        self.log_map = VMHOSTDEV_REQUESTS
 
     @property
     def data(self):
diff --git a/control/vm/ifaces.py b/control/vm/ifaces.py
index d856956..f7c4e36 100644
--- a/control/vm/ifaces.py
+++ b/control/vm/ifaces.py
@@ -21,6 +21,16 @@ from wok.control.base import Collection, Resource
 from wok.control.utils import UrlSubNode
 
 
+VMIFACES_REQUESTS = {
+    'POST': {'default': "Attach network interface '%(network)s' to guest"},
+}
+
+VMIFACE_REQUESTS = {
+    'DELETE': {'default': "Detach network interface '%(ident)s' from guest"},
+    'PUT': {'default': "Update guest network interface"},
+}
+
+
 @UrlSubNode("ifaces")
 class VMIfaces(Collection):
     def __init__(self, model, vm):
@@ -29,6 +39,7 @@ class VMIfaces(Collection):
         self.vm = vm
         self.resource_args = [self.vm, ]
         self.model_args = [self.vm, ]
+        self.log_map = VMIFACES_REQUESTS
 
 
 class VMIface(Resource):
@@ -39,6 +50,7 @@ class VMIface(Resource):
         self.info = {}
         self.model_args = [self.vm, self.ident]
         self.uri_fmt = '/vms/%s/ifaces/%s'
+        self.log_map = VMIFACE_REQUESTS
 
     @property
     def data(self):
diff --git a/control/vm/snapshots.py b/control/vm/snapshots.py
index b95eaa9..5a6013c 100644
--- a/control/vm/snapshots.py
+++ b/control/vm/snapshots.py
@@ -21,6 +21,18 @@ from wok.control.base import AsyncCollection, Resource
 from wok.control.utils import UrlSubNode
 
 
+VMSNAPSHOTS_REQUESTS = {
+    'POST': {'default': "Create guest snapshot '%(name)s'"},
+}
+
+VMSNAPSHOT_REQUESTS = {
+    'DELETE': {'default': "Remove guest snapshot '%(ident)s'"},
+    'POST': {
+        'revert': "Revert to guest snapshot '%(ident)s'",
+    },
+}
+
+
 @UrlSubNode('snapshots')
 class VMSnapshots(AsyncCollection):
     def __init__(self, model, vm):
@@ -30,6 +42,7 @@ class VMSnapshots(AsyncCollection):
         self.resource_args = [self.vm, ]
         self.model_args = [self.vm, ]
         self.current = CurrentVMSnapshot(model, vm)
+        self.log_map = VMSNAPSHOTS_REQUESTS
 
 
 class VMSnapshot(Resource):
@@ -40,6 +53,7 @@ class VMSnapshot(Resource):
         self.model_args = [self.vm, self.ident]
         self.uri_fmt = '/vms/%s/snapshots/%s'
         self.revert = self.generate_action_handler('revert')
+        self.log_map = VMSNAPSHOT_REQUESTS
 
     @property
     def data(self):
diff --git a/control/vm/storages.py b/control/vm/storages.py
index 3c7d1a3..5e7b8c4 100644
--- a/control/vm/storages.py
+++ b/control/vm/storages.py
@@ -21,6 +21,16 @@ from wok.control.base import Collection, Resource
 from wok.control.utils import UrlSubNode
 
 
+VMSTORAGES_REQUESTS = {
+    'POST': {'default': "Attach '%(type)s' storage '%(path)s' to guest"},
+}
+
+VMSTORAGE_REQUESTS = {
+    'DELETE': {'default': "Remove storage '%(ident)s' from guest"},
+    'PUT': {'default': "Update guest storage path to '%(path)s'"},
+}
+
+
 @UrlSubNode("storages")
 class VMStorages(Collection):
     def __init__(self, model, vm):
@@ -29,6 +39,7 @@ class VMStorages(Collection):
         self.vm = vm
         self.resource_args = [self.vm, ]
         self.model_args = [self.vm, ]
+        self.log_map = VMSTORAGES_REQUESTS
 
 
 class VMStorage(Resource):
@@ -39,6 +50,7 @@ class VMStorage(Resource):
         self.info = {}
         self.model_args = [self.vm, self.ident]
         self.uri_fmt = '/vms/%s/storages/%s'
+        self.log_map = VMSTORAGE_REQUESTS
 
     @property
     def data(self):
diff --git a/control/vms.py b/control/vms.py
index 7745a18..1297955 100644
--- a/control/vms.py
+++ b/control/vms.py
@@ -23,6 +23,28 @@ from wok.control.utils import internal_redirect, UrlSubNode
 from wok.plugins.kimchi.control.vm import sub_nodes
 
 
+VMS_REQUESTS = {
+    'POST': {'default': "Create guest from template '%(template)s'"},
+}
+
+VM_REQUESTS = {
+    'DELETE': {'default': "Remove guest '%(ident)s'"},
+    'PUT': {'default': "Update guest"},
+    'POST': {
+        'start': "Start guest '%(ident)s'",
+        'poweroff': "Power off guest '%(ident)s'",
+        'shutdown': "Shutdown guest '%(ident)s'",
+        'reset': "Restart guest '%(ident)s'",
+        'connect': "Connect to guest '%(ident)s' through novnc/spice",
+        'clone': "Clone guest '%(ident)s'",
+        'migrate': "Migrate guest '%(ident)s'",
+        'suspend': "Suspend guest '%(ident)s'",
+        'resume': "Resume guest '%(ident)s'",
+        'serial': "Connect to guest '%(ident)s' through serial",
+    },
+}
+
+
 @UrlSubNode('vms', True)
 class VMs(AsyncCollection):
     def __init__(self, model):
@@ -30,6 +52,7 @@ class VMs(AsyncCollection):
         self.resource = VM
         self.role_key = 'guests'
         self.admin_methods = ['POST']
+        self.log_map = VMS_REQUESTS
 
 
 class VM(Resource):
@@ -56,6 +79,7 @@ class VM(Resource):
         self.suspend = self.generate_action_handler('suspend')
         self.resume = self.generate_action_handler('resume')
         self.serial = self.generate_action_handler('serial')
+        self.log_map = VM_REQUESTS
 
     @property
     def data(self):
-- 
1.9.1




More information about the Kimchi-devel mailing list