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