2 #============LICENSE_START==========================================================
4 # ==================================================================================
5 # Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
6 # ==================================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END===========================================================
22 from sqlalchemy.orm.attributes import flag_modified
23 from manager_rest.flask_utils import setup_flask_app
24 from manager_rest.constants import PROVIDER_CONTEXT_ID
25 from manager_rest.storage import get_storage_manager, models
28 def main(dry_run, rules_file):
30 with setup_flask_app().app_context():
31 sm = get_storage_manager()
32 ctx = sm.get(models.ProviderContext, PROVIDER_CONTEXT_ID)
33 print 'Resolver rules before update:'
34 print yaml.safe_dump(ctx.context['cloudify']['import_resolver']['parameters']['rules'])
39 with open(rules_file, 'r') as rules:
40 new_rules = yaml.load(rules)
41 ctx.context['cloudify']['import_resolver']['parameters']['rules'] = new_rules
42 print '\nResolver rules to update:'
43 print yaml.safe_dump(new_rules)
44 flag_modified(ctx, 'context')
46 print '\nProvide Context Saved'
47 print '\nResolver rules after update:'
48 print yaml.safe_dump(ctx.context['cloudify']['import_resolver']['parameters']['rules'])
51 if __name__ == '__main__':
53 print 'Must provide path to yaml file containing new rules or --dry-run'
56 main(sys.argv[1]=='--dry-run', sys.argv[1])