[Kimchi-devel] [project-kimchi][PATCHv4] Return source information for storage pool

Ramon Medeiros ramonn at linux.vnet.ibm.com
Thu Dec 19 11:51:54 UTC 2013


Reviewed-By: Ramon Medeiros <ramonn at br.ibm.com>
On 12/19/2013 07:11 AM, lvroyce at linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>
> v1>v4, Delete logical pool source because UI just care VG name.
>         Add update controller.
> For netfs storage pool, remote export path and addr will make more
> sense than local mount point.
> Report storage source information in pool info.
>
> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
> ---
>   docs/API.md              |  3 +++
>   src/kimchi/controller.py |  1 +
>   src/kimchi/mockmodel.py  |  1 +
>   src/kimchi/model.py      | 16 ++++++++++++++++
>   tests/test_rest.py       |  1 +
>   5 files changed, 22 insertions(+)
>
> diff --git a/docs/API.md b/docs/API.md
> index 74bc1b5..9edc551 100644
> --- a/docs/API.md
> +++ b/docs/API.md
> @@ -215,6 +215,9 @@ Represents a snapshot of the Virtual Machine's primary monitor.
>       * nr_volumes: The number of storage volumes for active pools, 0 for inactive pools
>       * autostart: Whether the storage pool will be enabled
>                    automatically when the system boots
> +    * source: Source of the storage pool,
> +        * addr: mount address of this storage pool(for 'netfs' pool)
> +        * path: export path of this storage pool(for 'netfs' pool)
>   * **PUT**: Set whether the Storage Pool should be enabled automatically when the
>              system boots
>       * autostart: Toggle the autostart flag of the VM
> diff --git a/src/kimchi/controller.py b/src/kimchi/controller.py
> index 3b27c27..2940278 100644
> --- a/src/kimchi/controller.py
> +++ b/src/kimchi/controller.py
> @@ -533,6 +533,7 @@ class StoragePool(Resource):
>                  'allocated': self.info['allocated'],
>                  'available': self.info['available'],
>                  'path': self.info['path'],
> +               'source': self.info['source'],
>                  'type': self.info['type'],
>                  'nr_volumes': self.info['nr_volumes'],
>                  'autostart': self.info['autostart']}
> diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
> index 4839d4c..348127a 100644
> --- a/src/kimchi/mockmodel.py
> +++ b/src/kimchi/mockmodel.py
> @@ -639,6 +639,7 @@ class MockStoragePool(object):
>                        'allocated': 512 << 20,
>                        'available': 512 << 20,
>                        'path': '/var/lib/libvirt/images',
> +                     'source': {},
>                        'type': 'dir',
>                        'nr_volumes': 0,
>                        'autostart': 0}
> diff --git a/src/kimchi/model.py b/src/kimchi/model.py
> index 73c18ac..3bc5d6d 100644
> --- a/src/kimchi/model.py
> +++ b/src/kimchi/model.py
> @@ -78,6 +78,9 @@ GUESTS_STATS_INTERVAL = 5
>   HOST_STATS_INTERVAL = 1
>   VM_STATIC_UPDATE_PARAMS = {'name': './name'}
>   VM_LIVE_UPDATE_PARAMS = {}
> +STORAGE_SOURCES = {'netfs': {'addr': '/pool/source/host/@name',
> +                             'path': '/pool/source/dir/@path'}}
> +
>
>   def _uri_to_name(collection, uri):
>       expr = '/%s/(.*?)/?$' % collection
> @@ -1019,6 +1022,17 @@ class Model(object):
>               raise OperationFailed(e.get_error_message())
>           return name
>
> +    def _get_storage_source(self, pool_type, pool_xml):
> +        source = {}
> +        if pool_type not in STORAGE_SOURCES:
> +            return source
> +
> +        for key, val in STORAGE_SOURCES[pool_type].items():
> +            res = xmlutils.xpath_get_text(pool_xml, val)
> +            source[key] = res[0] if len(res) == 1 else res
> +
> +        return source
> +
>       def storagepool_lookup(self, name):
>           pool = self._get_storagepool(name)
>           info = pool.info()
> @@ -1027,8 +1041,10 @@ class Model(object):
>           xml = pool.XMLDesc(0)
>           path = xmlutils.xpath_get_text(xml, "/pool/target/path")[0]
>           pool_type = xmlutils.xpath_get_text(xml, "/pool/@type")[0]
> +        source = self._get_storage_source(pool_type, xml)
>           res = {'state': Model.pool_state_map[info[0]],
>                  'path': path,
> +               'source': source,
>                  'type': pool_type,
>                  'autostart': autostart,
>                  'capacity': info[1],
> diff --git a/tests/test_rest.py b/tests/test_rest.py
> index 73b5243..f597796 100644
> --- a/tests/test_rest.py
> +++ b/tests/test_rest.py
> @@ -417,6 +417,7 @@ class RestTests(unittest.TestCase):
>           storagepool = json.loads(resp.read())
>           self.assertEquals('storagepool-1', storagepool['name'])
>           self.assertEquals('inactive', storagepool['state'])
> +        self.assertIn('source', storagepool)
>
>       def test_storagepool_action(self):
>           # Create a storage pool


-- 
Ramon Nunes Medeiros
Software Engineer - Linux Technology Center Brazil
IBM Systems & Technology Group
Phone : +55 19 2132 7878
ramonn at br.ibm.com




More information about the Kimchi-devel mailing list