Skip to content

Commit

Permalink
Merge 06110e8 into 027cf2d
Browse files Browse the repository at this point in the history
  • Loading branch information
pbortlov committed Nov 2, 2020
2 parents 027cf2d + 06110e8 commit 529e108
Show file tree
Hide file tree
Showing 5 changed files with 675 additions and 305 deletions.
271 changes: 148 additions & 123 deletions iiblib/iib_build_details_model.py
Original file line number Diff line number Diff line change
@@ -1,135 +1,160 @@
class IIBBuildDetailsModel(object):
"""Model class handling data about index build task"""

def __init__(
self,
_id,
state,
reason,
state_history,
from_index,
from_index_resolved,
bundles,
removed_operators,
organization,
binary_image,
binary_image_resolved,
index_image,
request_type,
arches,
bundle_mapping,
omps_operator_version,
):
"""
Args:
_id (int)
Id of build
state (str)
State of build
state (str)
Reason for state change
from_index (str)
Reference of index image used as source for rebuild
from_index_resolved (str)
Reference of new index image
bundles (list)
List of bundles to be added to index image
removed_operators (list)
List of operators to be removed from index image
organization (str)
Name of organization to push to in the legacy app registry
binary_image (str)
Reference of binary image used for rebuilding
binary_image_resolved (str)
Checksum reference of binary image that was used for rebuilding
index_image (str)
Reference of index image to rebuild
request_type (str)
Type of iib build task (add or remove)
arches (list)
List of architectures supported in new index image
bundle_mapping (dict)
Operator names in "bundles" map to: list of "bundles" which
map to the operator key
omps_operator_version (dict)
Operator version returned from OMPS API call used for Add request
"""
self.id = _id
self.state = state
self.reason = reason
self.state_history = state_history
self.from_index = from_index
self.from_index_resolved = from_index_resolved
self.bundles = bundles
self.removed_operators = removed_operators
self.organization = organization
self.binary_image = binary_image
self.binary_image_resolved = binary_image_resolved
self.index_image = index_image
self.request_type = request_type
self.arches = arches
self.bundle_mapping = bundle_mapping
self.omps_operator_version = omps_operator_version
__slots__ = [
"id",
"arches",
"state",
"state_reason",
"request_type",
"batch",
"updated",
"user",
"state_history",
"batch_annotations",
"logs",
"__dict__",
]

_general_attrs = [
"id",
"arches",
"state",
"state_reason",
"request_type",
"batch",
"updated",
"user",
]

_optional_attrs = {
"state_history": lambda: list(),
"batch_annotations": lambda: dict(),
"logs": lambda: dict(),
}

_operational_attrs = []

def __init__(self, *args, **kwargs):
self._data = self.get_args(kwargs)

@classmethod
def from_dict(cls, data):
return cls(
data["id"],
data["state"],
data["state_reason"],
data.get("state_history", []),
data["from_index"],
data["from_index_resolved"],
data.get("bundles", []),
data.get("removed_operators", []),
data.get("organization"),
data["binary_image"],
data["binary_image_resolved"],
data["index_image"],
data["request_type"],
data["arches"],
data["bundle_mapping"],
data.get("omps_operator_version", {}),
)
if data["request_type"] == "add":
return AddModel(**data)
elif data["request_type"] == "rm":
return RmModel(**data)
elif data["request_type"] == "regenerate-bundle":
return RegenerateBundleModel(**data)
raise KeyError("Unsupported request type: %s" % data["request_type"])

def get_args(self, data):
attrs = {}
for general_attr in self._general_attrs:
attrs[general_attr] = data[general_attr]
for optional_attr, default_maker in self._optional_attrs.items():
if optional_attr in data:
attrs[optional_attr] = data[optional_attr]
else:
attrs[optional_attr] = default_maker()
for operation_attr in self._operation_attrs:
attrs[operation_attr] = data[operation_attr]
return attrs

def to_dict(self):
return {
"id": self.id,
"state": self.state,
"state_reason": self.reason,
"state_history": self.state_history,
"from_index": self.from_index,
"from_index_resolved": self.from_index,
"bundles": self.bundles,
"removed_operators": self.removed_operators,
"organization": self.organization,
"binary_image": self.binary_image,
"binary_image_resolved": self.binary_image_resolved,
"index_image": self.index_image,
"request_type": self.request_type,
"arches": self.arches,
"bundle_mapping": self.bundle_mapping,
"omps_operator_version": self.omps_operator_version,
}
result = {}
for key in self._general_attrs:
result[key] = self._data[key]
for key in self._optional_attrs.items():
result[key] = self._data.get(key)
for key in self._operation_attrs:
result[key] = self._data[key]
return result

def __eq__(self, other):
return isinstance(other, IIBBuildDetailsModel) and self._data == other._data

def __getattribute__(self, name):
if (
self.id == other.id
and self.state == other.state
and self.reason == other.reason
and self.state_history == other.state_history
and self.from_index == other.from_index
and self.from_index_resolved == other.from_index_resolved
and self.bundles == other.bundles
and self.removed_operators == other.removed_operators
and self.organization == other.organization
and self.binary_image == other.binary_image
and self.binary_image_resolved == other.binary_image_resolved
and self.index_image == other.index_image
and self.request_type == other.request_type
and self.arches == other.arches
and self.bundle_mapping == other.bundle_mapping
and self.omps_operator_version == other.omps_operator_version
name in object.__getattribute__(self, "_operation_attrs")
or name in object.__getattribute__(self, "_optional_attrs")
or name in object.__getattribute__(self, "_general_attrs")
):
return True
return False
return object.__getattribute__(self, "_data")[name]
else:
return object.__getattribute__(self, name)


class AddModel(IIBBuildDetailsModel):

__slots__ = [
"binary_image",
"binary_image_resolved",
"bundles",
"bundle_mapping",
"from_index",
"from_index_resolved",
"index_image",
"removed_operators",
"organization",
"omps_operator_version",
"distribution_scope",
]

_operation_attrs = [
"binary_image",
"binary_image_resolved",
"bundles",
"bundle_mapping",
"from_index",
"from_index_resolved",
"index_image",
"removed_operators",
"organization",
"omps_operator_version",
"distribution_scope",
]


class RmModel(IIBBuildDetailsModel):

__slots__ = [
"binary_image",
"binary_image_resolved",
"bundles",
"bundle_mapping",
"from_index",
"from_index_resolved",
"index_image",
"removed_operators",
"organization",
"distribution_scope",
]
_operation_attrs = [
"binary_image",
"binary_image_resolved",
"bundles",
"bundle_mapping",
"from_index",
"from_index_resolved",
"index_image",
"removed_operators",
"organization",
"distribution_scope",
]


class RegenerateBundleModel(IIBBuildDetailsModel):

__slots__ = [
"bundle_image",
"from_bundle_image",
"from_bundle_image_resolved",
"organization",
]
_operation_attrs = [
"bundle_image",
"from_bundle_image",
"from_bundle_image_resolved",
"organization",
]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def read_content(filepath):

setup(
name="iiblib",
version="1.0.0",
version="2.0.0",
description="IIB client library",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
Loading

0 comments on commit 529e108

Please sign in to comment.