~ubuntu-branches/ubuntu/lucid/landscape-client/lucid-updates

« back to all changes in this revision

Viewing changes to landscape/broker/registration.py

  • Committer: Package Import Robot
  • Author(s): Andreas Hasenack
  • Date: 2012-04-10 14:28:48 UTC
  • mfrom: (1.1.27)
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: package-import@ubuntu.com-20120410142848-7xsy4g2xii7y7ntc
ImportĀ upstreamĀ versionĀ 12.04.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    @ivar account_name: See L{BrokerConfiguration}.
53
53
    @ivar registration_password: See L{BrokerConfiguration}.
54
54
    @ivar tags: See L{BrokerConfiguration}
 
55
 
 
56
    @param config: A L{BrokerConfiguration} object, used to set the
 
57
        C{computer_title}, C{account_name} and C{registration_password}
 
58
        instance variables.
55
59
    """
56
60
 
57
61
    secure_id = persist_property("secure-id")
62
66
    tags = config_property("tags")
63
67
 
64
68
    def __init__(self, config, persist):
65
 
        """
66
 
        @param config: A L{BrokerConfiguration} object, used to set the
67
 
            C{computer_title}, C{account_name} and C{registration_password}
68
 
            instance variables.
69
 
        """
70
69
        self._config = config
71
70
        self._persist = persist.root_at("registration")
72
71
 
105
104
        if self._config.cloud:
106
105
            return bool(not id.secure_id
107
106
                        and self._message_store.accepts("register-cloud-vm"))
 
107
        elif self._config.provisioning_otp:
 
108
            return (not id.secure_id) and\
 
109
                self._message_store.accepts("register-provisioned-machine")
108
110
        return bool(not id.secure_id and id.computer_title and id.account_name
109
111
                    and self._message_store.accepts("register"))
110
112
 
146
148
                "/meta-data/local-hostname",
147
149
                "/meta-data/public-hostname",
148
150
                "/meta-data/ami-launch-index",
149
 
                "/meta-data/kernel-id",
150
 
                "/meta-data/ami-id"]
 
151
                "/meta-data/ami-id",
 
152
                "/meta-data/local-ipv4",
 
153
                "/meta-data/public-ipv4"]
151
154
            # We're not using a DeferredList here because we want to keep the
152
155
            # number of connections to the backend minimal. See lp:567515.
153
156
            for path in paths:
158
161
                lambda ignore: self._fetch_async(
159
162
                    EC2_API + "/meta-data/ramdisk-id").addErrback(log_failure))
160
163
            deferred.addCallback(ec2_data.append)
 
164
            # And same for kernel
 
165
            deferred.addCallback(
 
166
                lambda ignore: self._fetch_async(
 
167
                    EC2_API + "/meta-data/kernel-id").addErrback(log_failure))
 
168
            deferred.addCallback(ec2_data.append)
161
169
 
162
170
            def record_data(ignore):
163
171
                """Record the instance data returned by the EC2 API."""
164
172
                (raw_user_data, instance_key, reservation_key,
165
173
                 local_hostname, public_hostname, launch_index,
166
 
                 kernel_key, ami_key, ramdisk_key) = ec2_data
 
174
                 ami_key, local_ip, public_ip, ramdisk_key,
 
175
                 kernel_key) = ec2_data
167
176
                self._ec2_data = {
168
177
                    "instance_key": instance_key,
169
178
                    "reservation_key": reservation_key,
172
181
                    "launch_index": launch_index,
173
182
                    "kernel_key": kernel_key,
174
183
                    "ramdisk_key": ramdisk_key,
175
 
                    "image_key": ami_key}
 
184
                    "image_key": ami_key,
 
185
                    "public_ipv4": public_ip,
 
186
                    "local_ipv4": local_ip}
176
187
                for k, v in self._ec2_data.items():
177
 
                    if v is None and k == "ramdisk_key":
 
188
                    if v is None and k in ("ramdisk_key", "kernel_key"):
178
189
                        continue
179
190
                    self._ec2_data[k] = v.decode("utf-8")
180
191
                self._ec2_data["launch_index"] = int(
275
286
                with_word = ["without", "with"][bool(id.registration_password)]
276
287
                with_tags = ["", u"and tags %s " % tags][bool(tags)]
277
288
                logging.info(u"Queueing message to register with account %r %s"
278
 
                              "%s a password." % (id.account_name, with_tags,
279
 
                              with_word))
 
289
                             "%s a password." % (id.account_name, with_tags,
 
290
                                                 with_word))
280
291
                message = {"type": "register",
281
292
                           "computer_title": id.computer_title,
282
293
                           "account_name": id.account_name,
285
296
                           "tags": tags,
286
297
                           "vm-info": get_vm_info()}
287
298
                self._exchange.send(message)
 
299
            elif self._config.provisioning_otp:
 
300
                logging.info(u"Queueing message to register with OTP as a"
 
301
                             u" newly provisioned machine.")
 
302
                message = {"type": "register-provisioned-machine",
 
303
                           "otp": self._config.provisioning_otp}
 
304
                self._exchange.send(message)
288
305
            else:
289
306
                self._reactor.fire("registration-failed")
290
307