[Kimchi-devel] [PATCH V3 2/4] improve controller: tag the collections/resouces of root with @UrlSubNode

Aline Manera alinefm at linux.vnet.ibm.com
Thu Jan 23 20:03:51 UTC 2014


Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>

On 01/22/2014 02:51 PM, shaohef at linux.vnet.ibm.com wrote:
> From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
>
> we can difine a /host as follow:
>
> @UrlSubNode("host", True)
>   class Host(Resource):
>       def __init__(self, model, id=None):
>           super(Host, self).__init__(model, id)
>
> @UrlSubNode("host", True) means:
> the URL "/host" is root.Host, and it need authentication
>
> Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
> ---
>   src/kimchi/control/__init__.py     | 8 ++++++++
>   src/kimchi/control/config.py       | 2 ++
>   src/kimchi/control/debugreports.py | 2 ++
>   src/kimchi/control/host.py         | 2 ++
>   src/kimchi/control/interfaces.py   | 2 ++
>   src/kimchi/control/networks.py     | 2 ++
>   src/kimchi/control/plugins.py      | 2 ++
>   src/kimchi/control/storagepools.py | 2 ++
>   src/kimchi/control/tasks.py        | 2 ++
>   src/kimchi/control/templates.py    | 2 ++
>   src/kimchi/control/vms.py          | 2 ++
>   11 files changed, 28 insertions(+)
>
> diff --git a/src/kimchi/control/__init__.py b/src/kimchi/control/__init__.py
> index 8a37cc4..46305b5 100644
> --- a/src/kimchi/control/__init__.py
> +++ b/src/kimchi/control/__init__.py
> @@ -19,3 +19,11 @@
>   # You should have received a copy of the GNU Lesser General Public
>   # License along with this library; if not, write to the Free Software
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
> +
> +import os
> +
> +
> +from kimchi.utils import load_url_sub_node
> +
> +
> +sub_nodes = load_url_sub_node(os.path.dirname(__file__), __name__)
> diff --git a/src/kimchi/control/config.py b/src/kimchi/control/config.py
> index 603f51d..647f00b 100644
> --- a/src/kimchi/control/config.py
> +++ b/src/kimchi/control/config.py
> @@ -27,8 +27,10 @@ import cherrypy
>
>   from kimchi.config import config
>   from kimchi.control.base import Collection, Resource
> +from kimchi.utils import UrlSubNode
>
>
> + at UrlSubNode("config")
>   class Config(Resource):
>       def __init__(self, model, id=None):
>           super(Config, self).__init__(model, id)
> diff --git a/src/kimchi/control/debugreports.py b/src/kimchi/control/debugreports.py
> index a55ba38..38742d6 100644
> --- a/src/kimchi/control/debugreports.py
> +++ b/src/kimchi/control/debugreports.py
> @@ -23,8 +23,10 @@
>
>   from kimchi.control.base import AsyncCollection, Resource
>   from kimchi.control.utils import internal_redirect
> +from kimchi.utils import UrlSubNode
>
>
> + at UrlSubNode("debugreports", True)
>   class DebugReports(AsyncCollection):
>       def __init__(self, model):
>           super(DebugReports, self).__init__(model)
> diff --git a/src/kimchi/control/host.py b/src/kimchi/control/host.py
> index 9b19577..aa0199e 100644
> --- a/src/kimchi/control/host.py
> +++ b/src/kimchi/control/host.py
> @@ -24,8 +24,10 @@
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
>
>   from kimchi.control.base import Collection, Resource
> +from kimchi.utils import UrlSubNode
>
>
> + at UrlSubNode("host", True)
>   class Host(Resource):
>       def __init__(self, model, id=None):
>           super(Host, self).__init__(model, id)
> diff --git a/src/kimchi/control/interfaces.py b/src/kimchi/control/interfaces.py
> index 28be26e..8b94ae9 100644
> --- a/src/kimchi/control/interfaces.py
> +++ b/src/kimchi/control/interfaces.py
> @@ -23,8 +23,10 @@
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
>
>   from kimchi.control.base import Collection, Resource
> +from kimchi.utils import UrlSubNode
>
>
> + at UrlSubNode("interfaces")
>   class Interfaces(Collection):
>       def __init__(self, model):
>           super(Interfaces, self).__init__(model)
> diff --git a/src/kimchi/control/networks.py b/src/kimchi/control/networks.py
> index f3f0b41..c42e44b 100644
> --- a/src/kimchi/control/networks.py
> +++ b/src/kimchi/control/networks.py
> @@ -22,8 +22,10 @@
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
>
>   from kimchi.control.base import Collection, Resource
> +from kimchi.utils import UrlSubNode
>
>
> + at UrlSubNode("networks", True)
>   class Networks(Collection):
>       def __init__(self, model):
>           super(Networks, self).__init__(model)
> diff --git a/src/kimchi/control/plugins.py b/src/kimchi/control/plugins.py
> index af32709..7e99fe0 100644
> --- a/src/kimchi/control/plugins.py
> +++ b/src/kimchi/control/plugins.py
> @@ -25,8 +25,10 @@
>   import kimchi.template
>   from kimchi.control.base import Collection, Resource
>   from kimchi.control.utils import get_class_name, model_fn
> +from kimchi.utils import UrlSubNode
>
>
> + at UrlSubNode("plugins")
>   class Plugins(Collection):
>       def __init__(self, model):
>           super(Plugins, self).__init__(model)
> diff --git a/src/kimchi/control/storagepools.py b/src/kimchi/control/storagepools.py
> index 06b7196..29b10d9 100644
> --- a/src/kimchi/control/storagepools.py
> +++ b/src/kimchi/control/storagepools.py
> @@ -31,8 +31,10 @@ from kimchi.control.storagevolumes import IsoVolumes, StorageVolumes
>   from kimchi.control.utils import get_class_name, model_fn, parse_request
>   from kimchi.control.utils import validate_params
>   from kimchi.model import ISO_POOL_NAME
> +from kimchi.utils import UrlSubNode
>
>
> + at UrlSubNode("storagepools", True)
>   class StoragePools(Collection):
>       def __init__(self, model):
>           super(StoragePools, self).__init__(model)
> diff --git a/src/kimchi/control/tasks.py b/src/kimchi/control/tasks.py
> index b799422..47c6ff9 100644
> --- a/src/kimchi/control/tasks.py
> +++ b/src/kimchi/control/tasks.py
> @@ -22,8 +22,10 @@
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
>
>   from kimchi.control.base import Collection, Resource
> +from kimchi.utils import UrlSubNode
>
>
> + at UrlSubNode("tasks", True)
>   class Tasks(Collection):
>       def __init__(self, model):
>           super(Tasks, self).__init__(model)
> diff --git a/src/kimchi/control/templates.py b/src/kimchi/control/templates.py
> index a77936e..032682c 100644
> --- a/src/kimchi/control/templates.py
> +++ b/src/kimchi/control/templates.py
> @@ -22,8 +22,10 @@
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
>
>   from kimchi.control.base import Collection, Resource
> +from kimchi.utils import UrlSubNode
>
>
> + at UrlSubNode("templates", True)
>   class Templates(Collection):
>       def __init__(self, model):
>           super(Templates, self).__init__(model)
> diff --git a/src/kimchi/control/vms.py b/src/kimchi/control/vms.py
> index 7843be7..f4646d2 100644
> --- a/src/kimchi/control/vms.py
> +++ b/src/kimchi/control/vms.py
> @@ -24,8 +24,10 @@
>
>   from kimchi.control.base import Collection, Resource
>   from kimchi.control.utils import internal_redirect
> +from kimchi.utils import UrlSubNode
>
>
> + at UrlSubNode("vms", True)
>   class VMs(Collection):
>       def __init__(self, model):
>           super(VMs, self).__init__(model)




More information about the Kimchi-devel mailing list