Example #1
0
## Create a new user, which will fail if the user already exists
#createuser -h $dbHost $dbUser
#
## Create the database
#createdb -h $dbHost -U postgres --owner=$dbUser $dbName

# Change the password for postgres user
#read -s -p "Enter password for user $dbUser: "******"ALTER USER $dbUser WITH password '$password'";
#psql -h $dbHost -U postgres $dbName -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO $dbUser";

# Try and authenticate, giving up if password-less auth has not been configured
try:
    windb = windb2.WinDB2(args.dbhost,
                          args.dbname,
                          dbUser=args.dbuser,
                          port=args.port)
    windb.connect()

except psycopg2.OperationalError as e:

    # See if we can create the database
    if str(e).strip() == 'FATAL:  database "{}" does not exist'.format(
            args.dbname):

        # Create the database
        print('database "{}" does not exist... trying to create it'.format(
            args.dbname))
        try:
            conn = psycopg2.connect(user=args.dbuser,
                                    host=args.dbhost,
Example #2
0
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-d",
                   "--domain_key",
                   type=str,
                   help="Existing domain key in the WinDB2")
group.add_argument("-n",
                   "--new",
                   action="store_false",
                   help="Create a new WinDB2 domain")
args = parser.parse_args()

# TODO make sure that -m and -n are only used together (i.e. -m should not be used with -d)

# Connect to the WinDB
windb2 = windb2.WinDB2(args.db_host,
                       args.db_name,
                       dbUser=args.db_user,
                       port=args.port)
windb2.connect()

# Load a WinDB2 config file
windb2_config = config.WinDB2GFSConfigParser('windb2-gfs.json')

# Set up logging
LOGLEVEL = os.environ.get('LOGLEVEL', 'ERROR').upper()
logger = logging.getLogger(__name__)
try:
    logger.setLevel(LOGLEVEL)
except KeyError:
    print('invalid log level: {}, setting to INFO by default'.format(LOGLEVEL),
          file=sys.stderr)
    logger.setLevel(logging.INFO)
Example #3
0
parser.add_argument('dbUser', help='Database user')
parser.add_argument('dbName', help='Database name')
parser.add_argument('-p',
                    '--port',
                    type=int,
                    default='5432',
                    help='Port for WinDB2 connection')
parser.add_argument('-d',
                    '--dir',
                    type=str,
                    default='domain-inventory',
                    help='Directory name to store the inventory in.')
args = parser.parse_args()

# Connect to the WinDB
windb2 = windb2.WinDB2(args.dbHost, args.dbName, args.dbUser, port=args.port)
windb2.connect()

# Get all of the domains
sql = 'SELECT key FROM domain'
windb2.curs.execute(sql)
domains = windb2.curs.fetchall()

# Make sure the directory for the results exists
try:
    os.chdir(args.dir)
except FileNotFoundError:
    os.mkdir(args.dir)
    os.chdir(args.dir)

# Create the inventory
Example #4
0
 def setUp(self):
     self.db = windb2.WinDB2('localhost',
                             'windb2-test-1',
                             dbUser='******')
     self.db.connect()