aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources
diff options
context:
space:
mode:
authorJing Lu <lvjing5@huawei.com>2017-07-21 03:01:16 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-21 03:01:16 +0000
commit685af779d6a300a4e9bac8c1aa25f0e648a25d87 (patch)
treefb189160bfa2c10baefa8c31c3fd7c80a0b04042 /api/resources
parentbe2da4d7ef13f61cfcd9b591a9b00579b896213d (diff)
parent68c2a5f10b7c1f5fc59579a5a3078c57c60a85a6 (diff)
Merge "Add API(v2) to get all images"
Diffstat (limited to 'api/resources')
-rw-r--r--api/resources/v2/images.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/api/resources/v2/images.py b/api/resources/v2/images.py
index dc996742f..701818493 100644
--- a/api/resources/v2/images.py
+++ b/api/resources/v2/images.py
@@ -5,6 +5,8 @@ import threading
from api import ApiResource
from yardstick.common.utils import result_handler
from yardstick.common.utils import source_env
+from yardstick.common.utils import change_obj_to_dict
+from yardstick.common.openstack_utils import get_nova_client
from yardstick.common import constants as consts
LOG = logging.getLogger(__name__)
@@ -13,9 +15,35 @@ LOG.setLevel(logging.DEBUG)
class V2Images(ApiResource):
+ def get(self):
+ try:
+ source_env(consts.OPENRC)
+ except:
+ return result_handler(consts.API_ERROR, 'source openrc error')
+
+ nova_client = get_nova_client()
+ try:
+ images_list = nova_client.images.list()
+ except:
+ return result_handler(consts.API_ERROR, 'get images error')
+ else:
+ images = [self.get_info(change_obj_to_dict(i)) for i in images_list]
+ status = 1 if all(i['status'] == 'ACTIVE' for i in images) else 0
+
+ return result_handler(consts.API_SUCCESS, {'status': status, 'images': images})
+
def post(self):
return self._dispatch_post()
+ def get_info(self, data):
+ result = {
+ 'name': data.get('name', ''),
+ 'size': data.get('OS-EXT-IMG-SIZE:size', ''),
+ 'status': data.get('status', ''),
+ 'time': data.get('updated', '')
+ }
+ return result
+
def load_image(self, args):
thread = threading.Thread(target=self._load_images)
thread.start()
href='#n261'>261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369