[Kimchi-devel] [PATCH] Move resource config's info fetching to model level

Paulo Ricardo Paz Vital pvital at linux.vnet.ibm.com
Wed Jan 29 14:10:00 UTC 2014


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


On Wed, 2014-01-29 at 11:05 +0800, Mark Wu wrote:
> We should not put the resource specefic information in controller
> level. Controller is just used to dispatch request and act a glue
> of view and model.  We can dynamcially generate the controller code
> in future.
> 
> Signed-off-by: Mark Wu <wudxw at linux.vnet.ibm.com>
> ---
>  src/kimchi/control/config.py | 8 +-------
>  src/kimchi/mockmodel.py      | 7 +++++++
>  src/kimchi/model.py          | 7 +++++++
>  3 files changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/src/kimchi/control/config.py b/src/kimchi/control/config.py
> index 16cc384..4750410 100644
> --- a/src/kimchi/control/config.py
> +++ b/src/kimchi/control/config.py
> @@ -22,10 +22,6 @@
>  # 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 cherrypy
> -
> -
> -from kimchi.config import config
>  from kimchi.control.base import Collection, Resource
>  from kimchi.control.utils import UrlSubNode
> 
> @@ -39,9 +35,7 @@ class Config(Resource):
> 
>      @property
>      def data(self):
> -        display_proxy_port = config.get('display', 'display_proxy_port')
> -        return {'http_port': cherrypy.server.socket_port,
> -                'display_proxy_port': display_proxy_port}
> +        return self.info
> 
> 
>  class Capabilities(Resource):
> diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
> index 0fe69dd..bcc2ae0 100644
> --- a/src/kimchi/mockmodel.py
> +++ b/src/kimchi/mockmodel.py
> @@ -45,6 +45,7 @@ import kimchi.model
>  from kimchi import config
>  from kimchi import network as knetwork
>  from kimchi.asynctask import AsyncTask
> +from kimchi.config import config as kconfig
>  from kimchi.distroloader import DistroLoader
>  from kimchi.exception import InvalidOperation, InvalidParameter
>  from kimchi.exception import MissingParameter, NotFoundError, OperationFailed
> @@ -658,6 +659,12 @@ class MockModel(object):
>                                  % name)
>          return disks.get_partition_details(name)
> 
> +    def config_lookup(self, name):
> +        return {'http_port': cherrypy.server.socket_port,
> +                'display_proxy_port':
> +                kconfig.get('display', 'display_proxy_port')}
> +
> +
>  class MockVMTemplate(VMTemplate):
>      def __init__(self, args, mockmodel_inst=None):
>          VMTemplate.__init__(self, args)
> diff --git a/src/kimchi/model.py b/src/kimchi/model.py
> index 1f98bfa..7a9ebca 100644
> --- a/src/kimchi/model.py
> +++ b/src/kimchi/model.py
> @@ -67,6 +67,7 @@ from kimchi import vnc
>  from kimchi import xmlutils
>  from kimchi.asynctask import AsyncTask
>  from kimchi.distroloader import DistroLoader
> +from kimchi.config import config as kconfig
>  from kimchi.exception import InvalidOperation, InvalidParameter, IsoFormatError
>  from kimchi.exception import MissingParameter, NotFoundError, OperationFailed, TimeoutExpired
>  from kimchi.featuretests import FeatureTests
> @@ -1583,6 +1584,12 @@ class Model(object):
>          kimchi_log.info('Host is going to reboot.')
>          os.system('reboot')
> 
> +    def config_lookup(self, name):
> +        return {'http_port': cherrypy.server.socket_port,
> +                'display_proxy_port':
> +                kconfig.get('display', 'display_proxy_port')}
> +
> +
> 
>  class LibvirtVMTemplate(VMTemplate):
>      def __init__(self, args, scan=False, conn=None):




More information about the Kimchi-devel mailing list