~hazmat/pyjuju/rapi-rollup

« back to all changes in this revision

Viewing changes to juju/agents/api.py

  • Committer: Kapil Thangavelu
  • Date: 2012-12-17 22:14:37 UTC
  • mfrom: (616.1.2 rapi-login)
  • Revision ID: kapil@canonical.com-20121217221437-lhy4eck58wx3sf5n
merge rapi-login

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
from juju.errors import JujuError
12
12
from juju.lib.websockets import WebSocketsResource
13
13
from juju.rapi.transport.ws import WebSocketAPIFactory
 
14
from juju.state.auth import make_ace
14
15
 
15
16
from twisted.web.static import Data
16
17
from twisted.web.server import Site
32
33
        log.debug("Received environment data.")
33
34
        root = Data("Juju API Server\n", "text/plain")
34
35
        self.ws_factory = WebSocketAPIFactory(
35
 
                self.config['zookeeper_servers'], self.provider)
 
36
            self.config['zookeeper_servers'], self.provider)
36
37
        yield self.ws_factory.startFactory()
37
38
 
38
39
        root.putChild('ws', WebSocketsResource(self.ws_factory))
79
80
                environment = yield watch_d
80
81
            returnValue(environment)
81
82
 
 
83
        # Lazy initialize login nodes if not present.
 
84
        yield self._initialize_login()
 
85
 
82
86
        config = EnvironmentsConfig()
83
87
        config.parse(environment_data)
84
88
        returnValue(config.get_default())
85
89
 
 
90
    @inlineCallbacks
 
91
    def _initialize_login(self):
 
92
        children = yield self.client.get_children("/")
 
93
        if "login" in children:
 
94
            return
 
95
 
 
96
        acls, stat = yield self.client.get_acl("/initialized")
 
97
        admin_acl = None
 
98
 
 
99
        for a in acls:
 
100
            if a['id'].startswith('admin'):
 
101
                admin_acl = a
 
102
                break
 
103
 
 
104
        yield self.client.create(
 
105
            "/login", acls=[make_ace(admin_acl['id'], all=True)])
 
106
 
86
107
    def configure(self, options):
87
108
        super(APIEndpointAgent, self).configure(options)
88
109
        if not options.get("port"):