diff options
author | shiva-charan.m-s <shiva-charan.m-s@hpe.com> | 2016-07-26 22:34:23 -0500 |
---|---|---|
committer | shiva-charan <shiva-charan.m-s@hpe.com> | 2016-08-22 12:32:45 -0500 |
commit | d93490753ba93e4c3aa00cd487855e3d2970ae9a (patch) | |
tree | 9129d35d1df3c36f206d37b657a9100a39a94952 /policy2tosca/policy2tosca/del_definition.py | |
parent | 1a9b3ea86e026115938b1872ac1fc3bce30055ed (diff) |
policy2tosca patch set-6
Signed-off-by: shiva-charan <shiva-charan.m-s@hpe.com>
Diffstat (limited to 'policy2tosca/policy2tosca/del_definition.py')
-rw-r--r-- | policy2tosca/policy2tosca/del_definition.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/policy2tosca/policy2tosca/del_definition.py b/policy2tosca/policy2tosca/del_definition.py new file mode 100644 index 0000000..d8345cd --- /dev/null +++ b/policy2tosca/policy2tosca/del_definition.py @@ -0,0 +1,45 @@ +# 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. + +import logging +import os +from cliff.command import Command +from cliff.show import ShowOne +import yaml +import json + + +class Delete_definition(Command): + "Delete policy in a tosca file" + + log = logging.getLogger(__name__) + + def get_parser(self, prog_name): + parser = super(Delete_definition, self).get_parser(prog_name) + parser.add_argument('--policy_name', dest='policy_name', nargs='?', + help='delete policy') + parser.add_argument('--source', dest='source', nargs='?', + help='source tosca yaml file') + return parser + + def take_action(self, parsed_args): + yml = open(parsed_args.source, "r") + data = yaml.load(yml) + json_dump = json.dumps(data) + tosca_json = json.loads(json_dump) + del tosca_json['topology_template']['policies'][parsed_args.policy_name] + tosca = json.dumps(tosca_json) + data2 = json.loads(tosca) + yml2 = yaml.safe_dump(data2, default_flow_style=False) + tosca_file = open(parsed_args.source, "w") + tosca_file.write(yml2) |