Refactor db api:
1. Increasing flexibility of function parameters. 2. Passing session as a parameter. Change-Id: Idc4171b98dd2c975571734c4567602572ba4dcbc
This commit is contained in:
parent
4419a6d17e
commit
88f167c615
@ -95,7 +95,7 @@ def _filter_adapters(adapter_config, filter_name, filter_value):
|
||||
roles=RESP_ROLES_FIELDS,
|
||||
flavors=RESP_FLAVORS_FIELDS
|
||||
)
|
||||
def list_adapters(session, lister, **filters):
|
||||
def list_adapters(lister, session=None, **filters):
|
||||
"""list adapters."""
|
||||
if not ADAPTER_MAPPING:
|
||||
load_adapters_internal(session)
|
||||
@ -125,6 +125,6 @@ def get_adapter_internal(session, adapter_id):
|
||||
roles=RESP_ROLES_FIELDS,
|
||||
flavors=RESP_FLAVORS_FIELDS
|
||||
)
|
||||
def get_adapter(session, getter, adapter_id, **kwargs):
|
||||
def get_adapter(getter, adapter_id, session=None, **kwargs):
|
||||
"""get adapter."""
|
||||
return get_adapter_internal(session, adapter_id)
|
||||
|
@ -154,7 +154,7 @@ UPDATED_CLUSTERHOST_LOG_FIELDS = [
|
||||
permission.PERMISSION_LIST_CLUSTERS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def list_clusters(session, lister, **filters):
|
||||
def list_clusters(lister, session=None, **filters):
|
||||
"""List clusters."""
|
||||
return utils.list_db_objects(
|
||||
session, models.Cluster, **filters
|
||||
@ -168,8 +168,8 @@ def list_clusters(session, lister, **filters):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def get_cluster(
|
||||
session, getter, cluster_id,
|
||||
exception_when_missing=True, **kwargs
|
||||
getter, cluster_id,
|
||||
exception_when_missing=True, session=None, **kwargs
|
||||
):
|
||||
"""Get cluster info."""
|
||||
return utils.get_db_object(
|
||||
@ -243,9 +243,9 @@ def is_cluster_editable(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def add_cluster(
|
||||
session, creator,
|
||||
creator,
|
||||
exception_when_existing=True,
|
||||
name=None, **kwargs
|
||||
name=None, session=None, **kwargs
|
||||
):
|
||||
"""Create a cluster."""
|
||||
return utils.add_db_object(
|
||||
@ -265,7 +265,7 @@ def add_cluster(
|
||||
permission.PERMISSION_ADD_CLUSTER
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def update_cluster(session, updater, cluster_id, **kwargs):
|
||||
def update_cluster(updater, cluster_id, session=None, **kwargs):
|
||||
"""Update a cluster."""
|
||||
cluster = utils.get_db_object(
|
||||
session, models.Cluster, id=cluster_id
|
||||
@ -301,9 +301,9 @@ def update_cluster(session, updater, cluster_id, **kwargs):
|
||||
hosts=RESP_CLUSTERHOST_FIELDS
|
||||
)
|
||||
def del_cluster(
|
||||
session, deleter, cluster_id,
|
||||
deleter, cluster_id,
|
||||
force=False, from_database_only=False,
|
||||
delete_underlying_host=False, **kwargs
|
||||
delete_underlying_host=False, session=None, **kwargs
|
||||
):
|
||||
"""Delete a cluster."""
|
||||
cluster = utils.get_db_object(
|
||||
@ -371,7 +371,7 @@ def del_cluster(
|
||||
permission.PERMISSION_LIST_CLUSTER_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CONFIG_FIELDS)
|
||||
def get_cluster_config(session, getter, cluster_id, **kwargs):
|
||||
def get_cluster_config(getter, cluster_id, session=None, **kwargs):
|
||||
"""Get cluster config."""
|
||||
return utils.get_db_object(
|
||||
session, models.Cluster, id=cluster_id
|
||||
@ -384,7 +384,7 @@ def get_cluster_config(session, getter, cluster_id, **kwargs):
|
||||
permission.PERMISSION_LIST_CLUSTER_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_DEPLOYED_CONFIG_FIELDS)
|
||||
def get_cluster_deployed_config(session, getter, cluster_id, **kwargs):
|
||||
def get_cluster_deployed_config(getter, cluster_id, session=None, **kwargs):
|
||||
"""Get cluster deployed config."""
|
||||
return utils.get_db_object(
|
||||
session, models.Cluster, id=cluster_id
|
||||
@ -397,7 +397,7 @@ def get_cluster_deployed_config(session, getter, cluster_id, **kwargs):
|
||||
permission.PERMISSION_LIST_METADATAS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_METADATA_FIELDS)
|
||||
def get_cluster_metadata(session, getter, cluster_id, **kwargs):
|
||||
def get_cluster_metadata(getter, cluster_id, session=None, **kwargs):
|
||||
"""Get cluster metadata."""
|
||||
cluster = utils.get_db_object(
|
||||
session, models.Cluster, id=cluster_id
|
||||
@ -418,9 +418,6 @@ def get_cluster_metadata(session, getter, cluster_id, **kwargs):
|
||||
return metadatas
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_CLUSTER_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CONFIG_FIELDS)
|
||||
def _update_cluster_config(session, updater, cluster, **kwargs):
|
||||
"""Update a cluster config."""
|
||||
@ -444,7 +441,7 @@ def _update_cluster_config(session, updater, cluster, **kwargs):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_DEPLOYED_CONFIG_FIELDS)
|
||||
def update_cluster_deployed_config(
|
||||
session, updater, cluster_id, **kwargs
|
||||
updater, cluster_id, session=None, **kwargs
|
||||
):
|
||||
"""Update cluster deployed config."""
|
||||
cluster = utils.get_db_object(
|
||||
@ -466,7 +463,10 @@ def update_cluster_deployed_config(
|
||||
ignore_support_keys=IGNORE_FIELDS
|
||||
)
|
||||
@database.run_in_session()
|
||||
def update_cluster_config(session, updater, cluster_id, **kwargs):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_CLUSTER_CONFIG
|
||||
)
|
||||
def update_cluster_config(updater, cluster_id, session=None, **kwargs):
|
||||
"""Update cluster config."""
|
||||
cluster = utils.get_db_object(
|
||||
session, models.Cluster, id=cluster_id
|
||||
@ -507,7 +507,10 @@ def update_cluster_config(session, updater, cluster_id, **kwargs):
|
||||
ignore_support_keys=IGNORE_FIELDS
|
||||
)
|
||||
@database.run_in_session()
|
||||
def patch_cluster_config(session, updater, cluster_id, **kwargs):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_CLUSTER_CONFIG
|
||||
)
|
||||
def patch_cluster_config(updater, cluster_id, session=None, **kwargs):
|
||||
"""patch cluster config."""
|
||||
cluster = utils.get_db_object(
|
||||
session, models.Cluster, id=cluster_id
|
||||
@ -543,7 +546,7 @@ def patch_cluster_config(session, updater, cluster_id, **kwargs):
|
||||
permission.PERMISSION_DEL_CLUSTER_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CONFIG_FIELDS)
|
||||
def del_cluster_config(session, deleter, cluster_id):
|
||||
def del_cluster_config(deleter, cluster_id, session=None):
|
||||
"""Delete a cluster config."""
|
||||
cluster = utils.get_db_object(
|
||||
session, models.Cluster, id=cluster_id
|
||||
@ -669,7 +672,7 @@ def _set_clusterhosts(session, cluster, machines):
|
||||
permission.PERMISSION_LIST_CLUSTERHOSTS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_FIELDS)
|
||||
def list_cluster_hosts(session, lister, cluster_id, **filters):
|
||||
def list_cluster_hosts(lister, cluster_id, session=None, **filters):
|
||||
"""Get cluster host info."""
|
||||
return utils.list_db_objects(
|
||||
session, models.ClusterHost, cluster_id=cluster_id,
|
||||
@ -683,7 +686,7 @@ def list_cluster_hosts(session, lister, cluster_id, **filters):
|
||||
permission.PERMISSION_LIST_CLUSTERHOSTS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_FIELDS)
|
||||
def list_clusterhosts(session, lister, **filters):
|
||||
def list_clusterhosts(lister, session=None, **filters):
|
||||
"""Get cluster host info."""
|
||||
return utils.list_db_objects(
|
||||
session, models.ClusterHost, **filters
|
||||
@ -697,8 +700,8 @@ def list_clusterhosts(session, lister, **filters):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_FIELDS)
|
||||
def get_cluster_host(
|
||||
session, getter, cluster_id, host_id,
|
||||
exception_when_missing=True, **kwargs
|
||||
getter, cluster_id, host_id,
|
||||
exception_when_missing=True, session=None, **kwargs
|
||||
):
|
||||
"""Get clusterhost info."""
|
||||
return utils.get_db_object(
|
||||
@ -715,8 +718,8 @@ def get_cluster_host(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_FIELDS)
|
||||
def get_clusterhost(
|
||||
session, getter, clusterhost_id,
|
||||
exception_when_missing=True, **kwargs
|
||||
getter, clusterhost_id,
|
||||
exception_when_missing=True, session=None, **kwargs
|
||||
):
|
||||
"""Get clusterhost info."""
|
||||
return utils.get_db_object(
|
||||
@ -732,8 +735,8 @@ def get_clusterhost(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_FIELDS)
|
||||
def add_cluster_host(
|
||||
session, creator, cluster_id,
|
||||
exception_when_existing=True, **kwargs
|
||||
creator, cluster_id,
|
||||
exception_when_existing=True, session=None, **kwargs
|
||||
):
|
||||
"""Add cluster host."""
|
||||
cluster = utils.get_db_object(
|
||||
@ -746,9 +749,6 @@ def add_cluster_host(
|
||||
)
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_UPDATE_CLUSTER_HOSTS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_FIELDS)
|
||||
def _update_clusterhost(session, updater, clusterhost, **kwargs):
|
||||
clusterhost_dict = {}
|
||||
@ -835,9 +835,12 @@ def _update_clusterhost(session, updater, clusterhost, **kwargs):
|
||||
ignore_support_keys=IGNORE_FIELDS
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_UPDATE_CLUSTER_HOSTS
|
||||
)
|
||||
def update_cluster_host(
|
||||
session, updater, cluster_id, host_id,
|
||||
**kwargs
|
||||
updater, cluster_id, host_id,
|
||||
session=None, **kwargs
|
||||
):
|
||||
"""Update cluster host."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -851,9 +854,12 @@ def update_cluster_host(
|
||||
ignore_support_keys=IGNORE_FIELDS
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_UPDATE_CLUSTER_HOSTS
|
||||
)
|
||||
def update_clusterhost(
|
||||
session, updater, clusterhost_id,
|
||||
**kwargs
|
||||
updater, clusterhost_id,
|
||||
session=None, **kwargs
|
||||
):
|
||||
"""Update cluster host."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -870,8 +876,11 @@ def update_clusterhost(
|
||||
ignore_support_keys=IGNORE_FIELDS
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_UPDATE_CLUSTER_HOSTS
|
||||
)
|
||||
def patch_cluster_host(
|
||||
session, updater, cluster_id, host_id,
|
||||
updater, cluster_id, host_id, session=None,
|
||||
**kwargs
|
||||
):
|
||||
"""Update cluster host."""
|
||||
@ -889,8 +898,11 @@ def patch_cluster_host(
|
||||
ignore_support_keys=IGNORE_FIELDS
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_UPDATE_CLUSTER_HOSTS
|
||||
)
|
||||
def patch_clusterhost(
|
||||
session, updater, clusterhost_id,
|
||||
updater, clusterhost_id, session=None,
|
||||
**kwargs
|
||||
):
|
||||
"""Update cluster host."""
|
||||
@ -910,10 +922,10 @@ def patch_clusterhost(
|
||||
host=RESP_CLUSTERHOST_FIELDS
|
||||
)
|
||||
def del_cluster_host(
|
||||
session, deleter, cluster_id, host_id,
|
||||
deleter, cluster_id, host_id,
|
||||
force=False, from_database_only=False,
|
||||
delete_underlying_host=False,
|
||||
**kwargs
|
||||
session=None, **kwargs
|
||||
):
|
||||
"""Delete cluster host."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -978,10 +990,10 @@ def del_cluster_host(
|
||||
host=RESP_CLUSTERHOST_FIELDS
|
||||
)
|
||||
def del_clusterhost(
|
||||
session, deleter, clusterhost_id,
|
||||
deleter, clusterhost_id,
|
||||
force=False, from_database_only=False,
|
||||
delete_underlying_host=False,
|
||||
**kwargs
|
||||
session=None, **kwargs
|
||||
):
|
||||
"""Delete cluster host."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -1039,7 +1051,10 @@ def del_clusterhost(
|
||||
permission.PERMISSION_LIST_CLUSTERHOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_CONFIG_FIELDS)
|
||||
def get_cluster_host_config(session, getter, cluster_id, host_id, **kwargs):
|
||||
def get_cluster_host_config(
|
||||
getter, cluster_id,
|
||||
host_id, session=None, **kwargs
|
||||
):
|
||||
"""Get clusterhost config."""
|
||||
return utils.get_db_object(
|
||||
session, models.ClusterHost,
|
||||
@ -1054,7 +1069,7 @@ def get_cluster_host_config(session, getter, cluster_id, host_id, **kwargs):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_DEPLOYED_CONFIG_FIELDS)
|
||||
def get_cluster_host_deployed_config(
|
||||
session, getter, cluster_id, host_id, **kwargs
|
||||
getter, cluster_id, host_id, session=None, **kwargs
|
||||
):
|
||||
"""Get clusterhost deployed config."""
|
||||
return utils.get_db_object(
|
||||
@ -1069,7 +1084,7 @@ def get_cluster_host_deployed_config(
|
||||
permission.PERMISSION_LIST_CLUSTERHOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_CONFIG_FIELDS)
|
||||
def get_clusterhost_config(session, getter, clusterhost_id, **kwargs):
|
||||
def get_clusterhost_config(getter, clusterhost_id, session=None, **kwargs):
|
||||
"""Get clusterhost config."""
|
||||
return utils.get_db_object(
|
||||
session, models.ClusterHost, clusterhost_id=clusterhost_id
|
||||
@ -1082,16 +1097,16 @@ def get_clusterhost_config(session, getter, clusterhost_id, **kwargs):
|
||||
permission.PERMISSION_LIST_CLUSTERHOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_DEPLOYED_CONFIG_FIELDS)
|
||||
def get_clusterhost_deployed_config(session, getter, clusterhost_id, **kwargs):
|
||||
def get_clusterhost_deployed_config(
|
||||
getter, clusterhost_id,
|
||||
session=None, **kwargs
|
||||
):
|
||||
"""Get clusterhost deployed config."""
|
||||
return utils.get_db_object(
|
||||
session, models.ClusterHost, clusterhost_id=clusterhost_id
|
||||
)
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_CLUSTERHOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_CONFIG_FIELDS)
|
||||
def _update_clusterhost_config(session, updater, clusterhost, **kwargs):
|
||||
from compass.db.api import host as host_api
|
||||
@ -1132,9 +1147,6 @@ def _update_clusterhost_config(session, updater, clusterhost, **kwargs):
|
||||
)
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_CLUSTERHOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_DEPLOYED_CONFIG_FIELDS)
|
||||
def _update_clusterhost_deployed_config(
|
||||
session, updater, clusterhost, **kwargs
|
||||
@ -1179,8 +1191,11 @@ def _update_clusterhost_deployed_config(
|
||||
package_config='put_package_config'
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_CLUSTERHOST_CONFIG
|
||||
)
|
||||
def update_cluster_host_config(
|
||||
session, updater, cluster_id, host_id, **kwargs
|
||||
updater, cluster_id, host_id, session=None, **kwargs
|
||||
):
|
||||
"""Update clusterhost config."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -1197,8 +1212,11 @@ def update_cluster_host_config(
|
||||
package_config='deployed_package_config'
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_CLUSTERHOST_CONFIG
|
||||
)
|
||||
def update_cluster_host_deployed_config(
|
||||
session, updater, cluster_id, host_id, **kwargs
|
||||
updater, cluster_id, host_id, session=None, **kwargs
|
||||
):
|
||||
"""Update clusterhost deployed config."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -1215,8 +1233,11 @@ def update_cluster_host_deployed_config(
|
||||
package_config='put_package_config'
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_CLUSTERHOST_CONFIG
|
||||
)
|
||||
def update_clusterhost_config(
|
||||
session, updater, clusterhost_id, **kwargs
|
||||
updater, clusterhost_id, session=None, **kwargs
|
||||
):
|
||||
"""Update clusterhost config."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -1232,8 +1253,11 @@ def update_clusterhost_config(
|
||||
package_config='deployed_package_config'
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_CLUSTERHOST_CONFIG
|
||||
)
|
||||
def update_clusterhost_deployed_config(
|
||||
session, updater, clusterhost_id, **kwargs
|
||||
updater, clusterhost_id, session=None, **kwargs
|
||||
):
|
||||
"""Update clusterhost deployed config."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -1244,9 +1268,6 @@ def update_clusterhost_deployed_config(
|
||||
)
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_CLUSTERHOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_CONFIG_FIELDS)
|
||||
def _patch_clusterhost_config(session, updater, clusterhost, **kwargs):
|
||||
from compass.db.api import host as host_api
|
||||
@ -1291,8 +1312,11 @@ def _patch_clusterhost_config(session, updater, clusterhost, **kwargs):
|
||||
package_config='patched_package_config'
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_CLUSTERHOST_CONFIG
|
||||
)
|
||||
def patch_cluster_host_config(
|
||||
session, updater, cluster_id, host_id, **kwargs
|
||||
updater, cluster_id, host_id, session=None, **kwargs
|
||||
):
|
||||
"""patch clusterhost config."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -1309,8 +1333,11 @@ def patch_cluster_host_config(
|
||||
package_config='patched_package_config'
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_CLUSTERHOST_CONFIG
|
||||
)
|
||||
def patch_clusterhost_config(
|
||||
session, updater, clusterhost_id, **kwargs
|
||||
updater, clusterhost_id, session=None, **kwargs
|
||||
):
|
||||
"""patch clusterhost config."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -1321,9 +1348,6 @@ def patch_clusterhost_config(
|
||||
)
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_DEL_CLUSTERHOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_CONFIG_FIELDS)
|
||||
def _delete_clusterhost_config(
|
||||
session, deleter, clusterhost
|
||||
@ -1360,8 +1384,11 @@ def _delete_clusterhost_config(
|
||||
|
||||
@utils.supported_filters([])
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_DEL_CLUSTERHOST_CONFIG
|
||||
)
|
||||
def delete_cluster_host_config(
|
||||
session, deleter, cluster_id, host_id
|
||||
deleter, cluster_id, host_id, session=None
|
||||
):
|
||||
"""Delete a clusterhost config."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -1379,7 +1406,7 @@ def delete_cluster_host_config(
|
||||
permission.PERMISSION_DEL_CLUSTERHOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_CONFIG_FIELDS)
|
||||
def delete_clusterhost_config(session, deleter, clusterhost_id):
|
||||
def delete_clusterhost_config(deleter, clusterhost_id, session=None):
|
||||
"""Delet a clusterhost config."""
|
||||
clusterhost = utils.get_db_object(
|
||||
session, models.ClusterHost, clusterhost_id=clusterhost_id
|
||||
@ -1401,8 +1428,8 @@ def delete_clusterhost_config(session, deleter, clusterhost_id):
|
||||
hosts=RESP_CLUSTERHOST_FIELDS
|
||||
)
|
||||
def update_cluster_hosts(
|
||||
session, updater, cluster_id, add_hosts={}, set_hosts=None,
|
||||
remove_hosts={}
|
||||
updater, cluster_id, add_hosts={}, set_hosts=None,
|
||||
remove_hosts={}, session=None
|
||||
):
|
||||
"""Update cluster hosts."""
|
||||
cluster = utils.get_db_object(
|
||||
@ -1487,7 +1514,7 @@ def validate_cluster(session, cluster):
|
||||
cluster=RESP_CONFIG_FIELDS,
|
||||
hosts=RESP_CLUSTERHOST_CONFIG_FIELDS
|
||||
)
|
||||
def review_cluster(session, reviewer, cluster_id, review={}, **kwargs):
|
||||
def review_cluster(reviewer, cluster_id, review={}, session=None, **kwargs):
|
||||
"""review cluster."""
|
||||
from compass.db.api import host as host_api
|
||||
cluster = utils.get_db_object(
|
||||
@ -1589,7 +1616,7 @@ def review_cluster(session, reviewer, cluster_id, review={}, **kwargs):
|
||||
hosts=RESP_CLUSTERHOST_FIELDS
|
||||
)
|
||||
def deploy_cluster(
|
||||
session, deployer, cluster_id, deploy={}, **kwargs
|
||||
deployer, cluster_id, deploy={}, session=None, **kwargs
|
||||
):
|
||||
"""deploy cluster."""
|
||||
from compass.db.api import host as host_api
|
||||
@ -1645,7 +1672,7 @@ def deploy_cluster(
|
||||
permission.PERMISSION_GET_CLUSTER_STATE
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_STATE_FIELDS)
|
||||
def get_cluster_state(session, getter, cluster_id, **kwargs):
|
||||
def get_cluster_state(getter, cluster_id, session=None, **kwargs):
|
||||
"""Get cluster state info."""
|
||||
return utils.get_db_object(
|
||||
session, models.Cluster, id=cluster_id
|
||||
@ -1659,7 +1686,7 @@ def get_cluster_state(session, getter, cluster_id, **kwargs):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_STATE_FIELDS)
|
||||
def get_cluster_host_state(
|
||||
session, getter, cluster_id, host_id, **kwargs
|
||||
getter, cluster_id, host_id, session=None, **kwargs
|
||||
):
|
||||
"""Get clusterhost state info."""
|
||||
return utils.get_db_object(
|
||||
@ -1675,7 +1702,7 @@ def get_cluster_host_state(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_STATE_FIELDS)
|
||||
def get_cluster_host_self_state(
|
||||
session, getter, cluster_id, host_id, **kwargs
|
||||
getter, cluster_id, host_id, session=None, **kwargs
|
||||
):
|
||||
"""Get clusterhost state info."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -1695,7 +1722,7 @@ def get_cluster_host_self_state(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_STATE_FIELDS)
|
||||
def get_clusterhost_state(
|
||||
session, getter, clusterhost_id, **kwargs
|
||||
getter, clusterhost_id, session=None, **kwargs
|
||||
):
|
||||
"""Get clusterhost state info."""
|
||||
return utils.get_db_object(
|
||||
@ -1711,7 +1738,7 @@ def get_clusterhost_state(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_STATE_FIELDS)
|
||||
def get_clusterhost_self_state(
|
||||
session, getter, clusterhost_id, **kwargs
|
||||
getter, clusterhost_id, session=None, **kwargs
|
||||
):
|
||||
"""Get clusterhost state info."""
|
||||
return utils.get_db_object(
|
||||
@ -1730,7 +1757,7 @@ def get_clusterhost_self_state(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_STATE_FIELDS)
|
||||
def update_cluster_host_state(
|
||||
session, updater, cluster_id, host_id, **kwargs
|
||||
updater, cluster_id, host_id, session=None, **kwargs
|
||||
):
|
||||
"""Update a clusterhost state."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -1751,7 +1778,7 @@ def update_cluster_host_state(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_STATE_FIELDS)
|
||||
def update_clusterhost_state(
|
||||
session, updater, clusterhost_id, **kwargs
|
||||
updater, clusterhost_id, session=None, **kwargs
|
||||
):
|
||||
"""Update a clusterhost state."""
|
||||
clusterhost = utils.get_db_object(
|
||||
@ -1772,7 +1799,7 @@ def update_clusterhost_state(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_STATE_FIELDS)
|
||||
def update_cluster_state(
|
||||
session, updater, cluster_id, **kwargs
|
||||
updater, cluster_id, session=None, **kwargs
|
||||
):
|
||||
"""Update a cluster state."""
|
||||
cluster = utils.get_db_object(
|
||||
@ -1786,7 +1813,7 @@ def update_cluster_state(
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_LOG_FIELDS)
|
||||
def get_cluster_host_log_histories(
|
||||
session, getter, cluster_id, host_id, **kwargs
|
||||
getter, cluster_id, host_id, session=None, **kwargs
|
||||
):
|
||||
"""Get clusterhost log history."""
|
||||
return utils.list_db_objects(
|
||||
@ -1798,7 +1825,10 @@ def get_cluster_host_log_histories(
|
||||
@utils.supported_filters([])
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_LOG_FIELDS)
|
||||
def get_clusterhost_log_histories(session, getter, clusterhost_id, **kwargs):
|
||||
def get_clusterhost_log_histories(
|
||||
getter, clusterhost_id,
|
||||
session=None, **kwargs
|
||||
):
|
||||
"""Get clusterhost log history."""
|
||||
return utils.list_db_objects(
|
||||
session, models.ClusterHostLogHistory, clusterhost_id=clusterhost_id
|
||||
@ -1809,7 +1839,7 @@ def get_clusterhost_log_histories(session, getter, clusterhost_id, **kwargs):
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_LOG_FIELDS)
|
||||
def get_cluster_host_log_history(
|
||||
session, getter, cluster_id, host_id, filename, **kwargs
|
||||
getter, cluster_id, host_id, filename, session=None, **kwargs
|
||||
):
|
||||
"""Get clusterhost log history."""
|
||||
return utils.get_db_object(
|
||||
@ -1822,7 +1852,7 @@ def get_cluster_host_log_history(
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_LOG_FIELDS)
|
||||
def get_clusterhost_log_history(
|
||||
session, getter, clusterhost_id, filename, **kwargs
|
||||
getter, clusterhost_id, filename, session=None, **kwargs
|
||||
):
|
||||
"""Get host log history."""
|
||||
return utils.get_db_object(
|
||||
@ -1838,7 +1868,7 @@ def get_clusterhost_log_history(
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_LOG_FIELDS)
|
||||
def update_cluster_host_log_history(
|
||||
session, updater, cluster_id, host_id, filename, **kwargs
|
||||
updater, cluster_id, host_id, filename, session=None, **kwargs
|
||||
):
|
||||
"""Update a host log history."""
|
||||
cluster_host_log_history = utils.get_db_object(
|
||||
@ -1855,7 +1885,7 @@ def update_cluster_host_log_history(
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_LOG_FIELDS)
|
||||
def update_clusterhost_log_history(
|
||||
session, updater, clusterhost_id, filename, **kwargs
|
||||
updater, clusterhost_id, filename, session=None, **kwargs
|
||||
):
|
||||
"""Update a host log history."""
|
||||
clusterhost_log_history = utils.get_db_object(
|
||||
@ -1873,8 +1903,8 @@ def update_clusterhost_log_history(
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_LOG_FIELDS)
|
||||
def add_clusterhost_log_history(
|
||||
session, creator, clusterhost_id, exception_when_existing=False,
|
||||
filename=None, **kwargs
|
||||
creator, clusterhost_id, exception_when_existing=False,
|
||||
filename=None, session=None, **kwargs
|
||||
):
|
||||
"""add a host log history."""
|
||||
return utils.add_db_object(
|
||||
@ -1891,8 +1921,8 @@ def add_clusterhost_log_history(
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_CLUSTERHOST_LOG_FIELDS)
|
||||
def add_cluster_host_log_history(
|
||||
session, creator, cluster_id, host_id, exception_when_existing=False,
|
||||
filename=None, **kwargs
|
||||
creator, cluster_id, host_id, exception_when_existing=False,
|
||||
filename=None, session=None, **kwargs
|
||||
):
|
||||
"""add a host log history."""
|
||||
clusterhost = utils.get_db_object(
|
||||
|
@ -149,8 +149,14 @@ def run_in_session():
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
with session() as my_session:
|
||||
return func(my_session, *args, **kwargs)
|
||||
if args is not () and 'session' in str(args[-1]):
|
||||
return func(*args, **kwargs)
|
||||
elif 'session' in kwargs.keys():
|
||||
return func(*args, **kwargs)
|
||||
else:
|
||||
with session() as my_session:
|
||||
kwargs['session'] = my_session
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
@ -289,24 +295,24 @@ def _update_others(other_session):
|
||||
|
||||
|
||||
@run_in_session()
|
||||
def create_db(my_session):
|
||||
def create_db(session):
|
||||
"""Create database."""
|
||||
models.BASE.metadata.create_all(bind=ENGINE)
|
||||
_setup_permission_table(my_session)
|
||||
_setup_user_table(my_session)
|
||||
_setup_switch_table(my_session)
|
||||
_setup_os_installers(my_session)
|
||||
_setup_package_installers(my_session)
|
||||
_setup_oses(my_session)
|
||||
_setup_distributed_systems(my_session)
|
||||
_setup_adapters(my_session)
|
||||
_setup_adapter_roles(my_session)
|
||||
_setup_adapter_flavors(my_session)
|
||||
_setup_os_fields(my_session)
|
||||
_setup_package_fields(my_session)
|
||||
_setup_os_metadatas(my_session)
|
||||
_setup_package_metadatas(my_session)
|
||||
_update_others(my_session)
|
||||
_setup_permission_table(session)
|
||||
_setup_user_table(session)
|
||||
_setup_switch_table(session)
|
||||
_setup_os_installers(session)
|
||||
_setup_package_installers(session)
|
||||
_setup_oses(session)
|
||||
_setup_distributed_systems(session)
|
||||
_setup_adapters(session)
|
||||
_setup_adapter_roles(session)
|
||||
_setup_adapter_flavors(session)
|
||||
_setup_os_fields(session)
|
||||
_setup_package_fields(session)
|
||||
_setup_os_metadatas(session)
|
||||
_setup_package_metadatas(session)
|
||||
_update_others(session)
|
||||
|
||||
|
||||
def drop_db():
|
||||
|
@ -107,7 +107,7 @@ UPDATED_LOG_FIELDS = [
|
||||
permission.PERMISSION_LIST_HOSTS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def list_hosts(session, lister, **filters):
|
||||
def list_hosts(lister, session=None, **filters):
|
||||
"""List hosts."""
|
||||
return utils.list_db_objects(
|
||||
session, models.Host, **filters
|
||||
@ -128,7 +128,7 @@ def list_hosts(session, lister, **filters):
|
||||
os_id=utils.general_filter_callback
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def list_machines_or_hosts(session, lister, **filters):
|
||||
def list_machines_or_hosts(lister, session=None, **filters):
|
||||
"""List hosts."""
|
||||
machines = utils.list_db_objects(
|
||||
session, models.Machine, **filters
|
||||
@ -150,8 +150,8 @@ def list_machines_or_hosts(session, lister, **filters):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def get_host(
|
||||
session, getter, host_id,
|
||||
exception_when_missing=True, **kwargs
|
||||
getter, host_id,
|
||||
exception_when_missing=True, session=None, **kwargs
|
||||
):
|
||||
"""get host info."""
|
||||
return utils.get_db_object(
|
||||
@ -167,8 +167,8 @@ def get_host(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def get_machine_or_host(
|
||||
session, getter, host_id,
|
||||
exception_when_missing=True, **kwargs
|
||||
getter, host_id,
|
||||
exception_when_missing=True, session=None, **kwargs
|
||||
):
|
||||
"""get host info."""
|
||||
machine = utils.get_db_object(
|
||||
@ -190,7 +190,7 @@ def get_machine_or_host(
|
||||
permission.PERMISSION_LIST_HOST_CLUSTERS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CLUSTER_FIELDS)
|
||||
def get_host_clusters(session, getter, host_id, **kwargs):
|
||||
def get_host_clusters(getter, host_id, session=None, **kwargs):
|
||||
"""get host clusters."""
|
||||
host = utils.get_db_object(
|
||||
session, models.Host, id=host_id
|
||||
@ -303,7 +303,7 @@ def _update_host(session, updater, host_id, **kwargs):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_UPDATE_HOST
|
||||
)
|
||||
def update_host(session, updater, host_id, **kwargs):
|
||||
def update_host(updater, host_id, session=None, **kwargs):
|
||||
"""Update a host."""
|
||||
return _update_host(session, updater, host_id=host_id, **kwargs)
|
||||
|
||||
@ -312,7 +312,7 @@ def update_host(session, updater, host_id, **kwargs):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_UPDATE_HOST
|
||||
)
|
||||
def update_hosts(session, updater, data=[]):
|
||||
def update_hosts(updater, data=[], session=None):
|
||||
hosts = []
|
||||
for host_data in data:
|
||||
hosts.append(_update_host(session, updater, **host_data))
|
||||
@ -329,8 +329,8 @@ def update_hosts(session, updater, data=[]):
|
||||
host=RESP_FIELDS
|
||||
)
|
||||
def del_host(
|
||||
session, deleter, host_id,
|
||||
force=False, from_database_only=False, **kwargs
|
||||
deleter, host_id,
|
||||
force=False, from_database_only=False, session=None, **kwargs
|
||||
):
|
||||
"""Delete a host."""
|
||||
from compass.db.api import cluster as cluster_api
|
||||
@ -378,7 +378,7 @@ def del_host(
|
||||
permission.PERMISSION_LIST_HOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CONFIG_FIELDS)
|
||||
def get_host_config(session, getter, host_id, **kwargs):
|
||||
def get_host_config(getter, host_id, session=None, **kwargs):
|
||||
"""Get host config."""
|
||||
return utils.get_db_object(
|
||||
session, models.Host, id=host_id
|
||||
@ -391,7 +391,7 @@ def get_host_config(session, getter, host_id, **kwargs):
|
||||
permission.PERMISSION_LIST_HOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_DEPLOYED_CONFIG_FIELDS)
|
||||
def get_host_deployed_config(session, getter, host_id, **kwargs):
|
||||
def get_host_deployed_config(getter, host_id, session=None, **kwargs):
|
||||
"""Get host deployed config."""
|
||||
return utils.get_db_object(
|
||||
session, models.Host, id=host_id
|
||||
@ -410,7 +410,7 @@ def get_host_deployed_config(session, getter, host_id, **kwargs):
|
||||
permission.PERMISSION_ADD_HOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CONFIG_FIELDS)
|
||||
def update_host_deployed_config(session, updater, host_id, **kwargs):
|
||||
def update_host_deployed_config(updater, host_id, session=None, **kwargs):
|
||||
"""Update host deployed config."""
|
||||
host = utils.get_db_object(
|
||||
session, models.Host, id=host_id
|
||||
@ -420,9 +420,6 @@ def update_host_deployed_config(session, updater, host_id, **kwargs):
|
||||
return utils.update_db_object(session, host, **kwargs)
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_HOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CONFIG_FIELDS)
|
||||
def _update_host_config(session, updater, host, **kwargs):
|
||||
"""Update host config."""
|
||||
@ -438,7 +435,10 @@ def _update_host_config(session, updater, host, **kwargs):
|
||||
ignore_support_keys=IGNORE_FIELDS
|
||||
)
|
||||
@database.run_in_session()
|
||||
def update_host_config(session, updater, host_id, **kwargs):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_HOST_CONFIG
|
||||
)
|
||||
def update_host_config(updater, host_id, session=None, **kwargs):
|
||||
host = utils.get_db_object(
|
||||
session, models.Host, id=host_id
|
||||
)
|
||||
@ -469,7 +469,10 @@ def update_host_config(session, updater, host_id, **kwargs):
|
||||
ignore_support_keys=IGNORE_FIELDS
|
||||
)
|
||||
@database.run_in_session()
|
||||
def patch_host_config(session, updater, host_id, **kwargs):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_HOST_CONFIG
|
||||
)
|
||||
def patch_host_config(updater, host_id, session=None, **kwargs):
|
||||
host = utils.get_db_object(
|
||||
session, models.Host, id=host_id
|
||||
)
|
||||
@ -498,7 +501,7 @@ def patch_host_config(session, updater, host_id, **kwargs):
|
||||
permission.PERMISSION_DEL_HOST_CONFIG
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_CONFIG_FIELDS)
|
||||
def del_host_config(session, deleter, host_id):
|
||||
def del_host_config(deleter, host_id, session=None):
|
||||
"""delete a host config."""
|
||||
host = utils.get_db_object(
|
||||
session, models.Host, id=host_id
|
||||
@ -517,7 +520,7 @@ def del_host_config(session, deleter, host_id):
|
||||
permission.PERMISSION_LIST_HOST_NETWORKS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_NETWORK_FIELDS)
|
||||
def list_host_networks(session, lister, host_id, **filters):
|
||||
def list_host_networks(lister, host_id, session=None, **filters):
|
||||
"""Get host networks."""
|
||||
return utils.list_db_objects(
|
||||
session, models.HostNetwork,
|
||||
@ -533,7 +536,7 @@ def list_host_networks(session, lister, host_id, **filters):
|
||||
permission.PERMISSION_LIST_HOST_NETWORKS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_NETWORK_FIELDS)
|
||||
def list_hostnetworks(session, lister, **filters):
|
||||
def list_hostnetworks(lister, session=None, **filters):
|
||||
"""Get host networks."""
|
||||
return utils.list_db_objects(
|
||||
session, models.HostNetwork, **filters
|
||||
@ -547,8 +550,8 @@ def list_hostnetworks(session, lister, **filters):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_NETWORK_FIELDS)
|
||||
def get_host_network(
|
||||
session, getter, host_id,
|
||||
host_network_id, **kwargs
|
||||
getter, host_id,
|
||||
host_network_id, session=None, **kwargs
|
||||
):
|
||||
"""Get host network."""
|
||||
host_network = utils.get_db_object(
|
||||
@ -570,7 +573,7 @@ def get_host_network(
|
||||
permission.PERMISSION_LIST_HOST_NETWORKS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_NETWORK_FIELDS)
|
||||
def get_hostnetwork(session, getter, host_network_id, **kwargs):
|
||||
def get_hostnetwork(getter, host_network_id, session=None, **kwargs):
|
||||
"""Get host network."""
|
||||
return utils.get_db_object(
|
||||
session, models.HostNetwork,
|
||||
@ -623,9 +626,9 @@ def _add_host_network(
|
||||
permission.PERMISSION_ADD_HOST_NETWORK
|
||||
)
|
||||
def add_host_network(
|
||||
session, creator, host_id,
|
||||
creator, host_id,
|
||||
exception_when_existing=True,
|
||||
interface=None, **kwargs
|
||||
interface=None, session=None, **kwargs
|
||||
):
|
||||
"""Create a host network."""
|
||||
return _add_host_network(
|
||||
@ -639,9 +642,9 @@ def add_host_network(
|
||||
permission.PERMISSION_ADD_HOST_NETWORK
|
||||
)
|
||||
def add_host_networks(
|
||||
session, creator,
|
||||
creator,
|
||||
exception_when_existing=False,
|
||||
data=[]
|
||||
data=[], session=None
|
||||
):
|
||||
"""Create host networks."""
|
||||
hosts = []
|
||||
@ -672,9 +675,6 @@ def add_host_networks(
|
||||
}
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_HOST_NETWORK
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_NETWORK_FIELDS)
|
||||
def _update_host_network(
|
||||
session, updater, host_network, **kwargs
|
||||
@ -720,8 +720,11 @@ def _update_host_network(
|
||||
ip=utils.check_ip
|
||||
)
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_HOST_NETWORK
|
||||
)
|
||||
def update_host_network(
|
||||
session, updater, host_id, host_network_id, **kwargs
|
||||
updater, host_id, host_network_id, session=None, **kwargs
|
||||
):
|
||||
"""Update a host network."""
|
||||
host_network = utils.get_db_object(
|
||||
@ -747,7 +750,10 @@ def update_host_network(
|
||||
ip=utils.check_ip
|
||||
)
|
||||
@database.run_in_session()
|
||||
def update_hostnetwork(session, updater, host_network_id, **kwargs):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_HOST_NETWORK
|
||||
)
|
||||
def update_hostnetwork(updater, host_network_id, session=None, **kwargs):
|
||||
"""Update a host network."""
|
||||
host_network = utils.get_db_object(
|
||||
session, models.HostNetwork, id=host_network_id
|
||||
@ -763,7 +769,10 @@ def update_hostnetwork(session, updater, host_network_id, **kwargs):
|
||||
permission.PERMISSION_DEL_HOST_NETWORK
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_NETWORK_FIELDS)
|
||||
def del_host_network(session, deleter, host_id, host_network_id, **kwargs):
|
||||
def del_host_network(
|
||||
deleter, host_id, host_network_id,
|
||||
session=None, **kwargs
|
||||
):
|
||||
"""Delete a host network."""
|
||||
host_network = utils.get_db_object(
|
||||
session, models.HostNetwork,
|
||||
@ -785,7 +794,7 @@ def del_host_network(session, deleter, host_id, host_network_id, **kwargs):
|
||||
permission.PERMISSION_DEL_HOST_NETWORK
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_NETWORK_FIELDS)
|
||||
def del_hostnetwork(session, deleter, host_network_id, **kwargs):
|
||||
def del_hostnetwork(deleter, host_network_id, session=None, **kwargs):
|
||||
"""Delete a host network."""
|
||||
host_network = utils.get_db_object(
|
||||
session, models.HostNetwork, id=host_network_id
|
||||
@ -800,7 +809,7 @@ def del_hostnetwork(session, deleter, host_network_id, **kwargs):
|
||||
permission.PERMISSION_GET_HOST_STATE
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_STATE_FIELDS)
|
||||
def get_host_state(session, getter, host_id, **kwargs):
|
||||
def get_host_state(getter, host_id, session=None, **kwargs):
|
||||
"""Get host state info."""
|
||||
return utils.get_db_object(
|
||||
session, models.Host, id=host_id
|
||||
@ -816,7 +825,7 @@ def get_host_state(session, getter, host_id, **kwargs):
|
||||
permission.PERMISSION_UPDATE_HOST_STATE
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_STATE_FIELDS)
|
||||
def update_host_state(session, updater, host_id, **kwargs):
|
||||
def update_host_state(updater, host_id, session=None, **kwargs):
|
||||
"""Update a host state."""
|
||||
host = utils.get_db_object(
|
||||
session, models.Host, id=host_id
|
||||
@ -828,7 +837,7 @@ def update_host_state(session, updater, host_id, **kwargs):
|
||||
@utils.supported_filters([])
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_LOG_FIELDS)
|
||||
def get_host_log_histories(session, getter, host_id, **kwargs):
|
||||
def get_host_log_histories(getter, host_id, session=None, **kwargs):
|
||||
"""Get host log history."""
|
||||
return utils.list_db_objects(
|
||||
session, models.HostLogHistory, id=host_id
|
||||
@ -838,7 +847,7 @@ def get_host_log_histories(session, getter, host_id, **kwargs):
|
||||
@utils.supported_filters([])
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_LOG_FIELDS)
|
||||
def get_host_log_history(session, getter, host_id, filename, **kwargs):
|
||||
def get_host_log_history(getter, host_id, filename, session=None, **kwargs):
|
||||
"""Get host log history."""
|
||||
return utils.get_db_object(
|
||||
session, models.HostLogHistory, id=host_id, filename=filename
|
||||
@ -851,7 +860,10 @@ def get_host_log_history(session, getter, host_id, filename, **kwargs):
|
||||
)
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_LOG_FIELDS)
|
||||
def update_host_log_history(session, updater, host_id, filename, **kwargs):
|
||||
def update_host_log_history(
|
||||
updater, host_id, filename,
|
||||
session=None, **kwargs
|
||||
):
|
||||
"""Update a host log history."""
|
||||
host_log_history = utils.get_db_object(
|
||||
session, models.HostLogHistory, id=host_id, filename=filename
|
||||
@ -867,8 +879,8 @@ def update_host_log_history(session, updater, host_id, filename, **kwargs):
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_LOG_FIELDS)
|
||||
def add_host_log_history(
|
||||
session, creator, host_id, exception_when_existing=False,
|
||||
filename=None, **kwargs
|
||||
creator, host_id, exception_when_existing=False,
|
||||
filename=None, session=None, **kwargs
|
||||
):
|
||||
"""add a host log history."""
|
||||
return utils.add_db_object(
|
||||
@ -887,7 +899,7 @@ def add_host_log_history(
|
||||
host=RESP_CONFIG_FIELDS
|
||||
)
|
||||
def poweron_host(
|
||||
session, deployer, host_id, poweron={}, **kwargs
|
||||
deployer, host_id, poweron={}, session=None, **kwargs
|
||||
):
|
||||
"""power on host."""
|
||||
from compass.tasks import client as celery_client
|
||||
@ -915,7 +927,7 @@ def poweron_host(
|
||||
host=RESP_CONFIG_FIELDS
|
||||
)
|
||||
def poweroff_host(
|
||||
session, deployer, host_id, poweroff={}, **kwargs
|
||||
deployer, host_id, poweroff={}, session=None, **kwargs
|
||||
):
|
||||
"""power off host."""
|
||||
from compass.tasks import client as celery_client
|
||||
@ -943,7 +955,7 @@ def poweroff_host(
|
||||
host=RESP_CONFIG_FIELDS
|
||||
)
|
||||
def reset_host(
|
||||
session, deployer, host_id, reset={}, **kwargs
|
||||
deployer, host_id, reset={}, session=None, **kwargs
|
||||
):
|
||||
"""reset host."""
|
||||
from compass.tasks import client as celery_client
|
||||
|
@ -50,8 +50,8 @@ RESP_DEPLOY_FIELDS = [
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def get_machine(
|
||||
session, getter, machine_id,
|
||||
exception_when_missing=True,
|
||||
getter, machine_id,
|
||||
exception_when_missing=True, session=None,
|
||||
**kwargs
|
||||
):
|
||||
"""get field dict of a machine."""
|
||||
@ -73,16 +73,13 @@ def get_machine(
|
||||
location=utils.general_filter_callback
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def list_machines(session, lister, **filters):
|
||||
def list_machines(lister, session=None, **filters):
|
||||
"""List machines."""
|
||||
return utils.list_db_objects(
|
||||
session, models.Machine, **filters
|
||||
)
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_MACHINE
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def _update_machine(session, updater, machine_id, **kwargs):
|
||||
"""Update a machine."""
|
||||
@ -96,7 +93,10 @@ def _update_machine(session, updater, machine_id, **kwargs):
|
||||
)
|
||||
@utils.input_validates(ipmi_credentials=utils.check_ipmi_credentials)
|
||||
@database.run_in_session()
|
||||
def update_machine(session, updater, machine_id, **kwargs):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_MACHINE
|
||||
)
|
||||
def update_machine(updater, machine_id, session=None, **kwargs):
|
||||
return _update_machine(
|
||||
session, updater, machine_id, **kwargs
|
||||
)
|
||||
@ -113,7 +113,7 @@ def update_machine(session, updater, machine_id, **kwargs):
|
||||
)
|
||||
@database.run_in_session()
|
||||
@utils.output_validates(ipmi_credentials=utils.check_ipmi_credentials)
|
||||
def patch_machine(session, updater, machine_id, **kwargs):
|
||||
def patch_machine(updater, machine_id, session=None, **kwargs):
|
||||
return _update_machine(
|
||||
session, updater, machine_id, **kwargs
|
||||
)
|
||||
@ -125,7 +125,7 @@ def patch_machine(session, updater, machine_id, **kwargs):
|
||||
permission.PERMISSION_DEL_MACHINE
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def del_machine(session, deleter, machine_id, **kwargs):
|
||||
def del_machine(deleter, machine_id, session=None, **kwargs):
|
||||
"""Delete a machine."""
|
||||
machine = utils.get_db_object(session, models.Machine, id=machine_id)
|
||||
if machine.host:
|
||||
@ -148,7 +148,7 @@ def del_machine(session, deleter, machine_id, **kwargs):
|
||||
machine=RESP_FIELDS
|
||||
)
|
||||
def poweron_machine(
|
||||
session, deployer, machine_id, poweron={}, **kwargs
|
||||
deployer, machine_id, poweron={}, session=None, **kwargs
|
||||
):
|
||||
"""power on machine."""
|
||||
from compass.tasks import client as celery_client
|
||||
@ -175,7 +175,7 @@ def poweron_machine(
|
||||
machine=RESP_FIELDS
|
||||
)
|
||||
def poweroff_machine(
|
||||
session, deployer, machine_id, poweroff={}, **kwargs
|
||||
deployer, machine_id, poweroff={}, session=None, **kwargs
|
||||
):
|
||||
"""power off machine."""
|
||||
from compass.tasks import client as celery_client
|
||||
@ -202,7 +202,7 @@ def poweroff_machine(
|
||||
machine=RESP_FIELDS
|
||||
)
|
||||
def reset_machine(
|
||||
session, deployer, machine_id, reset={}, **kwargs
|
||||
deployer, machine_id, reset={}, session=None, **kwargs
|
||||
):
|
||||
"""reset machine."""
|
||||
from compass.tasks import client as celery_client
|
||||
|
@ -133,7 +133,7 @@ def get_package_metadata_internal(session, adapter_id):
|
||||
permission.PERMISSION_LIST_METADATAS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_METADATA_FIELDS)
|
||||
def get_package_metadata(session, getter, adapter_id, **kwargs):
|
||||
def get_package_metadata(getter, adapter_id, session=None, **kwargs):
|
||||
return {
|
||||
'package_config': get_package_metadata_internal(session, adapter_id)
|
||||
}
|
||||
@ -158,7 +158,7 @@ def get_os_metadata_internal(session, os_id):
|
||||
permission.PERMISSION_LIST_METADATAS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_METADATA_FIELDS)
|
||||
def get_os_metadata(session, getter, os_id, **kwargs):
|
||||
def get_os_metadata(getter, os_id, session=None, **kwargs):
|
||||
"""get os metadatas."""
|
||||
return {'os_config': get_os_metadata_internal(session, os_id)}
|
||||
|
||||
@ -169,7 +169,7 @@ def get_os_metadata(session, getter, os_id, **kwargs):
|
||||
permission.PERMISSION_LIST_METADATAS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_METADATA_FIELDS)
|
||||
def get_package_os_metadata(session, getter, adapter_id, os_id, **kwargs):
|
||||
def get_package_os_metadata(getter, adapter_id, os_id, session=None, **kwargs):
|
||||
from compass.db.api import adapter_holder as adapter_api
|
||||
adapter = adapter_api.get_adapter_internal(session, adapter_id)
|
||||
os_ids = [os['os_id'] for os in adapter['supported_oses']]
|
||||
|
@ -51,7 +51,7 @@ def _check_subnet(subnet):
|
||||
permission.PERMISSION_LIST_SUBNETS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def list_subnets(session, lister, **filters):
|
||||
def list_subnets(lister, session=None, **filters):
|
||||
"""List subnets."""
|
||||
return utils.list_db_objects(
|
||||
session, models.Subnet, **filters
|
||||
@ -65,8 +65,8 @@ def list_subnets(session, lister, **filters):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def get_subnet(
|
||||
session, getter, subnet_id,
|
||||
exception_when_missing=True, **kwargs
|
||||
getter, subnet_id,
|
||||
exception_when_missing=True, session=None, **kwargs
|
||||
):
|
||||
"""Get subnet info."""
|
||||
return utils.get_db_object(
|
||||
@ -86,8 +86,8 @@ def get_subnet(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def add_subnet(
|
||||
session, creator, exception_when_existing=True,
|
||||
subnet=None, **kwargs
|
||||
creator, exception_when_existing=True,
|
||||
subnet=None, session=None, **kwargs
|
||||
):
|
||||
"""Create a subnet."""
|
||||
return utils.add_db_object(
|
||||
@ -106,7 +106,7 @@ def add_subnet(
|
||||
permission.PERMISSION_ADD_SUBNET
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def update_subnet(session, updater, subnet_id, **kwargs):
|
||||
def update_subnet(updater, subnet_id, session=None, **kwargs):
|
||||
"""Update a subnet."""
|
||||
subnet = utils.get_db_object(
|
||||
session, models.Subnet, id=subnet_id
|
||||
@ -120,7 +120,7 @@ def update_subnet(session, updater, subnet_id, **kwargs):
|
||||
permission.PERMISSION_DEL_SUBNET
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def del_subnet(session, deleter, subnet_id, **kwargs):
|
||||
def del_subnet(deleter, subnet_id, session=None, **kwargs):
|
||||
"""Delete a subnet."""
|
||||
subnet = utils.get_db_object(
|
||||
session, models.Subnet, id=subnet_id
|
||||
|
@ -270,7 +270,7 @@ def list_permissions_internal(session, **filters):
|
||||
@database.run_in_session()
|
||||
@user_api.check_user_permission_in_session(PERMISSION_LIST_PERMISSIONS)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def list_permissions(session, lister, **filters):
|
||||
def list_permissions(lister, session=None, **filters):
|
||||
"""list permissions."""
|
||||
return utils.list_db_objects(
|
||||
session, models.Permission, **filters
|
||||
@ -282,8 +282,8 @@ def list_permissions(session, lister, **filters):
|
||||
@user_api.check_user_permission_in_session(PERMISSION_LIST_PERMISSIONS)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def get_permission(
|
||||
session, getter, permission_id,
|
||||
exception_when_missing=True, **kwargs
|
||||
getter, permission_id,
|
||||
exception_when_missing=True, session=None, **kwargs
|
||||
):
|
||||
"""get permissions."""
|
||||
return utils.get_db_object(
|
||||
|
@ -140,8 +140,8 @@ def get_switch_internal(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def get_switch(
|
||||
session, getter, switch_id,
|
||||
exception_when_missing=True, **kwargs
|
||||
getter, switch_id,
|
||||
exception_when_missing=True, session=None, **kwargs
|
||||
):
|
||||
"""get field dict of a switch."""
|
||||
return utils.get_db_object(
|
||||
@ -156,7 +156,7 @@ def get_switch(
|
||||
permission.PERMISSION_LIST_SWITCHES
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def list_switches(session, lister, **filters):
|
||||
def list_switches(lister, session=None, **filters):
|
||||
"""List switches."""
|
||||
switches = utils.list_db_objects(
|
||||
session, models.Switch, **filters
|
||||
@ -176,7 +176,7 @@ def list_switches(session, lister, **filters):
|
||||
permission.PERMISSION_DEL_SWITCH
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def del_switch(session, deleter, switch_id, **kwargs):
|
||||
def del_switch(deleter, switch_id, session=None, **kwargs):
|
||||
"""Delete a switch."""
|
||||
switch = utils.get_db_object(session, models.Switch, id=switch_id)
|
||||
default_switch_ip_int = long(netaddr.IPAddress(setting.DEFAULT_SWITCH_IP))
|
||||
@ -212,8 +212,8 @@ def del_switch(session, deleter, switch_id, **kwargs):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def add_switch(
|
||||
session, creator, exception_when_existing=True,
|
||||
ip=None, **kwargs
|
||||
creator, exception_when_existing=True,
|
||||
ip=None, session=None, **kwargs
|
||||
):
|
||||
"""Create a switch."""
|
||||
ip_int = long(netaddr.IPAddress(ip))
|
||||
@ -230,9 +230,6 @@ def update_switch_internal(session, switch, **kwargs):
|
||||
)
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_SWITCH
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def _update_switch(session, updater, switch_id, **kwargs):
|
||||
"""Update a switch."""
|
||||
@ -254,7 +251,10 @@ def _update_switch(session, updater, switch_id, **kwargs):
|
||||
put_filters=_check_filters
|
||||
)
|
||||
@database.run_in_session()
|
||||
def update_switch(session, updater, switch_id, **kwargs):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_ADD_SWITCH
|
||||
)
|
||||
def update_switch(updater, switch_id, session=None, **kwargs):
|
||||
"""Update fields of a switch."""
|
||||
return _update_switch(session, updater, switch_id, **kwargs)
|
||||
|
||||
@ -274,7 +274,7 @@ def update_switch(session, updater, switch_id, **kwargs):
|
||||
@utils.output_validates(
|
||||
credentials=utils.check_switch_credentials
|
||||
)
|
||||
def patch_switch(session, updater, switch_id, **kwargs):
|
||||
def patch_switch(updater, switch_id, session=None, **kwargs):
|
||||
"""Patch fields of a switch."""
|
||||
return _update_switch(session, updater, switch_id, **kwargs)
|
||||
|
||||
@ -285,7 +285,7 @@ def patch_switch(session, updater, switch_id, **kwargs):
|
||||
permission.PERMISSION_LIST_SWITCH_FILTERS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FILTERS_FIELDS)
|
||||
def list_switch_filters(session, lister, **filters):
|
||||
def list_switch_filters(lister, session=None, **filters):
|
||||
"""List switch filters."""
|
||||
return utils.list_db_objects(
|
||||
session, models.Switch, **filters
|
||||
@ -299,7 +299,7 @@ def list_switch_filters(session, lister, **filters):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FILTERS_FIELDS)
|
||||
def get_switch_filters(
|
||||
session, getter, switch_id, **kwargs
|
||||
getter, switch_id, session=None, **kwargs
|
||||
):
|
||||
"""get switch filter."""
|
||||
return utils.get_db_object(
|
||||
@ -320,7 +320,7 @@ def get_switch_filters(
|
||||
permission.PERMISSION_UPDATE_SWITCH_FILTERS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FILTERS_FIELDS)
|
||||
def update_switch_filters(session, updater, switch_id, **kwargs):
|
||||
def update_switch_filters(updater, switch_id, session=None, **kwargs):
|
||||
"""Update a switch filter."""
|
||||
switch = utils.get_db_object(session, models.Switch, id=switch_id)
|
||||
return utils.update_db_object(session, switch, **kwargs)
|
||||
@ -339,7 +339,7 @@ def update_switch_filters(session, updater, switch_id, **kwargs):
|
||||
permission.PERMISSION_UPDATE_SWITCH_FILTERS
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_FILTERS_FIELDS)
|
||||
def patch_switch_filter(session, updater, switch_id, **kwargs):
|
||||
def patch_switch_filter(updater, switch_id, session=None, **kwargs):
|
||||
"""Patch a switch filter."""
|
||||
switch = utils.get_db_object(session, models.Switch, id=switch_id)
|
||||
return utils.update_db_object(session, switch, **kwargs)
|
||||
@ -399,9 +399,6 @@ def _filter_vlans(vlan_filter, obj):
|
||||
return True
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_LIST_SWITCH_MACHINES
|
||||
)
|
||||
@utils.output_filters(
|
||||
port=_filter_port, vlans=_filter_vlans,
|
||||
tag=utils.general_filter_callback,
|
||||
@ -415,9 +412,6 @@ def _filter_switch_machines(session, user, switch_machines):
|
||||
]
|
||||
|
||||
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_LIST_SWITCH_MACHINES
|
||||
)
|
||||
@utils.output_filters(
|
||||
missing_ok=True,
|
||||
port=_filter_port, vlans=_filter_vlans,
|
||||
@ -454,7 +448,10 @@ def _filter_switch_machines_hosts(session, user, switch_machines):
|
||||
optional_support_keys=SUPPORTED_MACHINES_FIELDS
|
||||
)
|
||||
@database.run_in_session()
|
||||
def list_switch_machines(session, getter, switch_id, **filters):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_LIST_SWITCH_MACHINES
|
||||
)
|
||||
def list_switch_machines(getter, switch_id, session=None, **filters):
|
||||
"""Get switch machines."""
|
||||
switch_machines = get_switch_machines_internal(
|
||||
session, switch_id=switch_id, **filters
|
||||
@ -469,7 +466,10 @@ def list_switch_machines(session, getter, switch_id, **filters):
|
||||
optional_support_keys=SUPPORTED_SWITCH_MACHINES_FIELDS
|
||||
)
|
||||
@database.run_in_session()
|
||||
def list_switchmachines(session, lister, **filters):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_LIST_SWITCH_MACHINES
|
||||
)
|
||||
def list_switchmachines(lister, session=None, **filters):
|
||||
"""List switch machines."""
|
||||
switch_machines = get_switch_machines_internal(
|
||||
session, **filters
|
||||
@ -483,7 +483,10 @@ def list_switchmachines(session, lister, **filters):
|
||||
optional_support_keys=SUPPORTED_MACHINES_HOSTS_FIELDS
|
||||
)
|
||||
@database.run_in_session()
|
||||
def list_switch_machines_hosts(session, getter, switch_id, **filters):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_LIST_SWITCH_MACHINES
|
||||
)
|
||||
def list_switch_machines_hosts(getter, switch_id, session=None, **filters):
|
||||
"""Get switch machines hosts."""
|
||||
switch_machines = get_switch_machines_internal(
|
||||
session, switch_id=switch_id, **filters
|
||||
@ -500,7 +503,10 @@ def list_switch_machines_hosts(session, getter, switch_id, **filters):
|
||||
optional_support_keys=SUPPORTED_SWITCH_MACHINES_HOSTS_FIELDS
|
||||
)
|
||||
@database.run_in_session()
|
||||
def list_switchmachines_hosts(session, lister, **filters):
|
||||
@user_api.check_user_permission_in_session(
|
||||
permission.PERMISSION_LIST_SWITCH_MACHINES
|
||||
)
|
||||
def list_switchmachines_hosts(lister, session=None, **filters):
|
||||
"""List switch machines hosts."""
|
||||
switch_machines = get_switch_machines_internal(
|
||||
session, **filters
|
||||
@ -528,9 +534,9 @@ def list_switchmachines_hosts(session, lister, **filters):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_MACHINES_FIELDS)
|
||||
def add_switch_machine(
|
||||
session, creator, switch_id,
|
||||
creator, switch_id,
|
||||
exception_when_existing=True,
|
||||
mac=None, **kwargs
|
||||
mac=None, session=None, **kwargs
|
||||
):
|
||||
"""Add switch machine."""
|
||||
switch = utils.get_db_object(
|
||||
@ -560,7 +566,7 @@ def add_switch_machine(
|
||||
permission.PERMISSION_UPDATE_SWITCH_MACHINES
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_ACTION_FIELDS)
|
||||
def poll_switch_machines(session, poller, switch_id, **kwargs):
|
||||
def poll_switch_machines(poller, switch_id, session=None, **kwargs):
|
||||
"""poll switch machines."""
|
||||
from compass.tasks import client as celery_client
|
||||
switch = utils.get_db_object(session, models.Switch, id=switch_id)
|
||||
@ -582,8 +588,8 @@ def poll_switch_machines(session, poller, switch_id, **kwargs):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_MACHINES_FIELDS)
|
||||
def get_switch_machine(
|
||||
session, getter, switch_id, machine_id,
|
||||
exception_when_missing=True, **kwargs
|
||||
getter, switch_id, machine_id,
|
||||
exception_when_missing=True, session=None, **kwargs
|
||||
):
|
||||
"""get field dict of a switch machine."""
|
||||
return utils.get_db_object(
|
||||
@ -600,8 +606,8 @@ def get_switch_machine(
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_MACHINES_FIELDS)
|
||||
def get_switchmachine(
|
||||
session, getter, switch_machine_id,
|
||||
exception_when_missing=True,
|
||||
getter, switch_machine_id,
|
||||
exception_when_missing=True, session=None,
|
||||
**kwargs
|
||||
):
|
||||
"""get field dict of a switch machine."""
|
||||
@ -641,7 +647,10 @@ def update_switch_machine_internal(
|
||||
permission.PERMISSION_ADD_SWITCH_MACHINE
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_MACHINES_FIELDS)
|
||||
def update_switch_machine(session, updater, switch_id, machine_id, **kwargs):
|
||||
def update_switch_machine(
|
||||
updater, switch_id, machine_id,
|
||||
session=None, **kwargs
|
||||
):
|
||||
"""Update switch machine."""
|
||||
switch_machine = utils.get_db_object(
|
||||
session, models.SwitchMachine,
|
||||
@ -663,7 +672,7 @@ def update_switch_machine(session, updater, switch_id, machine_id, **kwargs):
|
||||
permission.PERMISSION_ADD_SWITCH_MACHINE
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_MACHINES_FIELDS)
|
||||
def update_switchmachine(session, updater, switch_machine_id, **kwargs):
|
||||
def update_switchmachine(updater, switch_machine_id, session=None, **kwargs):
|
||||
"""Update switch machine."""
|
||||
switch_machine = utils.get_db_object(
|
||||
session, models.SwitchMachine,
|
||||
@ -691,7 +700,10 @@ def update_switchmachine(session, updater, switch_machine_id, **kwargs):
|
||||
permission.PERMISSION_ADD_SWITCH_MACHINE
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_MACHINES_FIELDS)
|
||||
def patch_switch_machine(session, updater, switch_id, machine_id, **kwargs):
|
||||
def patch_switch_machine(
|
||||
updater, switch_id, machine_id,
|
||||
session=None, **kwargs
|
||||
):
|
||||
"""Patch switch machine."""
|
||||
switch_machine = utils.get_db_object(
|
||||
session, models.SwitchMachine,
|
||||
@ -719,7 +731,7 @@ def patch_switch_machine(session, updater, switch_id, machine_id, **kwargs):
|
||||
permission.PERMISSION_ADD_SWITCH_MACHINE
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_MACHINES_FIELDS)
|
||||
def patch_switchmachine(session, updater, switch_machine_id, **kwargs):
|
||||
def patch_switchmachine(updater, switch_machine_id, session=None, **kwargs):
|
||||
"""Patch switch machine."""
|
||||
switch_machine = utils.get_db_object(
|
||||
session, models.SwitchMachine,
|
||||
@ -737,7 +749,7 @@ def patch_switchmachine(session, updater, switch_machine_id, **kwargs):
|
||||
permission.PERMISSION_DEL_SWITCH_MACHINE
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_MACHINES_FIELDS)
|
||||
def del_switch_machine(session, deleter, switch_id, machine_id, **kwargs):
|
||||
def del_switch_machine(deleter, switch_id, machine_id, session=None, **kwargs):
|
||||
"""Delete switch machine by switch id and machine id."""
|
||||
switch_machine = utils.get_db_object(
|
||||
session, models.SwitchMachine,
|
||||
@ -765,7 +777,7 @@ def del_switch_machine(session, deleter, switch_id, machine_id, **kwargs):
|
||||
permission.PERMISSION_DEL_SWITCH_MACHINE
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_MACHINES_FIELDS)
|
||||
def del_switchmachine(session, deleter, switch_machine_id, **kwargs):
|
||||
def del_switchmachine(deleter, switch_machine_id, session=None, **kwargs):
|
||||
"""Delete switch machine by switch_machine_id."""
|
||||
switch_machine = utils.get_db_object(
|
||||
session, models.SwitchMachine,
|
||||
@ -835,9 +847,9 @@ def _set_machines(session, switch, machines):
|
||||
)
|
||||
@utils.wrap_to_dict(RESP_MACHINES_FIELDS)
|
||||
def update_switch_machines(
|
||||
session, updater, switch_id,
|
||||
updater, switch_id,
|
||||
add_machines=[], remove_machines=[],
|
||||
set_machines=None, **kwargs
|
||||
set_machines=None, session=None, **kwargs
|
||||
):
|
||||
"""update switch machines."""
|
||||
switch = utils.get_db_object(
|
||||
|
@ -101,9 +101,13 @@ def _check_user_permission(session, user, permission):
|
||||
def check_user_permission_in_session(permission):
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(session, user, *args, **kwargs):
|
||||
def wrapper(user, *args, **kwargs):
|
||||
if 'session' in kwargs.keys():
|
||||
session = kwargs['session']
|
||||
else:
|
||||
session = args[-1]
|
||||
_check_user_permission(session, user, permission)
|
||||
return func(session, user, *args, **kwargs)
|
||||
return func(user, *args, **kwargs)
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
@ -223,7 +227,7 @@ class UserWrapper(UserMixin):
|
||||
|
||||
|
||||
@database.run_in_session()
|
||||
def get_user_object(session, email, **kwargs):
|
||||
def get_user_object(email, session=None, **kwargs):
|
||||
user = utils.get_db_object(
|
||||
session, models.User, False, email=email
|
||||
)
|
||||
@ -237,7 +241,7 @@ def get_user_object(session, email, **kwargs):
|
||||
|
||||
|
||||
@database.run_in_session()
|
||||
def get_user_object_from_token(session, token):
|
||||
def get_user_object_from_token(token, session=None):
|
||||
expire_timestamp = {
|
||||
'ge': datetime.datetime.now()
|
||||
}
|
||||
@ -262,7 +266,7 @@ def get_user_object_from_token(session, token):
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_TOKEN_FIELDS)
|
||||
def record_user_token(
|
||||
session, user, token, expire_timestamp
|
||||
user, token, expire_timestamp, session=None
|
||||
):
|
||||
"""record user token in database."""
|
||||
user_token = utils.get_db_object(
|
||||
@ -285,7 +289,7 @@ def record_user_token(
|
||||
@utils.supported_filters()
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_TOKEN_FIELDS)
|
||||
def clean_user_token(session, user, token):
|
||||
def clean_user_token(user, token, session=None):
|
||||
"""clean user token in database."""
|
||||
return utils.del_db_objects(
|
||||
session, models.UserToken,
|
||||
@ -298,8 +302,8 @@ def clean_user_token(session, user, token):
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def get_user(
|
||||
session, getter, user_id,
|
||||
exception_when_missing=True, **kwargs
|
||||
getter, user_id,
|
||||
exception_when_missing=True, session=None, **kwargs
|
||||
):
|
||||
"""get field dict of a user."""
|
||||
return utils.get_db_object(
|
||||
@ -311,8 +315,8 @@ def get_user(
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def get_current_user(
|
||||
session, getter,
|
||||
exception_when_missing=True, **kwargs
|
||||
getter,
|
||||
exception_when_missing=True, session=None, **kwargs
|
||||
):
|
||||
"""get field dict of a user."""
|
||||
return utils.get_db_object(
|
||||
@ -326,7 +330,7 @@ def get_current_user(
|
||||
@check_user_admin()
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def list_users(session, lister, **filters):
|
||||
def list_users(lister, session=None, **filters):
|
||||
"""List fields of all users by some fields."""
|
||||
return utils.list_db_objects(
|
||||
session, models.User, **filters
|
||||
@ -343,9 +347,9 @@ def list_users(session, lister, **filters):
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def add_user(
|
||||
session, creator,
|
||||
creator,
|
||||
exception_when_existing=True,
|
||||
**kwargs
|
||||
session=None, **kwargs
|
||||
):
|
||||
"""Create a user and return created user object."""
|
||||
return add_user_internal(
|
||||
@ -357,7 +361,7 @@ def add_user(
|
||||
@check_user_admin()
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def del_user(session, deleter, user_id, **kwargs):
|
||||
def del_user(deleter, user_id, session=None, **kwargs):
|
||||
"""delete a user and return the deleted user object."""
|
||||
user = utils.get_db_object(session, models.User, id=user_id)
|
||||
return utils.del_db_object(session, user)
|
||||
@ -370,7 +374,7 @@ def del_user(session, deleter, user_id, **kwargs):
|
||||
@utils.input_validates(email=_check_email)
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def update_user(session, updater, user_id, **kwargs):
|
||||
def update_user(updater, user_id, session=None, **kwargs):
|
||||
"""Update a user and return the updated user object."""
|
||||
user = utils.get_db_object(
|
||||
session, models.User, id=user_id
|
||||
@ -395,7 +399,7 @@ def update_user(session, updater, user_id, **kwargs):
|
||||
@check_user_admin_or_owner()
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(PERMISSION_RESP_FIELDS)
|
||||
def get_permissions(session, lister, user_id, **kwargs):
|
||||
def get_permissions(lister, user_id, session=None, **kwargs):
|
||||
"""List permissions of a user."""
|
||||
return utils.list_db_objects(
|
||||
session, models.UserPermission, user_id=user_id, **kwargs
|
||||
@ -407,8 +411,8 @@ def get_permissions(session, lister, user_id, **kwargs):
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(PERMISSION_RESP_FIELDS)
|
||||
def get_permission(
|
||||
session, getter, user_id, permission_id,
|
||||
exception_when_missing=True, **kwargs
|
||||
getter, user_id, permission_id,
|
||||
exception_when_missing=True, session=None, **kwargs
|
||||
):
|
||||
"""Get a specific user permission."""
|
||||
return utils.get_db_object(
|
||||
@ -423,7 +427,7 @@ def get_permission(
|
||||
@check_user_admin_or_owner()
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(PERMISSION_RESP_FIELDS)
|
||||
def del_permission(session, deleter, user_id, permission_id, **kwargs):
|
||||
def del_permission(deleter, user_id, permission_id, session=None, **kwargs):
|
||||
"""Delete a specific user permission."""
|
||||
user_permission = utils.get_db_object(
|
||||
session, models.UserPermission,
|
||||
@ -441,8 +445,8 @@ def del_permission(session, deleter, user_id, permission_id, **kwargs):
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(PERMISSION_RESP_FIELDS)
|
||||
def add_permission(
|
||||
session, creator, user_id,
|
||||
exception_when_missing=True, permission_id=None
|
||||
creator, user_id,
|
||||
exception_when_missing=True, permission_id=None, session=None
|
||||
):
|
||||
"""Add an user permission."""
|
||||
return utils.add_db_object(
|
||||
@ -467,9 +471,9 @@ def _get_permission_filters(permission_ids):
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(PERMISSION_RESP_FIELDS)
|
||||
def update_permissions(
|
||||
session, updater, user_id,
|
||||
updater, user_id,
|
||||
add_permissions=[], remove_permissions=[],
|
||||
set_permissions=None, **kwargs
|
||||
set_permissions=None, session=None, **kwargs
|
||||
):
|
||||
"""update user permissions."""
|
||||
user = utils.get_db_object(session, models.User, id=user_id)
|
||||
|
@ -28,7 +28,7 @@ RESP_FIELDS = ['user_id', 'logs', 'timestamp']
|
||||
|
||||
|
||||
@database.run_in_session()
|
||||
def log_user_action(session, user_id, action):
|
||||
def log_user_action(user_id, action, session=None):
|
||||
"""Log user action."""
|
||||
utils.add_db_object(
|
||||
session, models.UserLog, True, user_id=user_id, action=action
|
||||
@ -39,7 +39,7 @@ def log_user_action(session, user_id, action):
|
||||
@user_api.check_user_admin_or_owner()
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def list_user_actions(session, lister, user_id, **filters):
|
||||
def list_user_actions(lister, user_id, session=None, **filters):
|
||||
"""list user actions."""
|
||||
return utils.list_db_objects(
|
||||
session, models.UserLog, order_by=['timestamp'],
|
||||
@ -51,7 +51,7 @@ def list_user_actions(session, lister, user_id, **filters):
|
||||
@user_api.check_user_admin()
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def list_actions(session, lister, **filters):
|
||||
def list_actions(lister, session=None, **filters):
|
||||
"""list actions."""
|
||||
return utils.list_db_objects(
|
||||
session, models.UserLog, order_by=['timestamp'], **filters
|
||||
@ -62,7 +62,7 @@ def list_actions(session, lister, **filters):
|
||||
@user_api.check_user_admin_or_owner()
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def del_user_actions(session, deleter, user_id, **filters):
|
||||
def del_user_actions(deleter, user_id, session=None, **filters):
|
||||
"""delete user actions."""
|
||||
return utils.del_db_objects(
|
||||
session, models.UserLog, user_id=user_id, **filters
|
||||
@ -73,7 +73,7 @@ def del_user_actions(session, deleter, user_id, **filters):
|
||||
@user_api.check_user_admin()
|
||||
@database.run_in_session()
|
||||
@utils.wrap_to_dict(RESP_FIELDS)
|
||||
def del_actions(session, deleter, **filters):
|
||||
def del_actions(deleter, session=None, **filters):
|
||||
"""delete actions."""
|
||||
return utils.del_db_objects(
|
||||
session, models.UserLog, **filters
|
||||
|
@ -20,6 +20,7 @@ import logging
|
||||
import netaddr
|
||||
import re
|
||||
|
||||
from inspect import isfunction
|
||||
from sqlalchemy import and_
|
||||
from sqlalchemy import or_
|
||||
|
||||
@ -255,6 +256,17 @@ def _replace_output(data, **output_mapping):
|
||||
return info
|
||||
|
||||
|
||||
def get_wrapped_func(func):
|
||||
"""Get wrapped function instance."""
|
||||
if func.func_closure:
|
||||
for closure in func.func_closure:
|
||||
if isfunction(closure.cell_contents):
|
||||
return get_wrapped_func(closure.cell_contents)
|
||||
return func
|
||||
else:
|
||||
return func
|
||||
|
||||
|
||||
def wrap_to_dict(support_keys=[], **filters):
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
@ -335,14 +347,18 @@ def replace_filters(**filter_mapping):
|
||||
def supported_filters(
|
||||
support_keys=[],
|
||||
optional_support_keys=[],
|
||||
ignore_support_keys=[]
|
||||
ignore_support_keys=[],
|
||||
):
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **filters):
|
||||
wrapped_func = get_wrapped_func(func)
|
||||
argspec = inspect.getargspec(wrapped_func)
|
||||
wrapped_args = argspec.args
|
||||
must_support_keys = set(support_keys)
|
||||
all_support_keys = must_support_keys | set(optional_support_keys)
|
||||
filter_keys = set(filters)
|
||||
filter_keys = set(filters) - set(wrapped_args)
|
||||
wrapped_support_keys = set(filters) | set(wrapped_args)
|
||||
unsupported_keys = (
|
||||
filter_keys - all_support_keys - set(ignore_support_keys)
|
||||
)
|
||||
@ -352,7 +368,7 @@ def supported_filters(
|
||||
list(unsupported_keys)
|
||||
)
|
||||
)
|
||||
missing_keys = must_support_keys - filter_keys
|
||||
missing_keys = must_support_keys - wrapped_support_keys
|
||||
if missing_keys:
|
||||
raise exception.InvalidParameter(
|
||||
'filter keys %s not found' % str(
|
||||
|
@ -326,6 +326,54 @@ class TestAddCluster(ClusterTestCase):
|
||||
result.append(add_cluster['name'])
|
||||
self.assertIn('test_add_cluster', result)
|
||||
|
||||
def test_add_cluster_position_args(self):
|
||||
cluster.add_cluster(
|
||||
self.user_object,
|
||||
True,
|
||||
'test_add_cluster_position',
|
||||
adapter_id=self.adapter_id,
|
||||
os_id=self.os_id,
|
||||
flavor_id=self.flavor_id,
|
||||
)
|
||||
add_clusters = cluster.list_clusters(self.user_object)
|
||||
result = []
|
||||
for add_cluster in add_clusters:
|
||||
result.append(add_cluster['name'])
|
||||
self.assertIn('test_add_cluster_position', result)
|
||||
|
||||
def test_add_cluster_session(self):
|
||||
with database.session() as session:
|
||||
cluster.add_cluster(
|
||||
self.user_object,
|
||||
adapter_id=self.adapter_id,
|
||||
os_id=self.os_id,
|
||||
flavor_id=self.flavor_id,
|
||||
name='test_add_cluster_session',
|
||||
session=session
|
||||
)
|
||||
add_clusters = cluster.list_clusters(self.user_object)
|
||||
result = []
|
||||
for add_cluster in add_clusters:
|
||||
result.append(add_cluster['name'])
|
||||
self.assertIn('test_add_cluster_session', result)
|
||||
|
||||
def test_add_cluster_position_args_session(self):
|
||||
with database.session() as session:
|
||||
cluster.add_cluster(
|
||||
self.user_object,
|
||||
True,
|
||||
'test_add_cluster_position_session',
|
||||
session,
|
||||
adapter_id=self.adapter_id,
|
||||
os_id=self.os_id,
|
||||
flavor_id=self.flavor_id,
|
||||
)
|
||||
add_clusters = cluster.list_clusters(self.user_object)
|
||||
result = []
|
||||
for add_cluster in add_clusters:
|
||||
result.append(add_cluster['name'])
|
||||
self.assertIn('test_add_cluster_position_session', result)
|
||||
|
||||
|
||||
class TestUpdateCluster(ClusterTestCase):
|
||||
"""Test update cluster."""
|
||||
@ -1927,7 +1975,6 @@ class TestAddClusterhostLogHistory(ClusterTestCase):
|
||||
self.user_object,
|
||||
self.clusterhost_id[0],
|
||||
filename='add_log_file'
|
||||
|
||||
)
|
||||
logs = cluster.get_clusterhost_log_histories(
|
||||
self.user_object,
|
||||
@ -1938,6 +1985,57 @@ class TestAddClusterhostLogHistory(ClusterTestCase):
|
||||
result.append(log['filename'])
|
||||
self.assertIn('add_log_file', result)
|
||||
|
||||
def test_add_clusterhost_log_history_position_args(self):
|
||||
cluster.add_clusterhost_log_history(
|
||||
self.user_object,
|
||||
self.clusterhost_id[0],
|
||||
False,
|
||||
'add_log_file_position'
|
||||
)
|
||||
logs = cluster.get_clusterhost_log_histories(
|
||||
self.user_object,
|
||||
self.clusterhost_id[0]
|
||||
)
|
||||
result = []
|
||||
for log in logs:
|
||||
result.append(log['filename'])
|
||||
self.assertIn('add_log_file_position', result)
|
||||
|
||||
def test_add_clusterhost_log_history_session(self):
|
||||
with database.session() as session:
|
||||
cluster.add_clusterhost_log_history(
|
||||
self.user_object,
|
||||
self.clusterhost_id[0],
|
||||
filename='add_log_file_session',
|
||||
session=session
|
||||
)
|
||||
logs = cluster.get_clusterhost_log_histories(
|
||||
self.user_object,
|
||||
self.clusterhost_id[0]
|
||||
)
|
||||
result = []
|
||||
for log in logs:
|
||||
result.append(log['filename'])
|
||||
self.assertIn('add_log_file_session', result)
|
||||
|
||||
def test_add_clusterhost_log_history_position_args_session(self):
|
||||
with database.session() as session:
|
||||
cluster.add_clusterhost_log_history(
|
||||
self.user_object,
|
||||
self.clusterhost_id[0],
|
||||
False,
|
||||
'add_log_file_position_session',
|
||||
session
|
||||
)
|
||||
logs = cluster.get_clusterhost_log_histories(
|
||||
self.user_object,
|
||||
self.clusterhost_id[0]
|
||||
)
|
||||
result = []
|
||||
for log in logs:
|
||||
result.append(log['filename'])
|
||||
self.assertIn('add_log_file_position_session', result)
|
||||
|
||||
|
||||
class TestAddClusterHostLogHistory(ClusterTestCase):
|
||||
"""Test add cluster host log history."""
|
||||
@ -1965,6 +2063,63 @@ class TestAddClusterHostLogHistory(ClusterTestCase):
|
||||
result.append(log['filename'])
|
||||
self.assertIn('add_log_file', result)
|
||||
|
||||
def test_add_cluster_host_log_history_position(self):
|
||||
cluster.add_cluster_host_log_history(
|
||||
self.user_object,
|
||||
self.cluster_id,
|
||||
self.host_id[0],
|
||||
False,
|
||||
'add_log_file_position'
|
||||
)
|
||||
logs = cluster.get_cluster_host_log_histories(
|
||||
self.user_object,
|
||||
self.cluster_id,
|
||||
self.host_id[0]
|
||||
)
|
||||
result = []
|
||||
for log in logs:
|
||||
result.append(log['filename'])
|
||||
self.assertIn('add_log_file_position', result)
|
||||
|
||||
def test_add_cluster_host_log_history_session(self):
|
||||
with database.session() as session:
|
||||
cluster.add_cluster_host_log_history(
|
||||
self.user_object,
|
||||
self.cluster_id,
|
||||
self.host_id[0],
|
||||
filename='add_log_file_session',
|
||||
session=session
|
||||
)
|
||||
logs = cluster.get_cluster_host_log_histories(
|
||||
self.user_object,
|
||||
self.cluster_id,
|
||||
self.host_id[0]
|
||||
)
|
||||
result = []
|
||||
for log in logs:
|
||||
result.append(log['filename'])
|
||||
self.assertIn('add_log_file_session', result)
|
||||
|
||||
def test_add_cluster_host_log_history_position_session(self):
|
||||
with database.session() as session:
|
||||
cluster.add_cluster_host_log_history(
|
||||
self.user_object,
|
||||
self.cluster_id,
|
||||
self.host_id[0],
|
||||
False,
|
||||
'add_log_file_position_session',
|
||||
session
|
||||
)
|
||||
logs = cluster.get_cluster_host_log_histories(
|
||||
self.user_object,
|
||||
self.cluster_id,
|
||||
self.host_id[0]
|
||||
)
|
||||
result = []
|
||||
for log in logs:
|
||||
result.append(log['filename'])
|
||||
self.assertIn('add_log_file_position_session', result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
flags.init()
|
||||
|
@ -835,6 +835,66 @@ class TestAddHostNetwork(HostTestCase):
|
||||
result.append(item['ip'])
|
||||
self.assertIn('10.145.88.20', result)
|
||||
|
||||
def test_add_host_network_position(self):
|
||||
host.add_host_network(
|
||||
self.user_object,
|
||||
self.host_ids[0],
|
||||
True,
|
||||
'eth1',
|
||||
ip='10.145.88.30',
|
||||
subnet_id=self.subnet_ids[0],
|
||||
is_mgmt=True
|
||||
)
|
||||
host_network = host.list_host_networks(
|
||||
self.user_object,
|
||||
self.host_ids[0]
|
||||
)
|
||||
result = []
|
||||
for item in host_network:
|
||||
result.append(item['ip'])
|
||||
self.assertIn('10.145.88.30', result)
|
||||
|
||||
def test_add_host_network_session(self):
|
||||
with database.session() as session:
|
||||
host.add_host_network(
|
||||
self.user_object,
|
||||
self.host_ids[0],
|
||||
interface='eth1',
|
||||
ip='10.145.88.40',
|
||||
subnet_id=self.subnet_ids[0],
|
||||
is_mgmt=True,
|
||||
session=session
|
||||
)
|
||||
host_network = host.list_host_networks(
|
||||
self.user_object,
|
||||
self.host_ids[0]
|
||||
)
|
||||
result = []
|
||||
for item in host_network:
|
||||
result.append(item['ip'])
|
||||
self.assertIn('10.145.88.40', result)
|
||||
|
||||
def test_add_host_network_position_session(self):
|
||||
with database.session() as session:
|
||||
host.add_host_network(
|
||||
self.user_object,
|
||||
self.host_ids[0],
|
||||
True,
|
||||
'eth1',
|
||||
session,
|
||||
ip='10.145.88.50',
|
||||
subnet_id=self.subnet_ids[0],
|
||||
is_mgmt=True
|
||||
)
|
||||
host_network = host.list_host_networks(
|
||||
self.user_object,
|
||||
self.host_ids[0]
|
||||
)
|
||||
result = []
|
||||
for item in host_network:
|
||||
result.append(item['ip'])
|
||||
self.assertIn('10.145.88.50', result)
|
||||
|
||||
def test_invalid_parameter(self):
|
||||
self.assertRaises(
|
||||
exception.InvalidParameter,
|
||||
@ -1167,6 +1227,57 @@ class TestAddHostLogHistory(HostTestCase):
|
||||
result.append(log['filename'])
|
||||
self.assertIn('add_log', result)
|
||||
|
||||
def test_add_host_log_history_position(self):
|
||||
host.add_host_log_history(
|
||||
self.user_object,
|
||||
self.host_ids[0],
|
||||
False,
|
||||
'add_log_position'
|
||||
)
|
||||
logs = host.get_host_log_histories(
|
||||
self.user_object,
|
||||
self.host_ids[0]
|
||||
)
|
||||
result = []
|
||||
for log in logs:
|
||||
result.append(log['filename'])
|
||||
self.assertIn('add_log_position', result)
|
||||
|
||||
def test_add_host_log_history_session(self):
|
||||
with database.session() as session:
|
||||
host.add_host_log_history(
|
||||
self.user_object,
|
||||
self.host_ids[0],
|
||||
filename='add_log_session',
|
||||
session=session
|
||||
)
|
||||
logs = host.get_host_log_histories(
|
||||
self.user_object,
|
||||
self.host_ids[0]
|
||||
)
|
||||
result = []
|
||||
for log in logs:
|
||||
result.append(log['filename'])
|
||||
self.assertIn('add_log_session', result)
|
||||
|
||||
def test_add_host_log_history_position_session(self):
|
||||
with database.session() as session:
|
||||
host.add_host_log_history(
|
||||
self.user_object,
|
||||
self.host_ids[0],
|
||||
False,
|
||||
'add_log_position_session',
|
||||
session
|
||||
)
|
||||
logs = host.get_host_log_histories(
|
||||
self.user_object,
|
||||
self.host_ids[0]
|
||||
)
|
||||
result = []
|
||||
for log in logs:
|
||||
result.append(log['filename'])
|
||||
self.assertIn('add_log_position_session', result)
|
||||
|
||||
|
||||
class TestPoweronHost(HostTestCase):
|
||||
"""Test poweron host."""
|
||||
|
@ -103,13 +103,54 @@ class TestAddSubnet(BaseTest):
|
||||
self.user_object,
|
||||
subnet='10.145.89.0/24'
|
||||
)
|
||||
add_subnet = network.list_subnets(
|
||||
add_subnets = network.list_subnets(
|
||||
self.user_object
|
||||
)
|
||||
expected = '10.145.89.0/24'
|
||||
self.assertTrue(
|
||||
item in add_subnet[0].items() for item in expected
|
||||
for add_subnet in add_subnets:
|
||||
self.assertEqual(expected, add_subnet['subnet'])
|
||||
|
||||
def test_add_subnet_position(self):
|
||||
network.add_subnet(
|
||||
self.user_object,
|
||||
True,
|
||||
'10.145.89.0/23'
|
||||
)
|
||||
add_subnets = network.list_subnets(
|
||||
self.user_object
|
||||
)
|
||||
expected = '10.145.89.0/23'
|
||||
for add_subnet in add_subnets:
|
||||
self.assertEqual(expected, add_subnet['subnet'])
|
||||
|
||||
def test_add_subnet_session(self):
|
||||
with database.session() as session:
|
||||
network.add_subnet(
|
||||
self.user_object,
|
||||
subnet='10.145.89.0/22',
|
||||
session=session
|
||||
)
|
||||
add_subnets = network.list_subnets(
|
||||
self.user_object
|
||||
)
|
||||
expected = '10.145.89.0/22'
|
||||
for add_subnet in add_subnets:
|
||||
self.assertEqual(expected, add_subnet['subnet'])
|
||||
|
||||
def test_add_subnet_position_session(self):
|
||||
with database.session() as session:
|
||||
network.add_subnet(
|
||||
self.user_object,
|
||||
True,
|
||||
'10.145.89.0/21',
|
||||
session
|
||||
)
|
||||
add_subnets = network.list_subnets(
|
||||
self.user_object
|
||||
)
|
||||
expected = '10.145.89.0/21'
|
||||
for add_subnet in add_subnets:
|
||||
self.assertEqual(expected, add_subnet['subnet'])
|
||||
|
||||
|
||||
class TestUpdateSubnet(BaseTest):
|
||||
|
@ -46,6 +46,7 @@ class TestListPermissions(BaseTest):
|
||||
def test_list_permissions(self):
|
||||
permissions = permission.list_permissions(self.user_object)
|
||||
self.assertIsNotNone(permissions)
|
||||
self.assertEqual(49, len(permissions))
|
||||
|
||||
|
||||
class TestGetPermission(BaseTest):
|
||||
@ -60,6 +61,13 @@ class TestGetPermission(BaseTest):
|
||||
def test_get_permission(self):
|
||||
get_permission = permission.get_permission(self.user_object, 1)
|
||||
self.assertIsNotNone(get_permission)
|
||||
expected = {
|
||||
'alias': 'list permissions',
|
||||
'description': 'list all permissions',
|
||||
'id': 1,
|
||||
'name': 'list_permissions'
|
||||
}
|
||||
self.assertDictEqual(get_permission, expected)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -64,11 +64,42 @@ class TestAddSwitch(BaseTest):
|
||||
def test_add_switch(self):
|
||||
add_switch = switch.add_switch(
|
||||
self.user_object,
|
||||
ip='2887583784'
|
||||
ip='2887583784',
|
||||
)
|
||||
expected = '172.29.8.40'
|
||||
self.assertEqual(expected, add_switch['ip'])
|
||||
|
||||
def test_add_switch_position_args(self):
|
||||
add_switch = switch.add_switch(
|
||||
self.user_object,
|
||||
True,
|
||||
'2887583784',
|
||||
)
|
||||
print add_switch
|
||||
expected = '172.29.8.40'
|
||||
self.assertEqual(expected, add_switch['ip'])
|
||||
|
||||
def test_add_switch_session(self):
|
||||
with database.session() as session:
|
||||
add_switch = switch.add_switch(
|
||||
self.user_object,
|
||||
ip='2887583784',
|
||||
session=session
|
||||
)
|
||||
expected = '172.29.8.40'
|
||||
self.assertEqual(expected, add_switch['ip'])
|
||||
|
||||
def test_add_switch_position_args_session(self):
|
||||
with database.session() as session:
|
||||
add_switch = switch.add_switch(
|
||||
self.user_object,
|
||||
True,
|
||||
'2887583784',
|
||||
session
|
||||
)
|
||||
expected = '172.29.8.40'
|
||||
self.assertEqual(expected, add_switch['ip'])
|
||||
|
||||
|
||||
class TestListSwitches(BaseTest):
|
||||
"""Test list switch."""
|
||||
@ -304,6 +335,42 @@ class TestAddSwitchMachine(BaseTest):
|
||||
expected = '28:6e:d4:46:c4:25'
|
||||
self.assertEqual(expected, add_switch_machine['mac'])
|
||||
|
||||
def test_add_switch_machine_position_args(self):
|
||||
add_switch_machine = switch.add_switch_machine(
|
||||
self.user_object,
|
||||
1,
|
||||
True,
|
||||
'28:6e:d4:46:c4:25',
|
||||
port='1'
|
||||
)
|
||||
expected = '28:6e:d4:46:c4:25'
|
||||
self.assertEqual(expected, add_switch_machine['mac'])
|
||||
|
||||
def test_add_switch_machine_session(self):
|
||||
with database.session() as session:
|
||||
add_switch_machine = switch.add_switch_machine(
|
||||
self.user_object,
|
||||
1,
|
||||
mac='28:6e:d4:46:c4:25',
|
||||
session=session,
|
||||
port='1'
|
||||
)
|
||||
expected = '28:6e:d4:46:c4:25'
|
||||
self.assertEqual(expected, add_switch_machine['mac'])
|
||||
|
||||
def test_add_switch_machine_position_args_session(self):
|
||||
with database.session() as session:
|
||||
add_switch_machine = switch.add_switch_machine(
|
||||
self.user_object,
|
||||
1,
|
||||
True,
|
||||
'28:6e:d4:46:c4:25',
|
||||
session,
|
||||
port='1'
|
||||
)
|
||||
expected = '28:6e:d4:46:c4:25'
|
||||
self.assertEqual(expected, add_switch_machine['mac'])
|
||||
|
||||
|
||||
class TestListSwitchMachines(BaseTest):
|
||||
"""Test get switch machines."""
|
||||
|
@ -176,6 +176,16 @@ class TestAddUser(BaseTest):
|
||||
)
|
||||
self.assertEqual('test@abc.com', user_objs['email'])
|
||||
|
||||
def test_add_user_session(self):
|
||||
with database.session() as session:
|
||||
user_objs = user_api.add_user(
|
||||
self.user_object,
|
||||
email='test@abc.com',
|
||||
password='password',
|
||||
session=session
|
||||
)
|
||||
self.assertEqual('test@abc.com', user_objs['email'])
|
||||
|
||||
|
||||
class TestDelUser(BaseTest):
|
||||
"""Test delete user."""
|
||||
@ -298,6 +308,60 @@ class TestAddDelUserPermission(BaseTest):
|
||||
result = permission['name']
|
||||
self.assertEqual(result, 'list_switches')
|
||||
|
||||
def test_add_permission_position(self):
|
||||
user_api.add_permission(
|
||||
self.user_object,
|
||||
self.user_object.id,
|
||||
True,
|
||||
2
|
||||
)
|
||||
permissions = user_api.get_permissions(
|
||||
self.user_object,
|
||||
self.user_object.id
|
||||
)
|
||||
result = None
|
||||
for permission in permissions:
|
||||
if permission['id'] == 2:
|
||||
result = permission['name']
|
||||
self.assertEqual(result, 'list_switches')
|
||||
|
||||
def test_add_permission_session(self):
|
||||
with database.session() as session:
|
||||
user_api.add_permission(
|
||||
self.user_object,
|
||||
self.user_object.id,
|
||||
permission_id=2,
|
||||
session=session
|
||||
)
|
||||
permissions = user_api.get_permissions(
|
||||
self.user_object,
|
||||
self.user_object.id
|
||||
)
|
||||
result = None
|
||||
for permission in permissions:
|
||||
if permission['id'] == 2:
|
||||
result = permission['name']
|
||||
self.assertEqual(result, 'list_switches')
|
||||
|
||||
def test_add_permission_position_session(self):
|
||||
with database.session() as session:
|
||||
user_api.add_permission(
|
||||
self.user_object,
|
||||
self.user_object.id,
|
||||
True,
|
||||
2,
|
||||
session
|
||||
)
|
||||
permissions = user_api.get_permissions(
|
||||
self.user_object,
|
||||
self.user_object.id
|
||||
)
|
||||
result = None
|
||||
for permission in permissions:
|
||||
if permission['id'] == 2:
|
||||
result = permission['name']
|
||||
self.assertEqual(result, 'list_switches')
|
||||
|
||||
def test_del_permission(self):
|
||||
user_api.del_permission(
|
||||
self.user_object,
|
||||
|
Loading…
x
Reference in New Issue
Block a user