Example #1
0
// Destroy destroys an Elastic Load Balancing instance from AWS. It matches the
// name of the given app.
func (m *ELBManager) Destroy(app provision.Named) error {
	_, err := m.elb().DeleteLoadBalancer(app.GetName())
	if err != nil {
		return err
	}
	return m.collection().Remove(bson.M{"name": app.GetName()})
}
Example #2
0
// Addr returns the dns-name of a load balancer, which is also the DNS name of
// the app.
func (m *ELBManager) Addr(app provision.Named) (string, error) {
	var lb loadBalancer
	conn, collection := m.collection()
	defer conn.Close()
	err := collection.Find(bson.M{"name": app.GetName()}).One(&lb)
	return lb.DNSName, err
}
Example #3
0
// Deregister removes EC2 instances (represented as units) from a load
// balancer.
func (m *ELBManager) Deregister(app provision.Named, units ...provision.Unit) error {
	ids := make([]string, len(units))
	for i, u := range units {
		ids[i] = u.InstanceId
	}
	_, err := m.elb().DeregisterInstancesFromLoadBalancer(ids, app.GetName())
	return err
}
Example #4
0
// Create creates a new Elastic Load Balancing instance for the given app. The
// name of the instance will be the same as the name of the app.
func (m *ELBManager) Create(app provision.Named) error {
	options := elb.CreateLoadBalancer{
		Name: app.GetName(),
		Listeners: []elb.Listener{
			{
				InstancePort:     80,
				InstanceProtocol: "HTTP",
				LoadBalancerPort: 80,
				Protocol:         "HTTP",
			},
		},
	}
	var err error
	if m.vpc() {
		options.Subnets, err = config.GetList("juju:elb-vpc-subnets")
		if err != nil {
			log.Fatal(err)
		}
		options.SecurityGroups, err = config.GetList("juju:elb-vpc-secgroups")
		if err != nil {
			log.Fatal(err)
		}
		options.Scheme = "internal"
	} else {
		options.AvailZones, err = config.GetList("juju:elb-avail-zones")
		if err != nil {
			log.Fatal(err)
		}
	}
	resp, err := m.elb().CreateLoadBalancer(&options)
	if err != nil {
		return err
	}
	lb := loadBalancer{Name: app.GetName(), DNSName: resp.DNSName}
	conn, collection := m.collection()
	defer conn.Close()
	return collection.Insert(lb)
}