Kaynağa Gözat

added domain commands

Daniel-Constantin Mierla 8 yıl önce
ebeveyn
işleme
6fabba5c4d
1 değiştirilmiş dosya ile 107 ekleme ve 0 silme
  1. 107 0
      kamcli/commands/cmd_domain.py

+ 107 - 0
kamcli/commands/cmd_domain.py

@@ -0,0 +1,107 @@
+import click
+from sqlalchemy import create_engine
+from kamcli.ioutils import ioutils_dbres_print
+from kamcli.cli import pass_context
+from kamcli.cli import parse_user_spec
+from kamcli.iorpc import command_ctl
+
+
+##
+#
+#
[email protected]('domain', help='Manage domain module (multi-domain records)')
+@pass_context
+def cli(ctx):
+    pass
+
+
+##
+#
+#
[email protected]('add', short_help='Add a new domain')
[email protected]('domain', metavar='<domain>')
+@pass_context
+def domain_add(ctx, domain):
+    """Add a new domain
+
+    \b
+    Parameters:
+        <domain> - domain value
+    """
+    ctx.vlog('Adding a new domain [%s]', domain)
+    e = create_engine(ctx.gconfig.get('db', 'rwurl'))
+    e.execute('insert into domain (domain) values ({0!r})'.format(domain.encode('ascii','ignore')))
+
+
+##
+#
+#
[email protected]('rm', short_help='Remove a record from domain table')
[email protected]('destination', metavar='<destination>')
+@pass_context
+def domain_rm(ctx, domain):
+    """Remove a a record from db domain table
+
+    \b
+    Parameters:
+        <domain> - domain value
+    """
+    e = create_engine(ctx.gconfig.get('db', 'rwurl'))
+    e.execute('delete from domain where domain={0!r}'.format(domain.encode('ascii','ignore')))
+
+
+##
+#
+#
[email protected]('showdb', short_help='Show domain records in database')
[email protected]('oformat', '--output-format', '-F',
+                type=click.Choice(['raw', 'json', 'table', 'dict']),
+                default=None, help='Format the output')
[email protected]('ostyle', '--output-style', '-S',
+                default=None, help='Style of the output (tabulate table format)')
[email protected]('domain', nargs=-1, metavar='[<domain>]')
+@pass_context
+def domain_showdb(ctx, oformat, ostyle, domain):
+    """Show details for records in domain table
+
+    \b
+    Parameters:
+        [<domain>] - domain value (optional)
+    """
+    e = create_engine(ctx.gconfig.get('db', 'rwurl'))
+    if not setid:
+        ctx.vlog('Showing all domain records')
+        res = e.execute('select * from domain')
+        ioutils_dbres_print(ctx, oformat, ostyle, res)
+    else:
+        for d in domain:
+            ctx.vlog('Showing a specific domain record')
+            res = e.execute('select * from domain where domain="%s"', d)
+            ioutils_dbres_print(ctx, oformat, ostyle, res)
+
+
+##
+#
+#
[email protected]('list', short_help='Show details for domain records in memory')
+@pass_context
+def domain_list(ctx):
+    """Show details for domain records in memory
+
+    \b
+    """
+    command_ctl(ctx, 'domain.dump', [ ])
+
+
+##
+#
+#
[email protected]('reload', short_help='Reload domain records from database into memory')
+@pass_context
+def domain_reload(ctx):
+    """Reload domain records from database into memory
+
+    \b
+    """
+    command_ctl(ctx, 'domain.reload', [ ])
+