#!/usr/bin/env python
# vim: sw=2 ts=2

import click
import os
import sys

hexboard_sizes = ['tiny', 'xsmall', 'small', 'medium', 'large', 'xlarge']

@click.command()

### Cluster options
@click.option('--cluster-id', default='demo', show_default=True,
              help='Cluster identifier (used for prefixing/naming various items created in AWS')
@click.option('--num-nodes', type=click.INT, default=1, show_default=True,
              help='Number of application nodes')
@click.option('--num-infra', type=click.IntRange(1,3), default=1,
              show_default=True, help='Number of infrastructure nodes')
@click.option('--hexboard-size', type=click.Choice(hexboard_sizes),
              help='Override Hexboard size calculation (tiny=32, xsmall=64, small=108, medium=266, large=512, xlarge=1026)',
              show_default=True)
@click.option('--console-port', default='8443', type=click.IntRange(1,65535), help='OpenShift web console port',
              show_default=True)
@click.option('--api-port', default='8443', type=click.IntRange(1,65535), help='OpenShift API port',
              show_default=True)
@click.option('--deployment-type', default='openshift-enterprise', help='openshift deployment type',
              show_default=True)
@click.option('--default-password', default='openshift3',
              help='password for all users', show_default=True)

### Smoke test options
@click.option('--run-smoke-tests', is_flag=True, help='Run workshop smoke tests')
@click.option('--num-smoke-test-users', default=5, type=click.INT,
              help='Number of smoke test users', show_default=True)
@click.option('--run-only-smoke-tests', is_flag=True, help='Run only the workshop smoke tests')

### AWS/EC2 options
@click.option('--region', default='us-east-1', help='ec2 region',
              show_default=True)
@click.option('--ami', default='ami-10251c7a', help='ec2 ami',
              show_default=True)
@click.option('--master-instance-type', default='m4.large', help='ec2 instance type',
              show_default=True)
@click.option('--infra-instance-type', default='m4.large', help='ec2 instance type',
              show_default=True)
@click.option('--node-instance-type', default='m4.large', help='ec2 instance type',
              show_default=True)
@click.option('--keypair', default='default', help='ec2 keypair name',
              show_default=True)

### DNS options
@click.option('--r53-zone', help='route53 hosted zone (must be pre-configured)')
@click.option('--app-dns-prefix', default='apps', help='application dns prefix',
              show_default=True)

### Subscription and Software options
@click.option('--rhsm-user', help='Red Hat Subscription Management User')
@click.option('--rhsm-pass', help='Red Hat Subscription Management Password',
                hide_input=True,)
@click.option('--skip-subscription-management', is_flag=True,
              help='Skip subscription management steps')
@click.option('--use-certificate-repos', is_flag=True,
              help='Uses certificate-based yum repositories for the AOS content. Requires providing paths to local certificate key and pem files.')
@click.option('--certificate-file', help='Certificate file for the yum repository',
              show_default=True)
@click.option('--certificate-key', help='Certificate key for the yum repository',
              show_default=True)

### Miscellaneous options
@click.option('--no-confirm', is_flag=True,
              help='Skip confirmation prompt')
@click.option('--debug-playbook',
              help='Specify a path to a specific playbook to debug with all vars')
@click.option('--cleanup', is_flag=True,
              help='Deletes environment')
@click.help_option('--help', '-h')
@click.option('-v', '--verbose', count=True)

def launch_demo_env(num_nodes,
                    num_infra,
                    hexboard_size=None,
                    region=None,
                    ami=None,
                    no_confirm=False,
                    master_instance_type=None,
                    node_instance_type=None,
                    infra_instance_type=None,
                    keypair=None,
                    r53_zone=None,
                    cluster_id=None,
                    app_dns_prefix=None,
                    deployment_type=None,
                    console_port=443,
                    api_port=443,
                    rhsm_user=None,
                    rhsm_pass=None,
                    skip_subscription_management=False,
                    certificate_file=None,
                    certificate_key=None,
                    use_certificate_repos=False,
                    run_smoke_tests=False,
                    num_smoke_test_users=None,
                    run_only_smoke_tests=False,
                    default_password=None,
                    debug_playbook=None,
                    cleanup=False,
                    verbose=0):

  # Force num_masters = 3 because of an issue with API startup and ELB health checks and more
  num_masters = 3

  # If not running cleanup need to prompt for the R53 zone:
  if r53_zone is None: