~gz/pyjuju/0.6_test_lsbrelease_backport

« back to all changes in this revision

Viewing changes to juju/providers/local/__init__.py

  • Committer: Clint Byrum
  • Date: 2012-10-06 14:38:12 UTC
  • mfrom: (486.4.39 local-cloud-img)
  • Revision ID: clint@fewbar.com-20121006143812-id2qq4i2ui75yy8h
Refactor local provider to use Cloud Images [r=hazmat][f=915520,930430,996358,997677,1037803,1038927]

- Boots a full container with cloud-init each time, No more template container + clone
- Removes upstart job for storage server. Also fixes machine-agent to be killable on destroy-env
- Uses LXC's default networking rather than libvirt. Removes dependency on libvirt entirely.
- Regresses HTTPS apt support for local provider because cloud-init doesn't have a way to make the
distinction.
- Regresses performance for the case where the download is cached. rsync'ing from the debootstrap
is a little faster than extracting the tar.gz. Also we now do a full apt-get upgrade, so all updates
have to be unpacked/configured.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
log = logging.getLogger("juju.local-dev")
27
27
 
28
28
REQUIRED_PACKAGES = ["zookeeper",
29
 
                     "libvirt-bin",
30
29
                     "lxc",
31
30
                     "apt-cacher-ng"]
32
31
 
54
53
    def provider_type(self):
55
54
        return "local"
56
55
 
 
56
    def _get_storage_server(self, ip='127.0.0.1'):
 
57
        return StorageServer(
 
58
            self._qualified_name,
 
59
            storage_dir=os.path.join(self._directory, "files"),
 
60
            host=ip,
 
61
            port=get_open_port(ip),
 
62
            logfile=os.path.join(self._directory, "storage-server.log"))
 
63
 
57
64
    @inlineCallbacks
58
65
    def bootstrap(self, constraints):
59
66
        """Bootstrap a local development environment.
82
89
 
83
90
        # Start networking, and get an open port.
84
91
        log.info("Starting networking...")
85
 
        net = Network("default", subnet=122)
 
92
        net = Network()
86
93
 
87
94
        # Start is a noop if its already started, which it is by default,
88
 
        # per libvirt-bin package installation
 
95
        # since lxc has it started by default
89
96
        yield net.start()
90
97
        net_attributes = yield net.get_attributes()
91
 
        port = get_open_port(net_attributes["ip"]["address"])
 
98
        port = get_open_port(net_attributes["ip"])
92
99
 
93
100
        # Get/create directory for zookeeper and files
94
101
        zookeeper_dir = os.path.join(self._directory, "zookeeper")
104
111
            zookeeper_user = "zookeeper"
105
112
        zookeeper = Zookeeper(zookeeper_dir,
106
113
                              port=port,
107
 
                              host=net_attributes["ip"]["address"],
 
114
                              host=net_attributes["ip"],
108
115
                              user=zookeeper_user,
109
116
                              group=zookeeper_user)
110
117
 
112
119
 
113
120
        # Starting provider storage server
114
121
        log.info("Starting storage server...")
115
 
        storage_server = StorageServer(
116
 
            self._qualified_name,
117
 
            storage_dir=os.path.join(self._directory, "files"),
118
 
            host=net_attributes["ip"]["address"],
119
 
            port=get_open_port(net_attributes["ip"]["address"]),
120
 
            logfile=os.path.join(self._directory, "storage-server.log"))
 
122
        storage_server = self._get_storage_server(net_attributes["ip"])
121
123
        yield storage_server.start()
122
124
 
123
125
        # Save the zookeeper start to provider storage.
172
174
 
173
175
        # Stop the machine agent
174
176
        log.debug("Stopping machine agent...")
175
 
        agent = ManagedMachineAgent(self._qualified_name)
 
177
        agent = ManagedMachineAgent(self._qualified_name,
 
178
            juju_directory=self._directory)
176
179
        yield agent.stop()
177
180
 
178
181
        # Stop the storage server
179
182
        log.debug("Stopping storage server...")
180
 
        storage_server = StorageServer(self._qualified_name)
 
183
        storage_server = self._get_storage_server()
181
184
        yield storage_server.stop()
182
185
 
183
186
        # Stop zookeeper
189
192
        # Clean out local state
190
193
        yield self.save_state(False)
191
194
 
192
 
        # Don't stop the network since we're using the default libvirt
 
195
        # Don't stop the network since we're using the default from lxc
193
196
        log.debug("Environment destroyed.")
194
197
 
195
198
    @inlineCallbacks