Files
deb-python-fuelclient/fuelclient/objects/base.py
Bulat Gaifullin bac19f24b3 Added commands to manage deployment sequences
Commands:
  - fuel2 sequence create -r <release> -n <name> -t <graph_type1> [graph_typeN]
  - fuel2 sequence upload -r <release> --file <file_path>
  - fuel2 sequence download <id> [--file <file path>]
  - fuel2 sequence delete <id>
  - fuel2 sequence update <id> [-name <name>] [-t <graph_type1> [graph_typeN]]
  - fuel2 sequence list -r <release_id> | -e <env_id>
  - fuel2 sequence show <id>
  - fuel2 sequence execute <id> -e <env_id> [--force] [--dry-run] [--noop]

DocImpact
Change-Id: I6eb688c5cc91b2b3dbaa2fe5c52a69fe062da664
Partial-Bug: 1620620
2016-09-09 10:49:29 +03:00

69 lines
2.1 KiB
Python

# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from fuelclient.cli.serializers import Serializer
from fuelclient.client import DefaultAPIClient
class BaseObject(object):
"""BaseObject class - base class for fuelclient.objects object classes
'class_api_path' - url path to object handler on Nailgun server.
'instance_api_path' - url path template which formatted with object id
returns only one serialized object.
'connection' - 'APIClient' class instance from fuelclient.client
"""
class_api_path = None
instance_api_path = None
connection = DefaultAPIClient
def __init__(self, obj_id, **kwargs):
self.connection = DefaultAPIClient
self.serializer = Serializer.from_params(kwargs.get('params'))
self.id = obj_id
self._data = None
@classmethod
def init_with_data(cls, data):
instance = cls(data["id"])
instance._data = data
return instance
@classmethod
def get_by_ids(cls, ids):
return map(cls, ids)
def update(self):
self._data = self.connection.get_request(
self.instance_api_path.format(self.id))
def get_fresh_data(self):
self.update()
return self.data
@property
def data(self):
if self._data is None:
return self.get_fresh_data()
else:
return self._data
@classmethod
def get_all_data(cls, **kwargs):
return cls.connection.get_request(cls.class_api_path, params=kwargs)
@classmethod
def get_all(cls, **kwargs):
return map(cls.init_with_data, cls.get_all_data(**kwargs))