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