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

Paulo Vital pvital at linux.vnet.ibm.com
Mon Mar 7 17:08:18 UTC 2016



Reviewed-by: Paulo Vital <pvital at linux.vnet.ibm.com>


On 03/07/2016 11:05 AM, Lucio Correia wrote:
> Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
> ---
>  control/networks.py       | 15 +++++++++++++++
>  control/storagepools.py   | 16 ++++++++++++++++
>  control/storagevolumes.py | 25 +++++++++++++++++++++++++
>  control/templates.py      | 15 +++++++++++++++
>  control/vm/hostdevs.py    | 19 +++++++++++++++++++
>  control/vm/ifaces.py      | 24 ++++++++++++++++++++++++
>  control/vm/snapshots.py   | 21 +++++++++++++++++++++
>  control/vm/storages.py    | 21 +++++++++++++++++++++
>  control/vms.py            | 27 +++++++++++++++++++++++++++
>  9 files changed, 183 insertions(+)
> 
> Changes in V2:
> - Improve log messages according to wok modifications
> 
> 
> diff --git a/control/networks.py b/control/networks.py
> index cd1feed..8ba2206 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 %(connection)s 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..aa7dbd3 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 %(type)s storage pool '%(name)s'"},
> +}
> +
> +STORAGEPOOL_REQUESTS = {
> +    'DELETE': {'default': "Remove storage pool '%(ident)s'"},
> +    'PUT': {'default': "Update storage pool '%(ident)s'"},
> +    '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..a04ad35 100644
> --- a/control/storagevolumes.py
> +++ b/control/storagevolumes.py
> @@ -22,6 +22,23 @@ 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' at pool '%(pool)s'"},
> +}
> +
> +STORAGEVOLUME_REQUESTS = {
> +    'DELETE': {'default': "Remove storage volume '%(ident)s' from "
> +                          "pool '%(pool)s'"},
> +    'PUT': {'default': "Update storage volume '%(ident)s' at pool '%(pool)s'"},
> +    'POST': {
> +        'wipe': "Wipe storage volume '%(ident)s' off pool '%(pool)s'",
> +        'resize': "Resize storage volume '%(ident)s' at pool '%(pool)s' with "
> +                  "size %(size)s",
> +        'clone': "Clone storage volume '%(ident)s' at pool '%(pool)s'",
> +    },
> +}
> +
> +
>  class StorageVolumes(AsyncCollection):
>      def __init__(self, model, pool):
>          super(StorageVolumes, self).__init__(model)
> @@ -29,6 +46,10 @@ class StorageVolumes(AsyncCollection):
>          self.pool = pool
>          self.resource_args = [self.pool, ]
>          self.model_args = [self.pool, ]
> +        self.log_map = STORAGEVOLUMES_REQUESTS
> +        self.log_args.update({
> +            'pool': self.pool.encode('utf-8') if self.pool else '',
> +        })
> 
>      def filter_data(self, resources, fields_filter):
>          # filter directory from storage volumes
> @@ -48,6 +69,10 @@ 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
> +        self.log_args.update({
> +            'pool': self.pool.encode('utf-8') if self.pool else '',
> +        })
> 
>      @property
>      def data(self):
> diff --git a/control/templates.py b/control/templates.py
> index aebac0c..343ced1 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 '%(ident)s'"},
> +    '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..8a82db0 100644
> --- a/control/vm/hostdevs.py
> +++ b/control/vm/hostdevs.py
> @@ -21,6 +21,17 @@ from wok.control.base import Collection, Resource
>  from wok.control.utils import UrlSubNode
> 
> 
> +VMHOSTDEVS_REQUESTS = {
> +    'POST': {'default': "Attach host device '%(name)s' to guest '%(vmid)s'"},
> +}
> +
> +VMHOSTDEV_REQUESTS = {
> +    'DELETE': {
> +        'default': "Detach host device '%(ident)s' from guest '%(vmid)s'",
> +    },
> +}
> +
> +
>  @UrlSubNode("hostdevs")
>  class VMHostDevs(Collection):
>      def __init__(self, model, vmid):
> @@ -29,6 +40,10 @@ class VMHostDevs(Collection):
>          self.vmid = vmid
>          self.resource_args = [self.vmid, ]
>          self.model_args = [self.vmid, ]
> +        self.log_map = VMHOSTDEVS_REQUESTS
> +        self.log_args.update({
> +            'vmid': self.vmid.encode('utf-8') if self.vmid else '',
> +        })
> 
> 
>  class VMHostDev(Resource):
> @@ -37,6 +52,10 @@ class VMHostDev(Resource):
>          self.vmid = vmid
>          self.ident = ident
>          self.model_args = [self.vmid, self.ident]
> +        self.log_map = VMHOSTDEV_REQUESTS
> +        self.log_args.update({
> +            'vmid': self.vmid.encode('utf-8') if self.vmid else '',
> +        })
> 
>      @property
>      def data(self):
> diff --git a/control/vm/ifaces.py b/control/vm/ifaces.py
> index d856956..9ecfc8f 100644
> --- a/control/vm/ifaces.py
> +++ b/control/vm/ifaces.py
> @@ -21,6 +21,22 @@ from wok.control.base import Collection, Resource
>  from wok.control.utils import UrlSubNode
> 
> 
> +VMIFACES_REQUESTS = {
> +    'POST': {
> +        'default': "Attach network interface '%(network)s' to guest '%(vm)s'",
> +    },
> +}
> +
> +VMIFACE_REQUESTS = {
> +    'DELETE': {
> +        'default': "Detach network interface '%(ident)s' from guest '%(vm)s'",
> +    },
> +    'PUT': {
> +        'default': "Update network interface '%(ident)s' at guest '%(vm)s'",
> +    },
> +}
> +
> +
>  @UrlSubNode("ifaces")
>  class VMIfaces(Collection):
>      def __init__(self, model, vm):
> @@ -29,6 +45,10 @@ class VMIfaces(Collection):
>          self.vm = vm
>          self.resource_args = [self.vm, ]
>          self.model_args = [self.vm, ]
> +        self.log_map = VMIFACES_REQUESTS
> +        self.log_args.update({
> +            'vm': self.vm.encode('utf-8') if self.vm else '',
> +        })
> 
> 
>  class VMIface(Resource):
> @@ -39,6 +59,10 @@ class VMIface(Resource):
>          self.info = {}
>          self.model_args = [self.vm, self.ident]
>          self.uri_fmt = '/vms/%s/ifaces/%s'
> +        self.log_map = VMIFACE_REQUESTS
> +        self.log_args.update({
> +            'vm': self.vm.encode('utf-8') if self.vm else '',
> +        })
> 
>      @property
>      def data(self):
> diff --git a/control/vm/snapshots.py b/control/vm/snapshots.py
> index b95eaa9..d8cccc1 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 snapshot '%(name)s' at guest '%(vm)s'"},
> +}
> +
> +VMSNAPSHOT_REQUESTS = {
> +    'DELETE': {'default': "Remove snapshot '%(ident)s' from guest '%(vm)s'"},
> +    'POST': {
> +        'revert': "Revert guest '%(vm)s' to snapshot '%(ident)s'",
> +    },
> +}
> +
> +
>  @UrlSubNode('snapshots')
>  class VMSnapshots(AsyncCollection):
>      def __init__(self, model, vm):
> @@ -30,6 +42,11 @@ class VMSnapshots(AsyncCollection):
>          self.resource_args = [self.vm, ]
>          self.model_args = [self.vm, ]
>          self.current = CurrentVMSnapshot(model, vm)
> +        self.log_map = VMSNAPSHOTS_REQUESTS
> +        self.log_args.update({
> +            'vm': self.vm.encode('utf-8') if self.vm else '',
> +            'name': '',
> +        })
> 
> 
>  class VMSnapshot(Resource):
> @@ -40,6 +57,10 @@ 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
> +        self.log_args.update({
> +            'vm': self.vm.encode('utf-8') if self.vm else '',
> +        })
> 
>      @property
>      def data(self):
> diff --git a/control/vm/storages.py b/control/vm/storages.py
> index 3c7d1a3..4a4c8d2 100644
> --- a/control/vm/storages.py
> +++ b/control/vm/storages.py
> @@ -21,6 +21,18 @@ 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 '%(vm)s'",
> +    },
> +}
> +
> +VMSTORAGE_REQUESTS = {
> +    'DELETE': {'default': "Remove storage '%(ident)s' from guest '%(vm)s'"},
> +    'PUT': {'default': "Update storage '%(ident)s' at guest '%(vm)s'"},
> +}
> +
> +
>  @UrlSubNode("storages")
>  class VMStorages(Collection):
>      def __init__(self, model, vm):
> @@ -29,6 +41,11 @@ class VMStorages(Collection):
>          self.vm = vm
>          self.resource_args = [self.vm, ]
>          self.model_args = [self.vm, ]
> +        self.log_map = VMSTORAGES_REQUESTS
> +        self.log_args.update({
> +            'vm': self.vm.encode('utf-8') if self.vm else '',
> +            'path': '',
> +        })
> 
> 
>  class VMStorage(Resource):
> @@ -39,6 +56,10 @@ class VMStorage(Resource):
>          self.info = {}
>          self.model_args = [self.vm, self.ident]
>          self.uri_fmt = '/vms/%s/storages/%s'
> +        self.log_map = VMSTORAGE_REQUESTS
> +        self.log_args.update({
> +            'vm': self.vm.encode('utf-8') if self.vm else '',
> +        })
> 
>      @property
>      def data(self):
> diff --git a/control/vms.py b/control/vms.py
> index 7745a18..64df00e 100644
> --- a/control/vms.py
> +++ b/control/vms.py
> @@ -23,6 +23,30 @@ from wok.control.utils import internal_redirect, UrlSubNode
>  from wok.plugins.kimchi.control.vm import sub_nodes
> 
> 
> +VMS_REQUESTS = {
> +    'POST': {
> +        'default': "Create guest '%(name)s' from template '%(template)s'",
> +    },
> +}
> +
> +VM_REQUESTS = {
> +    'DELETE': {'default': "Remove guest '%(ident)s'"},
> +    'PUT': {'default': "Edit guest '%(ident)s'"},
> +    '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' to '%(remote_host)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 +54,8 @@ class VMs(AsyncCollection):
>          self.resource = VM
>          self.role_key = 'guests'
>          self.admin_methods = ['POST']
> +        self.log_map = VMS_REQUESTS
> +        self.log_args.update({'name': ''})
> 
> 
>  class VM(Resource):
> @@ -56,6 +82,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):
> 




More information about the Kimchi-devel mailing list