/usr/lib/python2.7/dist-packages/heatclient/osc/v1/software_config.py is in python-heatclient 1.1.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | # Licensed 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.
#
"""Orchestration v1 software config action implementations"""
import logging
import six
from six.moves.urllib import request
import yaml
from cliff import command
from cliff import lister
from openstackclient.common import exceptions as exc
from openstackclient.common import utils
from heatclient.common import format_utils
from heatclient.common import template_format
from heatclient.common import utils as heat_utils
from heatclient import exc as heat_exc
from heatclient.openstack.common._i18n import _
class DeleteConfig(command.Command):
"""Delete software configs"""
log = logging.getLogger(__name__ + ".DeleteConfig")
def get_parser(self, prog_name):
parser = super(DeleteConfig, self).get_parser(prog_name)
parser.add_argument(
'config',
metavar='<config>',
nargs='+',
help=_('IDs of the software configs to delete')
)
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args)
heat_client = self.app.client_manager.orchestration
return _delete_config(heat_client, parsed_args)
def _delete_config(heat_client, args):
failure_count = 0
for config_id in args.config:
try:
heat_client.software_configs.delete(
config_id=config_id)
except Exception as e:
if isinstance(e, heat_exc.HTTPNotFound):
print(_('Software config with ID %s not found') % config_id)
failure_count += 1
continue
if failure_count:
raise exc.CommandError(_('Unable to delete %(count)s of the '
'%(total)s software configs.') %
{'count': failure_count,
'total': len(args.config)})
class ListConfig(lister.Lister):
"""List software configs"""
log = logging.getLogger(__name__ + ".ListConfig")
def get_parser(self, prog_name):
parser = super(ListConfig, self).get_parser(prog_name)
parser.add_argument(
'--limit',
metavar='<limit>',
help=_('Limit the number of configs returned')
)
parser.add_argument(
'--marker',
metavar='<id>',
help=_('Return configs that appear after the given config ID')
)
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args)
heat_client = self.app.client_manager.orchestration
return _list_config(heat_client, parsed_args)
def _list_config(heat_client, args):
kwargs = {}
if args.limit:
kwargs['limit'] = args.limit
if args.marker:
kwargs['marker'] = args.marker
scs = heat_client.software_configs.list(**kwargs)
columns = ['id', 'name', 'group', 'creation_time']
return (columns, (utils.get_item_properties(s, columns) for s in scs))
class CreateConfig(format_utils.JsonFormat):
"""Create software config"""
log = logging.getLogger(__name__ + ".CreateConfig")
def get_parser(self, prog_name):
parser = super(CreateConfig, self).get_parser(prog_name)
parser.add_argument(
'name',
metavar='<config-name>',
help=_('Name of the software config to create')
)
parser.add_argument(
'--config-file',
metavar='<config-file>',
help=_('Path to JSON/YAML containing map defining '
'<inputs>, <outputs>, and <options>')
)
parser.add_argument(
'--definition-file',
metavar='<destination-file>',
help=_('Path to software config script/data')
)
parser.add_argument(
'--group',
metavar='<group>',
default='Heat::Ungrouped',
help=_('Group name of tool expected by the software config')
)
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args)
heat_client = self.app.client_manager.orchestration
return _create_config(heat_client, parsed_args)
def _create_config(heat_client, args):
config = {
'group': args.group,
'config': ''
}
defn = {}
if args.definition_file:
defn_url = heat_utils.normalise_file_path_to_url(
args.definition_file)
defn_raw = request.urlopen(defn_url).read() or '{}'
defn = yaml.load(defn_raw, Loader=template_format.yaml_loader)
config['inputs'] = defn.get('inputs', [])
config['outputs'] = defn.get('outputs', [])
config['options'] = defn.get('options', {})
if args.config_file:
config_url = heat_utils.normalise_file_path_to_url(
args.config_file)
config['config'] = request.urlopen(config_url).read()
# build a mini-template with a config resource and validate it
validate_template = {
'heat_template_version': '2013-05-23',
'resources': {
args.name: {
'type': 'OS::Heat::SoftwareConfig',
'properties': config
}
}
}
heat_client.stacks.validate(template=validate_template)
config['name'] = args.name
sc = heat_client.software_configs.create(**config).to_dict()
rows = list(six.itervalues(sc))
columns = list(six.iterkeys(sc))
return columns, rows
class ShowConfig(format_utils.YamlFormat):
"""Show software config details"""
log = logging.getLogger(__name__ + ".ShowConfig")
def get_parser(self, prog_name):
parser = super(ShowConfig, self).get_parser(prog_name)
parser.add_argument(
'config',
metavar='<config>',
help=_('ID of the config')
)
parser.add_argument(
'--config-only',
default=False,
action="store_true",
help=_('Only display the value of the <config> property.')
)
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args)
heat_client = self.app.client_manager.orchestration
return _show_config(heat_client, config_id=parsed_args.config,
config_only=parsed_args.config_only)
def _show_config(heat_client, config_id, config_only):
try:
sc = heat_client.software_configs.get(config_id=config_id)
except heat_exc.HTTPNotFound:
raise exc.CommandError(_('Configuration not found: %s') % config_id)
columns = None
rows = None
if config_only:
print(sc.config)
else:
columns = (
'id',
'name',
'group',
'config',
'inputs',
'outputs',
'options',
'creation_time',
)
rows = utils.get_dict_properties(sc.to_dict(), columns)
return columns, rows
|