diff --git a/compass/db/api/cluster.py b/compass/db/api/cluster.py index 307b64f9..8bea5b06 100644 --- a/compass/db/api/cluster.py +++ b/compass/db/api/cluster.py @@ -39,9 +39,10 @@ RESP_FIELDS = [ 'created_at', 'updated_at' ] RESP_CLUSTERHOST_FIELDS = [ - 'id', 'host_id', 'machine_id', 'name', 'hostname', + 'id', 'host_id', 'clusterhost_id', 'machine_id', + 'name', 'hostname', 'cluster_id', 'clustername', 'location', 'tag', - 'networks', 'mac', + 'networks', 'mac', 'switch_ip', 'port', 'switches', 'os_installed', 'distributed_system_installed', 'os_name', 'distributed_system_name', 'reinstall_os', 'reinstall_distributed_system', @@ -557,7 +558,7 @@ def get_clusterhost( return utils.get_db_object( session, models.ClusterHost, exception_when_missing, - id=clusterhost_id + clusterhost_id=clusterhost_id ) @@ -611,7 +612,7 @@ def del_clusterhost(session, deleter, clusterhost_id, **kwargs): """Delete cluster host.""" clusterhost = utils.get_db_object( session, models.ClusterHost, - id=clusterhost_id + clusterhost_id=clusterhost_id ) return utils.del_db_object( session, clusterhost @@ -657,7 +658,7 @@ def get_cluster_host_deployed_config( def get_clusterhost_config(session, getter, clusterhost_id, **kwargs): """Get clusterhost config.""" return utils.get_db_object( - session, models.ClusterHost, id=clusterhost_id + session, models.ClusterHost, clusterhost_id=clusterhost_id ) @@ -670,7 +671,7 @@ def get_clusterhost_config(session, getter, clusterhost_id, **kwargs): def get_clusterhost_deployed_config(session, getter, clusterhost_id, **kwargs): """Get clusterhost deployed config.""" return utils.get_db_object( - session, models.ClusterHost, id=clusterhost_id + session, models.ClusterHost, clusterhost_id=clusterhost_id ) @@ -805,7 +806,7 @@ def update_clusterhost_config( ): """Update clusterhost config.""" clusterhost = utils.get_db_object( - session, models.ClusterHost, id=clusterhost_id + session, models.ClusterHost, clusterhost_id=clusterhost_id ) return _update_clusterhost_config( session, updater, clusterhost, **kwargs @@ -822,7 +823,7 @@ def update_clusterhost_deployed_config( ): """Update clusterhost deployed config.""" clusterhost = utils.get_db_object( - session, models.ClusterHost, id=clusterhost_id + session, models.ClusterHost, clusterhost_id=clusterhost_id ) return _update_clusterhost_deployed_config( session, updater, clusterhost, **kwargs @@ -899,7 +900,7 @@ def patch_clusterhost_config( ): """patch clusterhost config.""" clusterhost = utils.get_db_object( - session, models.ClusterHost, id=clusterhost_id + session, models.ClusterHost, clusterhost_id=clusterhost_id ) return _patch_clusterhost_config( session, updater, clusterhost, **kwargs @@ -967,7 +968,7 @@ def delete_cluster_host_config( def delete_clusterhost_config(session, deleter, clusterhost_id): """Delet a clusterhost config.""" clusterhost = utils.get_db_object( - session, models.ClusterHost, id=clusterhost_id + session, models.ClusterHost, clusterhost_id=clusterhost_id ) return _delete_clusterhost_config( session, deleter, clusterhost @@ -1001,9 +1002,7 @@ def update_cluster_hosts( if set_hosts is not None: _set_clusterhosts(session, cluster, **set_hosts) return { - 'hosts': [ - clusterhost.host for clusterhost in cluster.clusterhosts - ] + 'hosts': cluster.clusterhosts } @@ -1075,7 +1074,7 @@ def review_cluster(session, reviewer, cluster_id, review={}, **kwargs): utils.update_db_object(session, cluster, config_validated=True) return { 'cluster': cluster, - 'clusterhosts': clusterhosts + 'hosts': clusterhosts } @@ -1103,7 +1102,7 @@ def deploy_cluster( clusterhosts = [] for clusterhost in cluster.clusterhosts: if ( - clusterhost.id in clusterhost_ids or + clusterhost.clusterhost_id in clusterhost_ids or clusterhost.host_id in host_ids ): clusterhosts.append(clusterhost) @@ -1130,13 +1129,13 @@ def deploy_cluster( 'compass.tasks.deploy_cluster', ( deployer.email, cluster_id, - [clusterhost.id for clusterhost in clusterhosts] + [clusterhost.host_id for clusterhost in clusterhosts] ) ) return { 'status': 'deploy action sent', 'cluster': cluster, - 'clusterhosts': clusterhosts + 'hosts': clusterhosts } diff --git a/compass/db/api/host.py b/compass/db/api/host.py index 21f57581..1f394d16 100644 --- a/compass/db/api/host.py +++ b/compass/db/api/host.py @@ -31,7 +31,8 @@ SUPPORTED_NETOWORK_FIELDS = [ 'interface', 'ip', 'subnet', 'is_mgmt', 'is_promiscuous' ] RESP_FIELDS = [ - 'id', 'name', 'os_name', 'os_id', 'owner', 'mac', + 'id', 'name', 'hostname', 'os_name', 'os_id', 'owner', 'mac', + 'switch_ip', 'port', 'switches', 'reinstall_os', 'os_installed', 'tag', 'location', 'networks', 'created_at', 'updated_at' ] diff --git a/compass/db/api/utils.py b/compass/db/api/utils.py index 779a2582..f017d3fd 100644 --- a/compass/db/api/utils.py +++ b/compass/db/api/utils.py @@ -366,10 +366,6 @@ def _output_validates(kwargs_validators, obj): kwargs_validators[key](value) -def validate_outputs(kwargs_validators, obj): - return _output_validates(kwargs_validators, obj) - - def output_validates(**kwargs_validators): def decorator(func): @functools.wraps(func) diff --git a/compass/db/models.py b/compass/db/models.py index 22b40993..954dab8b 100644 --- a/compass/db/models.py +++ b/compass/db/models.py @@ -388,7 +388,10 @@ class ClusterHostState(BASE, StateMixin): id = Column( Integer, - ForeignKey('clusterhost.id', onupdate='CASCADE', ondelete='CASCADE'), + ForeignKey( + 'clusterhost.id', + onupdate='CASCADE', ondelete='CASCADE' + ), primary_key=True ) @@ -413,7 +416,7 @@ class ClusterHost(BASE, TimestampMixin, HelperMixin): """ClusterHost table.""" __tablename__ = 'clusterhost' - id = Column(Integer, primary_key=True) + clusterhost_id = Column('id', Integer, primary_key=True) cluster_id = Column( Integer, ForeignKey('cluster.id', onupdate='CASCADE', ondelete='CASCADE') @@ -591,18 +594,17 @@ class ClusterHost(BASE, TimestampMixin, HelperMixin): def to_dict(self): dict_info = self.host.to_dict() dict_info.update(super(ClusterHost, self).to_dict()) + state_dict = self.state_dict() dict_info.update({ 'distributed_system_name': self.distributed_system_name, 'distributed_system_installed': self.distributed_system_installed, 'reinstall_distributed_system': self.reinstall_distributed_system, 'owner': self.owner, 'clustername': self.clustername, - 'hostname': self.hostname, - 'name': self.name + 'name': self.name, + 'state': state_dict['state'], + 'roles': self.roles }) - roles = self.roles - if roles: - dict_info['roles'] = [role.to_dict() for role in roles] return dict_info @@ -776,15 +778,18 @@ class Host(BASE, TimestampMixin, HelperMixin): def to_dict(self): dict_info = self.machine.to_dict() dict_info.update(super(Host, self).to_dict()) + state_dict = self.state_dict() dict_info.update({ 'machine_id': self.machine.id, 'owner': self.owner, 'os_installed': self.os_installed, + 'hostname': self.name, 'networks': [ host_network.to_dict() for host_network in self.host_networks ], - 'clusters': [cluster.to_dict() for cluster in self.clusters] + 'clusters': [cluster.to_dict() for cluster in self.clusters], + 'state': state_dict['state'] }) return dict_info @@ -922,6 +927,7 @@ class Cluster(BASE, TimestampMixin, HelperMixin): self.put_package_config = { 'roles': [role.name for role in adapter.roles] } + super(Cluster, self).initialize() def update(self): if self.reinstall_distributed_system: @@ -1646,6 +1652,7 @@ class AdapterRole(BASE, HelperMixin): self.description = self.name if not self.display_name: self.display_name = self.name + super(AdapterRole, self).initialize() class PackageConfigMetadata(BASE, MetadataMixin): @@ -1801,6 +1808,7 @@ class Adapter(BASE, HelperMixin): def initialize(self): if not self.display_name: self.display_name = self.name + super(Adapter, self).initialize() @property def root_metadatas(self):