Skip to content

Commit

Permalink
Merge pull request #139 from mhilton/011-support-juju-2
Browse files Browse the repository at this point in the history
support juju 2

Basic work to support operating with juju2 controllers.
  • Loading branch information
jujugui authored Jul 1, 2016
2 parents b5df982 + e7f938b commit b853069
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 62 deletions.
40 changes: 17 additions & 23 deletions cmd/jaas-model/modelcmd/add-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package modelcmd
import (
"github.com/juju/cmd"
"github.com/juju/juju/cmd/modelcmd"
"github.com/juju/juju/environs"
"github.com/juju/juju/jujuclient"
"github.com/juju/utils/keyvalues"
"gopkg.in/errgo.v1"
Expand All @@ -16,10 +17,10 @@ import (
type addControllerCommand struct {
commandBase

modelName string
modelPath entityPathValue
attributes map[string]string
public bool
controllerName string
controllerPath entityPathValue
attributes map[string]string
public bool
}

func newAddControllerCommand() cmd.Command {
Expand Down Expand Up @@ -60,16 +61,16 @@ func (c *addControllerCommand) Info() *cmd.Info {

func (c *addControllerCommand) SetFlags(f *gnuflag.FlagSet) {
c.commandBase.SetFlags(f)
f.StringVar(&c.modelName, "m", "", "model to add")
f.StringVar(&c.modelName, "model", "", "")
f.StringVar(&c.controllerName, "c", "", "controller to add")
f.StringVar(&c.controllerName, "controller", "", "")
f.BoolVar(&c.public, "public", false, "whether it will be part of the public pool of controllers")
}

func (c *addControllerCommand) Init(args []string) error {
if len(args) < 1 {
return errgo.Newf("got %d arguments, want 1", len(args))
}
if err := c.modelPath.Set(args[0]); err != nil {
if err := c.controllerPath.Set(args[0]); err != nil {
return errgo.Mask(err)
}
attrs, err := keyvalues.Parse(args[1:], false)
Expand All @@ -85,7 +86,8 @@ func (c *addControllerCommand) Run(ctxt *cmd.Context) error {
if err != nil {
return errgo.Mask(err)
}
info, err := getModelInfo(c.modelName)
logger.Debugf("client: %#v\n", client)
info, err := getControllerInfo(c.controllerName)
if err != nil {
return errgo.Mask(err)
}
Expand All @@ -98,9 +100,9 @@ func (c *addControllerCommand) Run(ctxt *cmd.Context) error {
hostnames = info.controller.UnresolvedAPIEndpoints
}

logger.Infof("adding controller, user %s, name %s", c.modelPath.EntityPath.User, c.modelPath.EntityPath.Name)
logger.Infof("adding controller, user %s, name %s", c.controllerPath.EntityPath.User, c.controllerPath.EntityPath.Name)
if err := client.AddController(&params.AddController{
EntityPath: c.modelPath.EntityPath,
EntityPath: c.controllerPath.EntityPath,
Info: params.ControllerInfo{
HostPorts: hostnames,
CACert: info.controller.CACert,
Expand All @@ -116,25 +118,17 @@ func (c *addControllerCommand) Run(ctxt *cmd.Context) error {
return nil
}

type modelInfo struct {
type controllerInfo struct {
model *jujuclient.ModelDetails
controller *jujuclient.ControllerDetails
account *jujuclient.AccountDetails
}

func getModelInfo(modelName string) (*modelInfo, error) {
func getControllerInfo(controllerName string) (*controllerInfo, error) {
store := jujuclient.NewFileClientStore()
var err error
var controllerName string
if modelName == "" {
modelName, err = modelcmd.GetCurrentModel(store)
if err != nil {
return nil, errgo.Mask(err)
}
}
controllerName, modelName = modelcmd.SplitModelName(modelName)
if controllerName == "" {
controllerName, err = modelcmd.ReadCurrentController()
controllerName, err = store.CurrentController()
if err != nil {
return nil, errgo.Mask(err)
}
Expand All @@ -144,8 +138,8 @@ func getModelInfo(modelName string) (*modelInfo, error) {
return nil, errgo.Mask(err)
}

var info modelInfo
info.model, err = store.ModelByName(controllerName, accountName, modelName)
var info controllerInfo
info.model, err = store.ModelByName(controllerName, accountName, environs.ControllerModelName)
if err != nil {
return nil, errgo.Mask(err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/jaas-model/modelcmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/juju/juju/cmd/modelcmd"
"github.com/juju/juju/jujuclient"
"github.com/juju/loggo"
"github.com/juju/names"
"gopkg.in/errgo.v1"
"gopkg.in/juju/names.v2"
"gopkg.in/macaroon-bakery.v1/httpbakery"
"launchpad.net/gnuflag"

Expand Down Expand Up @@ -95,6 +95,7 @@ func (c *commandBase) newClient(ctxt *cmd.Context) (*jemclient.Client, error) {
return nil, errgo.Mask(err)
}
bakeryClient.VisitWebPage = httpbakery.OpenWebBrowser
bakeryClient.WebPageVisitor = nil
return jemclient.New(jemclient.NewParams{
BaseURL: c.serverURL(),
Client: bakeryClient,
Expand Down
2 changes: 1 addition & 1 deletion cmd/jaas-model/modelcmd/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func (s *commonSuite) SetUpTest(c *gc.C) {
s.idmSrv.SetDefaultUser("testuser")

os.Setenv("JAAS_MODEL", s.httpSrv.URL)

}

// jemClient returns a new JEM client that will act as the given user.
Expand Down Expand Up @@ -178,6 +177,7 @@ func newAPIConnectionParams(
AccountDetails: accountDetails,
ModelUUID: modelUUID,
DialOpts: dialOpts,
OpenAPI: api.Open,
}, nil
}

Expand Down
33 changes: 18 additions & 15 deletions dependencies.tsv
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
github.com/bmizerany/pat git c068ca2f0aacee5ac3681d68e4d0a003b7d1fd2c 2016-02-17T10:32:42Z
github.com/coreos/go-systemd git 2d21675230a81a503f4363f4aa3490af06d52bb8 2015-01-26T19:09:17Z
github.com/coreos/go-systemd git 7b2428fec40033549c68f54e26e89e7ca9a9ce31 2016-02-02T21:14:25Z
github.com/dustin/go-humanize git 145fabdb1ab757076a70a886d092a3af27f66f4c 2014-12-28T07:11:48Z
github.com/godbus/dbus git 88765d85c0fdadcd98a54e30694fa4e4f5b51133 2015-01-22T18:02:51Z
github.com/godbus/dbus git 32c6cc29c14570de4cf6d7e7737d68fb2d01ad15 2016-05-06T22:25:50Z
github.com/golang/groupcache git 604ed5785183e59ae2789449d89e73f3a2a77987 2015-01-25T18:08:32Z
github.com/gorilla/schema git 08023a0215e7fc27a9aecd8b8c50913c40019478 2016-04-26T23:15:12Z
github.com/gorilla/websocket git 13e4d0621caa4d77fd9aa470ef6d7ab63d1a5e41 2015-09-23T22:29:30Z
github.com/juju/bundlechanges git a1fcaa2fc3b55305d064d16cb56bf87541efb8a4 2016-04-18T04:33:00Z
github.com/juju/cmd git ca63dd8ba13f8fbbbe16a917696a7ce68cc3dc0b 2016-03-31T03:26:51Z
github.com/juju/bundlechanges git 8d99dd2a94d7b4fd975a152238d0e19d0c4a6cf1 2016-06-15T07:19:43Z
github.com/juju/cmd git a11ae7a7436c133e799f025998cbbefd3f6eef7e 2016-06-01T03:55:01Z
github.com/juju/errors git 1b5e39b83d1835fa480e0c2ddefb040ee82d58b3 2015-09-16T12:56:42Z
github.com/juju/go4 git 40d72ab9641a2a8c36a9c46a51e28367115c8e59 2016-02-22T16:32:58Z
github.com/juju/gojsonpointer git afe8b77aa08f272b49e01b82de78510c11f61500 2015-02-04T19:46:29Z
Expand All @@ -14,21 +15,22 @@ github.com/juju/gojsonschema git e1ad140384f254c82f89450d9a7c8dd38a632838 2015-0
github.com/juju/gomaasapi git 5bd7212f416a2d801e4a39800b66e1ee4461c42e 2016-05-03T13:03:30Z
github.com/juju/httpprof git 14bf14c307672fd2456bdbf35d19cf0ccd3cf565 2014-12-17T16:00:36Z
github.com/juju/httprequest git 796aaafaf712f666df58d31a482c51233038bf9f 2016-05-03T15:03:27Z
github.com/juju/idmclient git 88f418ef8a208c7a807a3883cc87a95e6ca335d1 2016-05-13T10:03:09Z
github.com/juju/juju git 59fd1c2f244b7e789feccebe42b276b32fdd4277 2016-05-20T00:14:47Z
github.com/juju/idmclient git 3dda079a75cccb85083d4c3877e638f5d6ab79c2 2016-05-26T05:00:34Z
github.com/juju/juju git 894de5b4a1d3955f5edd79f19255e41c0ab23d9c 2016-06-30T14:53:07Z
github.com/juju/loggo git 8477fc936adf0e382d680310047ca27e128a309a 2015-05-27T03:58:39Z
github.com/juju/mgoutil git 5f725bbe1f9842b097129570e79441be24012e9c 2016-05-20T10:19:24Z
github.com/juju/mutex git 59c26ee163447c5c57f63ff71610d433862013de 2016-06-17T01:09:07Z
github.com/juju/names git 8a0aa0963bbacdc790914892e9ff942e94d6f795 2016-03-30T15:05:33Z
github.com/juju/persistent-cookiejar git e710b897c13ca52828ca2fc9769465186fd6d15c 2016-03-31T17:12:27Z
github.com/juju/replicaset git fb7294cf57a1e2f08a57691f1246d129a87ab7e8 2015-05-08T02:21:43Z
github.com/juju/retry git 62c62032529169c7ec02fa48f93349604c345e1f 2015-10-29T02:48:21Z
github.com/juju/romulus git 50df1d58b502e363e2318164d24d7c67e7501370 2016-05-02T14:09:41Z
github.com/juju/romulus git 6bf2184bf0e9fe3e74d317e81a9a49a4cdcdf20b 2016-06-20T20:29:55Z
github.com/juju/schema git 075de04f9b7d7580d60a1e12a0b3f50bb18e6998 2016-04-20T04:42:03Z
github.com/juju/testing git b9cfe07211e464f16d78ca9304c503d636b8eefa 2016-05-19T00:49:35Z
github.com/juju/testing git ccf839b5a07a7a05009f8fa3ec41cd05fb2e0b08 2016-06-24T20:35:24Z
github.com/juju/txn git 99ec629d0066a4d73c54d8e021a7fc1dc07df614 2015-06-09T16:58:27Z
github.com/juju/usso git 5b79b358f4bb6735c1b00f6ad051c07c1a1a03e9 2016-04-18T12:10:39Z
github.com/juju/utils git d5423ca3ec0b0cc8ccf093fab1365b1c9f93eb2d 2016-05-02T18:15:00Z
github.com/juju/version git ef897ad7f130870348ce306f61332f5335355063 2015-11-27T20:34:00Z
github.com/juju/usso git 68a59c96c178fbbad65926e7f93db50a2cd14f33 2016-04-01T10:44:24Z
github.com/juju/utils git ffea6ead0c374583e876c8357c9db6e98bc71476 2016-05-26T02:52:51Z
github.com/juju/version git 4ae6172c00626779a5a462c3e3d22fc0e889431a 2016-06-03T19:49:58Z
github.com/juju/webbrowser git 54b8c57083b4afb7dc75da7f13e2967b2606a507 2016-03-09T14:36:29Z
github.com/julienschmidt/httprouter git 77a895ad01ebc98a4dc95d8355bc825ce80a56f6 2015-10-13T22:55:20Z
github.com/lxc/lxd git ba236f15fd862ffe588ed9349ea8bf0ff87f68d4 2016-05-09T16:40:25Z
Expand All @@ -41,14 +43,15 @@ gopkg.in/errgo.v1 git 66cb46252b94c1f3d65646f54ee8043ab38d766c 2015-10-07T15:31:
gopkg.in/goose.v1 git 495e6fa2ab89bc5ed2c8e1bbcbc4c9e4a3c97d37 2016-03-17T17:25:46Z
gopkg.in/ini.v1 git 776aa739ce9373377cd16f526cdf06cb4c89b40f 2016-02-22T23:24:41Z
gopkg.in/juju/blobstore.v2 git 51fa6e26128d74e445c72d3a91af555151cc3654 2016-01-25T02:37:03Z
gopkg.in/juju/charm.v6-unstable git 9857751ba31e81773bbb42557e85054d6b4de4dd 2016-04-27T02:42:06Z
gopkg.in/juju/charmrepo.v2-unstable git c42c5eeab84ddfc23fe5d125f13d411cffef65ab 2016-05-17T05:22:41Z
gopkg.in/juju/charm.v6-unstable git 8796be6021c9ecb20630950498ec515f7dd24575 2016-06-09T14:28:26Z
gopkg.in/juju/charmrepo.v2-unstable git 6e6733987fb03100f30e494cc1134351fe4a593b 2016-05-30T23:07:41Z
gopkg.in/juju/environschema.v1 git 7359fc7857abe2b11b5b3e23811a9c64cb6b01e0 2015-11-04T11:58:10Z
gopkg.in/juju/names.v2 git 84889e67a1a20ee2b33dcb98a126f9b240330c89 2016-06-01T09:30:20Z
gopkg.in/macaroon-bakery.v1 git b097c9d99b2537efaf54492e08f7e148f956ba51 2016-05-24T09:38:11Z
gopkg.in/macaroon.v1 git ab3940c6c16510a850e1c2dd628b919f0f3f1464 2015-01-21T11:42:31Z
gopkg.in/mgo.v2 git b6e2fa371e64216a45e61072a96d4e3859f169da 2016-03-16T05:49:52Z
gopkg.in/mgo.v2 git 4d04138ffef2791c479c0c8bbffc30b34081b8d9 2015-10-26T16:34:53Z
gopkg.in/natefinch/lumberjack.v2 git 514cbda263a734ae8caac038dadf05f8f3f9f738 2016-01-25T11:17:49Z
gopkg.in/natefinch/npipe.v2 git e562d4ae5c2f838f9e7e406f7d9890d5b02467a9 2014-08-11T16:19:00Z
gopkg.in/natefinch/npipe.v2 git c1b8fa8bdccecb0b8db834ee0b92fdbcfa606dd6 2016-06-21T03:49:01Z
gopkg.in/tomb.v2 git 14b3d72120e8d10ea6e6b7f87f7175734b1faab8 2014-06-26T14:46:23Z
gopkg.in/yaml.v1 git 9f9df34309c04878acc86042b16630b0f696e1de 2014-09-24T16:16:07Z
gopkg.in/yaml.v2 git a83829b6f1293c91addabc89d0571c246397bbf4 2016-03-01T20:40:22Z
Expand Down
2 changes: 1 addition & 1 deletion internal/jem/jem.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/juju/juju/api"
"github.com/juju/loggo"
"github.com/juju/mgoutil"
"github.com/juju/names"
"github.com/juju/utils"
"gopkg.in/errgo.v1"
"gopkg.in/juju/names.v2"
"gopkg.in/macaroon-bakery.v1/bakery"
"gopkg.in/macaroon-bakery.v1/bakery/mgostorage"
"gopkg.in/mgo.v2"
Expand Down
2 changes: 1 addition & 1 deletion internal/monitor/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (w *watcherState) addDelta(d multiwatcher.Delta) error {
}
case *multiwatcher.UnitInfo:
w.adjustCount(&w.stats.UnitCount, d)
case *multiwatcher.ServiceInfo:
case *multiwatcher.ApplicationInfo:
w.adjustCount(&w.stats.ServiceCount, d)
case *multiwatcher.MachineInfo:
// TODO for top level machines, increment instance count?
Expand Down
8 changes: 4 additions & 4 deletions internal/monitor/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ func (s *internalSuite) TestLeaseUpdaterWhenControllerRemoved(c *gc.C) {
func (s *internalSuite) TestWatcher(c *gc.C) {
// Add some entities to the admin model.
f := factory.NewFactory(s.State)
svc := f.MakeService(c, &factory.ServiceParams{
svc := f.MakeApplication(c, &factory.ApplicationParams{
Name: "wordpress",
})
f.MakeUnit(c, &factory.UnitParams{
Service: svc,
Application: svc,
})
f.MakeUnit(c, &factory.UnitParams{
Service: svc,
Application: svc,
})
modelSt := f.MakeModel(c, &factory.ModelParams{
Name: "jem-somemodel",
Expand Down Expand Up @@ -231,7 +231,7 @@ func (s *internalSuite) TestWatcher(c *gc.C) {
s.assertModelLife(c, modelPath, "alive")

// Add another service and check that the service count is maintained.
f.MakeService(c, &factory.ServiceParams{
f.MakeApplication(c, &factory.ApplicationParams{
Name: "mysql",
})

Expand Down
4 changes: 2 additions & 2 deletions internal/monitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *monitorSuite) TestMonitorWithBrokenMongoConnection(c *gc.C) {
proxy.CloseConns()

f := factory.NewFactory(s.State)
f.MakeService(c, &factory.ServiceParams{
f.MakeApplication(c, &factory.ApplicationParams{
Name: "wordpress",
})

Expand Down Expand Up @@ -150,7 +150,7 @@ func (s *monitorSuite) TestMonitorWithBrokenJujuAPIConnection(c *gc.C) {
proxy.CloseConns()

f := factory.NewFactory(s.State)
f.MakeService(c, &factory.ServiceParams{
f.MakeApplication(c, &factory.ApplicationParams{
Name: "wordpress",
})

Expand Down
Loading

0 comments on commit b853069

Please sign in to comment.