diff options
Diffstat (limited to 'lib/ansible/modules/database/vertica/vertica_schema.py')
-rw-r--r-- | lib/ansible/modules/database/vertica/vertica_schema.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/ansible/modules/database/vertica/vertica_schema.py b/lib/ansible/modules/database/vertica/vertica_schema.py index b92b8873de..713435f635 100644 --- a/lib/ansible/modules/database/vertica/vertica_schema.py +++ b/lib/ansible/modules/database/vertica/vertica_schema.py @@ -122,11 +122,13 @@ from ansible.module_utils._text import to_native class NotSupportedError(Exception): pass + class CannotDropError(Exception): pass # module specific functions + def get_schema_facts(cursor, schema=''): facts = {} cursor.execute(""" @@ -167,6 +169,7 @@ def get_schema_facts(cursor, schema=''): facts[schema_key]['usage_roles'].append(row.role_name) return facts + def update_roles(schema_facts, cursor, schema, existing, required, create_existing, create_required): @@ -180,6 +183,7 @@ def update_roles(schema_facts, cursor, schema, for role in set(create_required) - set(create_existing): cursor.execute("grant create on schema {0} to {1}".format(schema, role)) + def check(schema_facts, schema, usage_roles, create_roles, owner): schema_key = schema.lower() if schema_key not in schema_facts: @@ -192,6 +196,7 @@ def check(schema_facts, schema, usage_roles, create_roles, owner): return False return True + def present(schema_facts, cursor, schema, usage_roles, create_roles, owner): schema_key = schema.lower() if schema_key not in schema_facts: @@ -208,23 +213,24 @@ def present(schema_facts, cursor, schema, usage_roles, create_roles, owner): raise NotSupportedError(( "Changing schema owner is not supported. " "Current owner: {0}." - ).format(schema_facts[schema_key]['owner'])) + ).format(schema_facts[schema_key]['owner'])) if sorted(usage_roles) != sorted(schema_facts[schema_key]['usage_roles']) or \ sorted(create_roles) != sorted(schema_facts[schema_key]['create_roles']): update_roles(schema_facts, cursor, schema, - schema_facts[schema_key]['usage_roles'], usage_roles, - schema_facts[schema_key]['create_roles'], create_roles) + schema_facts[schema_key]['usage_roles'], usage_roles, + schema_facts[schema_key]['create_roles'], create_roles) changed = True if changed: schema_facts.update(get_schema_facts(cursor, schema)) return changed + def absent(schema_facts, cursor, schema, usage_roles, create_roles): schema_key = schema.lower() if schema_key in schema_facts: update_roles(schema_facts, cursor, schema, - schema_facts[schema_key]['usage_roles'], [], schema_facts[schema_key]['create_roles'], []) + schema_facts[schema_key]['usage_roles'], [], schema_facts[schema_key]['create_roles'], []) try: cursor.execute("drop schema {0} restrict".format(schema_facts[schema_key]['name'])) except pyodbc.Error: @@ -236,6 +242,7 @@ def absent(schema_facts, cursor, schema, usage_roles, create_roles): # module logic + def main(): module = AnsibleModule( @@ -250,7 +257,7 @@ def main(): port=dict(default='5433'), login_user=dict(default='dbadmin'), login_password=dict(default=None, no_log=True), - ), supports_check_mode = True) + ), supports_check_mode=True) if not pyodbc_found: module.fail_json(msg="The python pyodbc module is required.") @@ -281,8 +288,8 @@ def main(): "User={3};" "Password={4};" "ConnectionLoadBalance={5}" - ).format(module.params['cluster'], module.params['port'], db, - module.params['login_user'], module.params['login_password'], 'true') + ).format(module.params['cluster'], module.params['port'], db, + module.params['login_user'], module.params['login_password'], 'true') db_conn = pyodbc.connect(dsn, autocommit=True) cursor = db_conn.cursor() except Exception as e: |