<s> """<STR_LIT>""" <EOL> import re <EOL> from compass . db . api import database <EOL> from compass . db . api import user as user_api <EOL> from compass . db . api import utils <EOL> from compass . db import exception <EOL> from compass . db import models <EOL> from compass . utils import util <EOL> SUPPORTED_FIELDS = [ '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT:description>' ] <EOL> RESP_FIELDS = [ '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT:description>' ] <EOL> class PermissionWrapper ( object ) : <EOL> def __init__ ( self , name , alias , description ) : <EOL> self . name = name <EOL> self . alias = alias <EOL> self . description = description <EOL> def to_dict ( self ) : <EOL> return { <EOL> '<STR_LIT:name>' : self . name , <EOL> '<STR_LIT>' : self . alias , <EOL> '<STR_LIT:description>' : self . description <EOL> } <EOL> PERMISSION_LIST_PERMISSIONS = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_SWITCHES = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_SWITCH_FILTERS = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_ADD_SWITCH = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_UPDATE_SWITCH_FILTERS = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEL_SWITCH = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_SWITCH_MACHINES = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_ADD_SWITCH_MACHINE = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEL_SWITCH_MACHINE = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_UPDATE_SWITCH_MACHINES = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_MACHINES = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_ADD_MACHINE = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEL_MACHINE = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_ADAPTERS = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_METADATAS = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_SUBNETS = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_ADD_SUBNET = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEL_SUBNET = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_CLUSTERS = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_ADD_CLUSTER = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEL_CLUSTER = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_CLUSTER_CONFIG = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_ADD_CLUSTER_CONFIG = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEL_CLUSTER_CONFIG = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_UPDATE_CLUSTER_HOSTS = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEL_CLUSTER_HOST = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_REVIEW_CLUSTER = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEPLOY_CLUSTER = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEPLOY_HOST = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_GET_CLUSTER_STATE = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_UPDATE_CLUSTER_STATE = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_HOSTS = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_HOST_CLUSTERS = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_UPDATE_HOST = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEL_HOST = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_HOST_CONFIG = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_ADD_HOST_CONFIG = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEL_HOST_CONFIG = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_HOST_NETWORKS = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_ADD_HOST_NETWORK = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEL_HOST_NETWORK = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_GET_HOST_STATE = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_UPDATE_HOST_STATE = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_CLUSTERHOSTS = PermissionWrapper ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_CLUSTERHOST_CONFIG = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_ADD_CLUSTERHOST_CONFIG = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DEL_CLUSTERHOST_CONFIG = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_GET_CLUSTERHOST_STATE = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_UPDATE_CLUSTERHOST_STATE = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_LIST_HEALTH_REPORT = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_GET_HEALTH_REPORT = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_CHECK_CLUSTER_HEALTH = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_SET_HEALTH_CHECK_ERROR = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSION_DELETE_REPORT = PermissionWrapper ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> PERMISSIONS = [ <EOL> PERMISSION_LIST_PERMISSIONS , <EOL> PERMISSION_LIST_SWITCHES , <EOL> PERMISSION_ADD_SWITCH , <EOL> PERMISSION_DEL_SWITCH , <EOL> PERMISSION_LIST_SWITCH_FILTERS , <EOL> PERMISSION_UPDATE_SWITCH_FILTERS , <EOL> PERMISSION_LIST_SWITCH_MACHINES , <EOL> PERMISSION_ADD_SWITCH_MACHINE , <EOL> PERMISSION_DEL_SWITCH_MACHINE , <EOL> PERMISSION_UPDATE_SWITCH_MACHINES , <EOL> PERMISSION_LIST_MACHINES , <EOL> PERMISSION_ADD_MACHINE , <EOL> PERMISSION_DEL_MACHINE , <EOL> PERMISSION_LIST_ADAPTERS , <EOL> PERMISSION_LIST_METADATAS , <EOL> PERMISSION_LIST_SUBNETS , <EOL> PERMISSION_ADD_SUBNET , <EOL> PERMISSION_DEL_SUBNET , <EOL> PERMISSION_LIST_CLUSTERS , <EOL> PERMISSION_ADD_CLUSTER , <EOL> PERMISSION_DEL_CLUSTER , <EOL> PERMISSION_LIST_CLUSTER_CONFIG , <EOL> PERMISSION_ADD_CLUSTER_CONFIG , <EOL> PERMISSION_DEL_CLUSTER_CONFIG , <EOL> PERMISSION_UPDATE_CLUSTER_HOSTS , <EOL> PERMISSION_DEL_CLUSTER_HOST , <EOL> PERMISSION_REVIEW_CLUSTER , <EOL> PERMISSION_DEPLOY_CLUSTER , <EOL> PERMISSION_GET_CLUSTER_STATE , <EOL> PERMISSION_UPDATE_CLUSTER_STATE , <EOL> PERMISSION_LIST_HOSTS , <EOL> PERMISSION_LIST_HOST_CLUSTERS , <EOL> PERMISSION_UPDATE_HOST , <EOL> PERMISSION_DEL_HOST , <EOL> PERMISSION_LIST_HOST_CONFIG , <EOL> PERMISSION_ADD_HOST_CONFIG , <EOL> PERMISSION_DEL_HOST_CONFIG , <EOL> PERMISSION_LIST_HOST_NETWORKS , <EOL> PERMISSION_ADD_HOST_NETWORK , <EOL> PERMISSION_DEL_HOST_NETWORK , <EOL> PERMISSION_GET_HOST_STATE , <EOL> PERMISSION_UPDATE_HOST_STATE , <EOL> PERMISSION_DEPLOY_HOST , <EOL> PERMISSION_LIST_CLUSTERHOSTS , <EOL> PERMISSION_LIST_CLUSTERHOST_CONFIG , <EOL> PERMISSION_ADD_CLUSTERHOST_CONFIG , <EOL> PERMISSION_DEL_CLUSTERHOST_CONFIG , <EOL> PERMISSION_GET_CLUSTERHOST_STATE , <EOL> PERMISSION_UPDATE_CLUSTERHOST_STATE , <EOL> PERMISSION_LIST_HEALTH_REPORT , <EOL> PERMISSION_GET_HEALTH_REPORT , <EOL> PERMISSION_CHECK_CLUSTER_HEALTH , <EOL> PERMISSION_SET_HEALTH_CHECK_ERROR , <EOL> PERMISSION_DELETE_REPORT <EOL> ] <EOL> @ util . deprecated <EOL> def list_permissions_internal ( session , ** filters ) : <EOL> """<STR_LIT>""" <EOL> return utils . list_db_objects ( session , models . Permission , ** filters ) <EOL> @ utils . supported_filters ( optional_support_keys = SUPPORTED_FIELDS ) <EOL> @ database . run_in_session ( ) <EOL> @ user_api . check_user_permission ( PERMISSION_LIST_PERMISSIONS ) <EOL> @ utils . wrap_to_dict ( RESP_FIELDS ) <EOL> def list_permissions ( user = None , session = None , ** filters ) : <EOL> """<STR_LIT>""" <EOL> return utils . list_db_objects ( <EOL> session , models . Permission , ** filters <EOL> ) <EOL> def _get_permission ( permission_id , session = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( permission_id , ( int , long ) ) : <EOL> return utils . get_db_object ( <EOL> session , models . Permission , id = permission_id , ** kwargs ) <EOL> raise exception . InvalidParameter ( <EOL> '<STR_LIT>' % permission_id <EOL> ) <EOL> def get_permission_internal ( permission_id , session = None , ** kwargs ) : <EOL> return _get_permission ( permission_id , session = session , ** kwargs ) <EOL> @ utils . supported_filters ( ) <EOL> @ database . run_in_session ( ) <EOL> @ user_api . check_user_permission ( PERMISSION_LIST_PERMISSIONS ) <EOL> @ utils . wrap_to_dict ( RESP_FIELDS ) <EOL> def get_permission ( <EOL> permission_id , exception_when_missing = True , <EOL> user = None , session = None , ** kwargs <EOL> ) : <EOL> """<STR_LIT>""" <EOL> return _get_permission ( <EOL> permission_id , session = session , <EOL> exception_when_missing = exception_when_missing <EOL> ) <EOL> def add_permissions_internal ( session = None ) : <EOL> """<STR_LIT>""" <EOL> permissions = [ ] <EOL> for permission in PERMISSIONS : <EOL> permissions . append ( <EOL> utils . add_db_object ( <EOL> session , models . Permission , <EOL> True , <EOL> permission . name , <EOL> alias = permission . alias , <EOL> description = permission . description <EOL> ) <EOL> ) <EOL> return permissions </s>
