~hazmat/+junk/juju-autoscale

« back to all changes in this revision

Viewing changes to connect.go

  • Committer: Kapil Thangavelu
  • Date: 2013-11-14 19:21:00 UTC
  • Revision ID: kapil.foss@gmail.com-20131114192100-1578y5kv9dtrfn62
juju autoscale wip

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
package main
 
3
 
 
4
import (
 
5
        "io/ioutil"
 
6
        "launchpad.net/gnuflag"
 
7
        "launchpad.net/loggo"
 
8
        "launchpad.net/juju-core/juju"
 
9
        "fmt"
 
10
        "launchpad.net/juju-core/state"
 
11
)
 
12
 
 
13
 
 
14
var log = loggo.GetLogger("")
 
15
 
 
16
 
 
17
var (
 
18
        api_address  = gnuflag.String("api_address", "", "API Server Address")
 
19
        api_user     = gnuflag.String("api_user", "", "API User")
 
20
        cert_file    = gnuflag.String(
 
21
                "ca_file", "", "Certificate Authority")
 
22
        api_password = gnuflag.String("api_password", "", "API Password")
 
23
        service_name = gnuflag.String("service", "", "Service")
 
24
 
 
25
 
 
26
)
 
27
 
 
28
 
 
29
func main () {
 
30
        err := loggo.ConfigureLoggers("<root>=TRACE")
 
31
        gnuflag.Parse(true)
 
32
 
 
33
        addrs := []string{*api_address}
 
34
 
 
35
        cert, _ := ioutil.ReadFile(*cert_file)
 
36
        info := &state.Info{
 
37
                addrs,
 
38
                cert,
 
39
                *api_user,
 
40
                *api_password}
 
41
 
 
42
        opts := state.DefaultDialOpts()
 
43
        log.Infof("Connecting to state server %s %s %s",
 
44
                info.Addrs, info.Tag, info.Password)
 
45
        st, err := state.Open(info, opts)
 
46
        
 
47
        if err != nil {
 
48
                fmt.Printf("Error %s", err)
 
49
        }
 
50
 
 
51
        conn, _ := juju.NewConnFromState(st)
 
52
 
 
53
        service, err := conn.State.Service(service_name)
 
54
        if err != nil {
 
55
                info.Errorf("Service %s does not exist", service_name)
 
56
        }
 
57
 
 
58
        print(conn)
 
59
        
 
60
        params := state.AddMachineParams{
 
61
                ParentId:      "",
 
62
                ContainerType: "",
 
63
                Series:        "precise",
 
64
                Constraints:   c.Constraints,
 
65
                Jobs:          []state.MachineJob{state.JobHostUnits},
 
66
        }
 
67
        st.AddMachineWithConstraints(params)
 
68
 
 
69
        
 
70
}
 
 
b'\\ No newline at end of file'