fix api bug
Change-Id: Icbc5b1da947d988fb8240e7de80084baf3a9cc91
This commit is contained in:
parent
814f35d22e
commit
8710a15261
@ -29,6 +29,7 @@ SUPPORTED_FIELDS = [
|
||||
]
|
||||
RESP_FIELDS = [
|
||||
'id', 'name', 'roles',
|
||||
'os_installer', 'package_installer',
|
||||
'distributed_system_name',
|
||||
'supported_oses', 'display_name'
|
||||
]
|
||||
|
@ -62,8 +62,7 @@ RESP_DEPLOYED_CONFIG_FIELDS = [
|
||||
'updated_at'
|
||||
]
|
||||
RESP_METADATA_FIELDS = [
|
||||
'os_config',
|
||||
'package_config'
|
||||
'metadata'
|
||||
]
|
||||
RESP_CLUSTERHOST_CONFIG_FIELDS = [
|
||||
'package_config',
|
||||
@ -310,10 +309,10 @@ def get_cluster_metadata(session, getter, cluster_id, **kwargs):
|
||||
)
|
||||
adapter = cluster.adapter
|
||||
if adapter:
|
||||
metadatas['package_ocnfig'] = (
|
||||
metadatas['package_config'] = (
|
||||
metadata_api.get_package_metadata_internal(adapter.id)
|
||||
)
|
||||
return metadatas
|
||||
return {'metadata': metadatas}
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
@ -324,10 +323,14 @@ def _update_cluster_config(session, updater, cluster, **kwargs):
|
||||
"""Update a cluster config."""
|
||||
is_cluster_editable(session, cluster, updater)
|
||||
return utils.update_db_object(
|
||||
session, cluster, config_validated=False, **kwargs
|
||||
session, cluster, **kwargs
|
||||
)
|
||||
|
||||
|
||||
@utils.replace_filters(
|
||||
os_config='deployed_os_config',
|
||||
package_config='deployed_package_config'
|
||||
)
|
||||
@utils.supported_filters(
|
||||
optional_support_keys=UPDATED_DEPLOYED_CONFIG_FIELDS
|
||||
)
|
||||
@ -778,7 +781,7 @@ def update_cluster_host_config(
|
||||
package_config='deployed_package_config'
|
||||
)
|
||||
@database.run_in_session()
|
||||
def update_cluster_host_depolyed_config(
|
||||
def update_cluster_host_deployed_config(
|
||||
session, updater, cluster_id, host_id, **kwargs
|
||||
):
|
||||
"""Update clusterhost deployed config."""
|
||||
@ -857,12 +860,12 @@ def _patch_clusterhost_config(session, updater, clusterhost, **kwargs):
|
||||
os_config=os_config_validates,
|
||||
package_config=package_config_validates
|
||||
)
|
||||
def update_config_internal(clusterhost, **in_kwargs):
|
||||
return _update_cluster_config(
|
||||
session, updater, clusterhost, **in_kwargs
|
||||
def patch_config_internal(clusterhost, **in_kwargs):
|
||||
return utils.update_db_object(
|
||||
session, clusterhost, **in_kwargs
|
||||
)
|
||||
|
||||
return update_config_internal(
|
||||
return patch_config_internal(
|
||||
clusterhost, **kwargs
|
||||
)
|
||||
|
||||
@ -927,12 +930,13 @@ def _delete_clusterhost_config(
|
||||
@utils.output_validates(
|
||||
package_config=package_config_validates
|
||||
)
|
||||
def update_config_internal(clusterhost, **in_kwargs):
|
||||
def delete_config_internal(clusterhost, **in_kwargs):
|
||||
return utils.update_db_object(
|
||||
session, clusterhost, **in_kwargs
|
||||
session, clusterhost, config_validated=False,
|
||||
**in_kwargs
|
||||
)
|
||||
|
||||
return update_config_internal(
|
||||
return delete_config_internal(
|
||||
clusterhost, os_config={},
|
||||
package_config={}
|
||||
)
|
||||
@ -1127,7 +1131,7 @@ def deploy_cluster(
|
||||
)
|
||||
|
||||
celery_client.celery.send_task(
|
||||
'compass.tasks.deploy',
|
||||
'compass.tasks.deploy_cluster',
|
||||
(deployer.email, cluster_id, deploy.get('clusterhosts', []))
|
||||
)
|
||||
return {
|
||||
|
@ -324,7 +324,7 @@ def update_host_deployed_config(session, updater, host_id, **kwargs):
|
||||
permission.PERMISSION_ADD_HOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CONFIG_FIELDS)
|
||||
def update_host_config_internal(session, updater, host, **kwargs):
|
||||
def _update_host_config(session, updater, host, **kwargs):
|
||||
"""Update host config."""
|
||||
is_host_editable(session, host, updater)
|
||||
return utils.update_db_object(session, host, **kwargs)
|
||||
@ -347,7 +347,7 @@ def update_host_config(session, updater, host_id, **kwargs):
|
||||
put_os_config=os_config_validates,
|
||||
)
|
||||
def update_config_internal(host, **in_kwargs):
|
||||
return update_host_config_internal(
|
||||
return _update_host_config(
|
||||
session, updater, host, **kwargs
|
||||
)
|
||||
|
||||
@ -372,12 +372,12 @@ def patch_host_config(session, updater, host_id, **kwargs):
|
||||
@utils.output_validates(
|
||||
os_config=os_config_validates,
|
||||
)
|
||||
def update_config_internal(host, **in_kwargs):
|
||||
return update_host_config_internal(
|
||||
def patch_config_internal(host, **in_kwargs):
|
||||
return _update_host_config(
|
||||
session, updater, host, **in_kwargs
|
||||
)
|
||||
|
||||
return update_config_internal(
|
||||
return patch_config_internal(
|
||||
session, updater, host, **kwargs
|
||||
)
|
||||
|
||||
@ -395,7 +395,7 @@ def del_host_config(session, deleter, host_id):
|
||||
)
|
||||
is_host_editable(session, host, deleter)
|
||||
return utils.update_db_object(
|
||||
session, host, os_config={}
|
||||
session, host, os_config={}, config_validated=False
|
||||
)
|
||||
|
||||
|
||||
|
@ -61,7 +61,7 @@ def add_package_field_internal(session):
|
||||
|
||||
|
||||
def _add_metadata(
|
||||
session, field_model, metadata_model, name, config,
|
||||
session, field_model, metadata_model, path, name, config,
|
||||
parent=None, **kwargs
|
||||
):
|
||||
metadata_self = config.get('_self', {})
|
||||
@ -73,7 +73,7 @@ def _add_metadata(
|
||||
field = None
|
||||
metadata = utils.add_db_object(
|
||||
session, metadata_model, True,
|
||||
name, parent=parent, field=field,
|
||||
path, name=name, parent=parent, field=field,
|
||||
display_name=metadata_self.get('display_name', name),
|
||||
description=metadata_self.get('description', None),
|
||||
is_required=metadata_self.get('is_required', False),
|
||||
@ -91,7 +91,8 @@ def _add_metadata(
|
||||
for key, value in config.items():
|
||||
if key not in '_self':
|
||||
_add_metadata(
|
||||
session, field_model, metadata_model, key, value,
|
||||
session, field_model, metadata_model,
|
||||
'%s/%s' % (path, key), key, value,
|
||||
parent=metadata, **kwargs
|
||||
)
|
||||
return metadata
|
||||
@ -111,7 +112,7 @@ def add_os_metadata_internal(session):
|
||||
os_metadatas.append(_add_metadata(
|
||||
session, models.OSConfigField,
|
||||
models.OSConfigMetadata,
|
||||
key, value, parent=None,
|
||||
key, key, value, parent=None,
|
||||
os=os
|
||||
))
|
||||
return os_metadatas
|
||||
@ -131,7 +132,7 @@ def add_package_metadata_internal(session):
|
||||
package_metadatas.append(_add_metadata(
|
||||
session, models.PackageConfigField,
|
||||
models.PackageConfigMetadata,
|
||||
key, value, parent=None,
|
||||
key, key, value, parent=None,
|
||||
adapter=adapter
|
||||
))
|
||||
return package_metadatas
|
||||
|
@ -81,6 +81,7 @@ def _filter_metadata(metadata):
|
||||
'required_in_options': value['required_in_options'],
|
||||
'field_type': value['field_type_data'],
|
||||
'display_type': value.get('display_type', None),
|
||||
'mapping_to': value.get('mapping_to', None)
|
||||
}
|
||||
else:
|
||||
filtered_metadata[key] = _filter_metadata(value)
|
||||
|
@ -210,6 +210,9 @@ def supported_filters(
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **filters):
|
||||
logging.info('support_keys: %s', support_keys)
|
||||
logging.info('optional_support_keys: %s', optional_support_keys)
|
||||
logging.info('ignore_support_keys: %s', ignore_support_keys)
|
||||
must_support_keys = set(support_keys)
|
||||
all_support_keys = must_support_keys | set(optional_support_keys)
|
||||
filter_keys = set(filters)
|
||||
|
@ -105,15 +105,16 @@ class MetadataMixin(HelperMixin):
|
||||
|
||||
def initialize(self):
|
||||
if not self.display_name:
|
||||
if self.name:
|
||||
self.display_name = self.name
|
||||
if self.parent:
|
||||
self.path = '%s/%s' % (self.parent.path, self.name)
|
||||
else:
|
||||
self.path = self.name
|
||||
super(MetadataMixin, self).initialize()
|
||||
|
||||
@property
|
||||
def validator(self):
|
||||
if not self.name:
|
||||
raise exception.InvalidParamter(
|
||||
'name is not set in os metadata %s' % self.id
|
||||
)
|
||||
if not self.validator_data:
|
||||
return None
|
||||
func = eval(
|
||||
@ -520,6 +521,23 @@ class ClusterHost(BASE, TimestampMixin, HelperMixin):
|
||||
def os_installed(self):
|
||||
return self.host.os_installed
|
||||
|
||||
@property
|
||||
def roles(self):
|
||||
package_config = self.package_config
|
||||
if 'roles' in package_config:
|
||||
role_names = package_config['roles']
|
||||
roles = self.cluster.adapter.roles
|
||||
role_mapping = {}
|
||||
for role in roles:
|
||||
role_mapping[role.name] = role
|
||||
filtered_roles = []
|
||||
for role_name in role_names:
|
||||
if role_name in role_mapping:
|
||||
filtered_roles.append(role_mapping[role_name])
|
||||
return filtered_roles
|
||||
else:
|
||||
return None
|
||||
|
||||
@hybrid_property
|
||||
def owner(self):
|
||||
return self.cluster.owner
|
||||
@ -548,7 +566,8 @@ class ClusterHost(BASE, TimestampMixin, HelperMixin):
|
||||
'owner': self.owner,
|
||||
'clustername': self.clustername,
|
||||
'hostname': self.hostname,
|
||||
'name': self.name
|
||||
'name': self.name,
|
||||
'roles': [role.to_dict() for role in self.roles]
|
||||
})
|
||||
return dict_info
|
||||
|
||||
@ -687,6 +706,10 @@ class Host(BASE, TimestampMixin, HelperMixin):
|
||||
def os_installed(self):
|
||||
return self.state.state == 'SUCCESSFUL'
|
||||
|
||||
@property
|
||||
def clusters(self):
|
||||
return [clusterhost.cluster for clusterhost in self.clusterhosts]
|
||||
|
||||
def state_dict(self):
|
||||
return self.state.to_dict()
|
||||
|
||||
@ -700,7 +723,8 @@ class Host(BASE, TimestampMixin, HelperMixin):
|
||||
'networks': [
|
||||
host_network.to_dict()
|
||||
for host_network in self.host_networks
|
||||
]
|
||||
],
|
||||
'clusters': [cluster.to_dict() for cluster in self.clusters]
|
||||
})
|
||||
return dict_info
|
||||
|
||||
@ -1295,6 +1319,21 @@ class Machine(BASE, HelperMixin, TimestampMixin):
|
||||
location.update(value)
|
||||
self.location = location
|
||||
|
||||
def to_dict(self):
|
||||
dict_info = {}
|
||||
dict_info['switches'] = [
|
||||
{
|
||||
'switch_ip': switch_machine.switch_ip,
|
||||
'port': switch_machine.port,
|
||||
'vlans': switch_machine.vlans
|
||||
}
|
||||
for switch_machine in self.switch_machines
|
||||
]
|
||||
if dict_info['switches']:
|
||||
dict_info.update(dict_info['switches'][0])
|
||||
dict_info.update(super(Machine, self).to_dict())
|
||||
return dict_info
|
||||
|
||||
|
||||
class Switch(BASE, HelperMixin, TimestampMixin):
|
||||
"""Switch table."""
|
||||
@ -1393,8 +1432,8 @@ class OSConfigMetadata(BASE, MetadataMixin):
|
||||
UniqueConstraint('path', 'os_id', name='constraint'),
|
||||
)
|
||||
|
||||
def __init__(self, name, **kwargs):
|
||||
self.name = name
|
||||
def __init__(self, path, **kwargs):
|
||||
self.path = path
|
||||
super(OSConfigMetadata, self).__init__(**kwargs)
|
||||
|
||||
def validate(self):
|
||||
@ -1580,9 +1619,9 @@ class PackageConfigMetadata(BASE, MetadataMixin):
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self, name, **kwargs
|
||||
self, path, **kwargs
|
||||
):
|
||||
self.name = name
|
||||
self.path = path
|
||||
super(PackageConfigMetadata, self).__init__(**kwargs)
|
||||
|
||||
def validate(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user