5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # pylint: disable=line-too-long, too-few-public-methods
19 from copy import deepcopy
21 from hostcli.helper import ListerHelper, ShowOneHelper, CommandHelper
24 RESOURCE_PREFIX = 'caas/%s/' % API_VERSION
26 NAMESPACE = 'namespace'
28 TARGETURL = 'target_url'
34 'help': 'The ID of the log entry'},
35 NAMESPACE: {'display': 'namespace',
36 'help': 'The kubernetes namespace where the log entry applies'},
37 PLUGIN: {'display': 'plugin',
38 'help': 'The fluentd plugin which is used for forwarding log entries. '
39 'Should be one of remote_syslog, elasticsearch'},
40 TARGETURL: {'display': 'target_url',
41 'help': 'The URL of the log storage where fluentd will send log entries'},
42 STREAM: {'display': 'stream',
43 'help': 'The stream which will be logged by fluentd. '
44 'Should be one of stdout, stderr, both'}
48 class CaasCliLister(ListerHelper):
49 """Helper class for Lister"""
50 def __init__(self, app, app_args, cmd_name=None):
51 super(CaasCliLister, self).__init__(app, app_args, cmd_name)
52 self.fieldmap = deepcopy(FIELDMAP)
53 self.resource_prefix = RESOURCE_PREFIX
56 class CaasCliShowOne(ShowOneHelper):
57 """Helper class for ShowOne"""
58 def __init__(self, app, app_args, cmd_name=None):
59 super(CaasCliShowOne, self).__init__(app, app_args, cmd_name)
60 self.fieldmap = deepcopy(FIELDMAP)
61 self.resource_prefix = RESOURCE_PREFIX
64 class CaasCliCommand(CommandHelper):
65 """Helper class for Command"""
66 def __init__(self, app, app_args, cmd_name=None):
67 super(CaasCliCommand, self).__init__(app, app_args, cmd_name)
68 self.fieldmap = deepcopy(FIELDMAP)
69 self.resource_prefix = RESOURCE_PREFIX
72 class CreateAppLogBackend(CaasCliCommand):
73 """A command for adding a new CaaS application log forwarding entry."""
75 def __init__(self, app, app_args, cmd_name=None):
76 super(CreateAppLogBackend, self).__init__(app, app_args, cmd_name)
77 self.operation = 'post'
78 self.endpoint = 'log/apps'
79 self.mandatory_positional = True
80 self.positional_count = 4
81 self.arguments = [NAMESPACE, PLUGIN, TARGETURL, STREAM]
82 self.message = 'Entry has been added.'
85 class ChangeAppLogBackend(CaasCliCommand):
86 """A command for modifying a CaaS application log forwarding entry."""
88 def __init__(self, app, app_args, cmd_name=None):
89 super(ChangeAppLogBackend, self).__init__(app, app_args, cmd_name)
90 self.operation = 'put'
91 self.endpoint = 'log/apps'
92 self.mandatory_positional = True
93 self.positional_count = 1
94 self.arguments = [ID, NAMESPACE, PLUGIN, TARGETURL, STREAM]
95 self.message = 'Entry has been updated.'
98 class DeleteAppLogBackend(CaasCliCommand):
99 """A command for removing a CaaS application log forwarding entry."""
101 def __init__(self, app, app_args, cmd_name=None):
102 super(DeleteAppLogBackend, self).__init__(app, app_args, cmd_name)
103 self.operation = 'delete'
104 self.endpoint = 'log/apps'
105 self.mandatory_positional = True
106 self.positional_count = 1
107 self.arguments = [ID]
108 self.message = 'Entry has been deleted.'
111 class ShowAppLogBackend(CaasCliShowOne):
112 """A command for showing detail of a CaaS application log forwarding entry."""
114 def __init__(self, app, app_args, cmd_name=None):
115 super(ShowAppLogBackend, self).__init__(app, app_args, cmd_name)
116 self.operation = 'get'
117 self.endpoint = 'log/apps'
118 self.mandatory_positional = True
119 self.positional_count = 1
120 self.arguments = [ID]
121 self.columns = [ID, NAMESPACE, PLUGIN, TARGETURL, STREAM]
122 self.default_sort = [ID, 'asc']
125 class ListAppLogBackend(CaasCliLister):
126 """A command for listing existing CaaS application log forwarding entries."""
128 def __init__(self, app, app_args, cmd_name=None):
129 super(ListAppLogBackend, self).__init__(app, app_args, cmd_name)
130 self.operation = 'get'
131 self.endpoint = 'log/apps'
132 self.no_positional = True
133 self.columns = [ID, NAMESPACE, PLUGIN, TARGETURL, STREAM]
134 self.default_sort = [ID, 'asc']
137 class ListAppLogBackendForNamespace(CaasCliLister):
138 """A command for listing existing CaaS application log forwarding entries for a namespace"""
140 def __init__(self, app, app_args, cmd_name=None):
141 super(ListAppLogBackendForNamespace, self).__init__(app, app_args, cmd_name)
142 self.operation = 'get'
143 self.endpoint = 'log/apps'
144 self.mandatory_positional = True
145 self.positional_count = 1
146 self.arguments = [NAMESPACE]
147 self.columns = [ID, NAMESPACE, PLUGIN, TARGETURL, STREAM]
148 self.default_sort = [ID, 'asc']