def opsmgr_launch_instance(stack, version=None, verbose=False): version = cloudformation.get_tag(stack, "pcf-version") if version is None else version image = opsmgr_select_image(version, verbose) if verbose: print "Launching Ops Manager instance from", image["ImageId"] + ":", image.get("Description", "-") command = [ 'ec2', 'run-instances', '--image-id', image["ImageId"], '--instance-type', 'm3.large', '--subnet-id', cloudformation.get_output(stack, "PcfPublicSubnetId"), '--associate-public-ip-address', '--block-device-mapping', 'DeviceName=/dev/sda1,Ebs={VolumeSize=100}', '--security-group-ids', cloudformation.get_output(stack, "PcfOpsManagerSecurityGroupId"), '--key-name', config.get('aws', 'nat-key-pair') ] instance = json.loads(aws.aws_cli_verbose(command))["Instances"][0] tags = [ { "Key": "Name", "Value": "Ops Manager" }, { "Key": "Stack", "Value": stack["StackName"] }, { "Key": "Image", "Value": image.get("Description", "-") } ] command = [ 'ec2', 'create-tags', '--resources', instance["InstanceId"], '--tags', json.dumps(tags) ] aws.aws_cli_verbose(command) return instance
def launch_cmd(argv): cli.exit_with_usage(argv) if len(argv) < 2 else None stack_name = argv[1] version = argv[2] if len(argv) > 2 else "" stack = cloudformation.select_stack(stack_name) instance = opsmgr_launch_instance(stack, version, verbose=True) print "Waiting for Ops Manager to start ", opsmgr_wait(stack, verbose=True) print "Setting up initial Admin user" opsmgr_setup(stack) print "Configuring Ops Manager Director" bosh.bosh_config(stack) stack_section = "stack-" + stack["StackName"] password = config.get(stack_section, "opsmgr-password") opsmgr_dns = opsmgr_hostname(stack) pcfelb_dns = cloudformation.get_output(stack, "PcfElbDnsName") sshelb_dns = cloudformation.get_output(stack, "PcfElbSshDnsName") app_domain = config.get("cf", "apps-domain", stack=stack_name) sys_domain = config.get("cf", "system-domain", stack=stack_name) print print "Ops Manager started at", opsmgr_url(stack) print "Admin username is admin, password is", password print print "Before proceeding to install Elastic runtime, you must create" print "the following records through your DNS provider:" print print " CNAME", "opsmgr." + sys_domain, opsmgr_dns print " CNAME", "*." + app_domain, pcfelb_dns if app_domain != sys_domain: print " CNAME", "*." + sys_domain, pcfelb_dns if sshelb_dns is not None: print " CNAME", "ssh." + sys_domain, sshelb_dns print print "Failure to do so will lead to install failures later."
def opsmgr_find_instances(stack=None): filters = [ { "Name": "tag:Name", "Values": [ "Ops Manager" ] }, { "Name": "tag-key", "Values": [ "Stack" ] }, { "Name": "instance-state-name", "Values": [ "pending", "running"] } ] if stack is not None: filters.extend([ { "Name": "subnet-id", "Values": [ cloudformation.get_output(stack, "PcfPublicSubnetId") ] } ]) command = [ 'ec2', 'describe-instances', '--filters', json.dumps(filters) ] reservations = json.loads(aws.aws_cli_verbose(command))["Reservations"] instances = [] for r in reservations: instances += r["Instances"] return instances
def output(stack, key): return cloudformation.get_output(stack, key)
def first_of(stack, keys): for key in keys: output = cloudformation.get_output(stack, key) if output is not None: return output return None