Github user ran-z commented on a diff in the pull request:
https://github.com/apache/incubator-ariatosca/pull/97#discussion_r111984557
--- Diff: aria/cli/commands/services.py ---
@@ -0,0 +1,180 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import os
+from StringIO import StringIO
+
+from . import service_templates
+from ..cli import aria, helptexts
+from ..exceptions import AriaCliError
+from ..table import print_data
+from ..utils import storage_sort_param, handle_storage_exception
+from ...core import Core
+from ...exceptions import AriaException
+from ...storage import exceptions as storage_exceptions
+
+
+SERVICE_COLUMNS = ['id', 'name', 'service_template_name', 'created_at',
'updated_at']
+
+
[email protected](name='services')
[email protected]()
+def services():
+ """Handle services
+ """
+ pass
+
+
[email protected](name='list', short_help='List services')
[email protected]_template_name()
[email protected]_by()
[email protected]
[email protected]()
[email protected]_model_storage
[email protected]_logger
+def list(service_template_name,
+ sort_by,
+ descending,
+ model_storage,
+ logger):
+ """List services
+
+ If `--service-template-name` is provided, list services for that
service template.
+ Otherwise, list services for all service templates.
+ """
+ if service_template_name:
+ logger.info('Listing services for service template {0}...'.format(
+ service_template_name))
+ service_template =
model_storage.service_template.get(service_template_name)
+ filters = dict(service_template=service_template)
+ else:
+ logger.info('Listing all service...')
+ filters = {}
+
+ services_list = [d.to_dict() for d in model_storage.service.list(
+ sort=storage_sort_param(sort_by=sort_by, descending=descending),
+ filters=filters)]
+ print_data(SERVICE_COLUMNS, services_list, 'Services:')
+
+
[email protected](name='create',
+ short_help='Create a services')
[email protected]('service-name', required=False)
[email protected]_template_name(required=True)
[email protected]
[email protected]()
[email protected]_model_storage
[email protected]_resource_storage
[email protected]_plugin_manager
[email protected]_logger
+def create(service_template_name,
+ service_name,
+ inputs, # pylint: disable=redefined-outer-name
+ model_storage,
+ resource_storage,
+ plugin_manager,
+ logger):
+ """Create a service
+
+ `SERVICE_NAME` is the name of the service you'd like to create.
+
+ """
+ logger.info('Creating new service from service template {0}...'.format(
+ service_template_name))
+
+ try:
+ core = Core(model_storage, resource_storage, plugin_manager)
+ service_template =
model_storage.service_template.get_by_name(service_template_name)
+ service = core.create_service(service_template.id, inputs,
service_name)
+ except storage_exceptions.StorageError as e:
+ handle_storage_exception(e, 'service', service_name)
+ except AriaException as e:
+ logger.info(str(e))
--- End diff --
:+1:
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---