Esempio n. 1
0
File: builder.go Progetto: mmb/boosh
func (builder *Builder) buildElasticIPs(former cloudformer.CloudFormer) error {
	for _, x := range builder.spec.ElasticIPs {
		former.ElasticIP(x.Name).Domain("vpc")
	}

	return nil
}
Esempio n. 2
0
File: builder.go Progetto: mmb/boosh
func (builder *Builder) buildSubnets(former cloudformer.CloudFormer) error {
	natAMI, found := NAT_AMIS[builder.region]
	if !found {
		return fmt.Errorf("unknown NAT image for region: %s", builder.region)
	}

	for _, x := range builder.spec.Subnets {
		if x.NAT == nil {
			continue
		}

		if x.RouteTable != nil && x.RouteTable.Instance != nil {
			continue
		}

		subnet := builder.vpc.Subnet(x.Name)
		subnet.Network(cloudformer.CIDR(x.CIDR))
		subnet.AvailabilityZone(x.AvailabilityZone)

		if x.RouteTable != nil {
			if x.RouteTable.InternetGateway != nil {
				gateway, found := builder.gateways[*x.RouteTable.InternetGateway]
				if !found {
					return fmt.Errorf("unknown gateway: %s", *x.RouteTable.InternetGateway)
				}

				subnet.RouteTable().InternetGateway(gateway)
			}
		}

		nat := subnet.Instance(x.NAT.Name)
		nat.Type(x.NAT.InstanceType)
		nat.PrivateIP(cloudformer.IP(x.NAT.IP))
		nat.KeyPair(x.NAT.KeyPairName)
		nat.Image(natAMI)
		nat.SourceDestCheck(false)

		securityGroup, found := builder.securityGroups[x.NAT.SecurityGroup]
		if !found {
			return fmt.Errorf("unknown security group: %s", x.NAT.SecurityGroup)
		}

		nat.SecurityGroup(securityGroup)

		ip := former.ElasticIP("NAT")
		ip.Domain("vpc")
		ip.AttachTo(nat)

		builder.instances[x.NAT.Name] = nat
		builder.subnets[x.Name] = subnet
	}

	for _, x := range builder.spec.Subnets {
		if x.NAT != nil {
			continue
		}

		subnet := builder.vpc.Subnet(x.Name)
		subnet.Network(cloudformer.CIDR(x.CIDR))
		subnet.AvailabilityZone(x.AvailabilityZone)

		if x.RouteTable != nil {
			if x.RouteTable.Instance != nil {
				instance, found := builder.instances[*x.RouteTable.Instance]
				if !found {
					return fmt.Errorf("unknown instance: %s", *x.RouteTable.Instance)
				}

				subnet.RouteTable().Instance(instance)
			}

			if x.RouteTable.InternetGateway != nil {
				gateway, found := builder.gateways[*x.RouteTable.InternetGateway]
				if !found {
					return fmt.Errorf("unknown gateway: %s", *x.RouteTable.InternetGateway)
				}

				subnet.RouteTable().InternetGateway(gateway)
			}
		}

		builder.subnets[x.Name] = subnet
	}

	return nil
}