~ubuntu-branches/ubuntu/trusty/heat/trusty-security

« back to all changes in this revision

Viewing changes to heat/engine/resources/server.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-10-03 09:43:04 UTC
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: package-import@ubuntu.com-20131003094304-zhhr2brapzlpvjmm
Tags: upstream-2013.2~rc1
ImportĀ upstreamĀ versionĀ 2013.2~rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
            'Description': _('User data script to be executed by cloud-init')},
128
128
        'reservation_id': {
129
129
            'Type': 'String',
130
 
            'Description': _('A UUID for the set of servers being requested'),
131
 
            'Implemented': False},
 
130
            'Description': _('A UUID for the set of servers being requested')
 
131
        },
132
132
        'config_drive': {
133
133
            'Type': 'String',
134
134
            'Description': _('value for config drive either boolean, or '
135
 
                             'volume-id'),
136
 
            'Implemented': False},
 
135
                             'volume-id')
 
136
        },
137
137
        # diskConfig translates to API attribute OS-DCF:diskConfig
138
138
        # hence the camel case instead of underscore to separate the words
139
139
        'diskConfig': {
149
149
                       'the API'),
150
150
        'networks': _('A dict of assigned network addresses of the form: '
151
151
                      '{"public": [ip1, ip2...], "private": [ip3, ip4]}'),
152
 
        'first_private_address': _('Convenience attribute to fetch the first '
153
 
                                   'assigned private network address, or an '
154
 
                                   'empty string if nothing has been assigned '
155
 
                                   'at this time'),
156
 
        'first_public_address': _('Convenience attribute to fetch the first '
157
 
                                  'assigned public network address, or an '
158
 
                                  'empty string if nothing has been assigned '
159
 
                                  'at this time'),
 
152
        'first_address': _('Convenience attribute to fetch the first '
 
153
                           'assigned network address, or an '
 
154
                           'empty string if nothing has been assigned '
 
155
                           'at this time. Result may not be predictable '
 
156
                           'if the server has addresses from more than one '
 
157
                           'network.'),
160
158
        'instance_name': _('AWS compatible instance name'),
161
159
        'accessIPv4': _('The manually assigned alternative public IPv4 '
162
160
                        'address of the server'),
176
174
            self.mime_string = nova_utils.build_userdata(self, userdata)
177
175
        return self.mime_string
178
176
 
 
177
    def physical_resource_name(self):
 
178
        name = self.properties.get('name')
 
179
        if name:
 
180
            return name
 
181
 
 
182
        return super(Server, self).physical_resource_name()
 
183
 
179
184
    def handle_create(self):
180
185
        security_groups = self.properties.get('security_groups', [])
181
186
        userdata = self.properties.get('user_data', '')
267
272
            if (mapping.get('volume_size') or
268
273
                    mapping.get('delete_on_termination')):
269
274
 
270
 
                mapping_parts.append(mapping.get('volume_size', 0))
 
275
                mapping_parts.append(mapping.get('volume_size', '0'))
271
276
            if mapping.get('delete_on_termination'):
272
 
                mapping_parts.append(mapping.get('delete_on_termination'))
273
 
            bdm_dict[mapping.get('device_name')] = mapping_parts
 
277
                mapping_parts.append(str(mapping.get('delete_on_termination')))
 
278
            bdm_dict[mapping.get('device_name')] = ':'.join(mapping_parts)
274
279
 
275
280
        return bdm_dict
276
281
 
293
298
        return nics
294
299
 
295
300
    def _resolve_attribute(self, name):
 
301
        if name == 'first_address':
 
302
            return nova_utils.server_to_ipaddress(
 
303
                self.nova(), self.resource_id) or ''
296
304
        server = self.nova().servers.get(self.resource_id)
297
305
        if name == 'addresses':
298
306
            return server.addresses
299
307
        if name == 'networks':
300
308
            return server.networks
301
 
        if name == 'first_private_address':
302
 
            private = server.networks.get('private', [])
303
 
            if len(private) > 0:
304
 
                return private[0]
305
 
            return ''
306
 
        if name == 'first_public_address':
307
 
            public = server.networks.get('public', [])
308
 
            if len(public) > 0:
309
 
                return public[0]
310
 
            return ''
311
309
        if name == 'instance_name':
312
310
            return server._info.get('OS-EXT-SRV-ATTR:instance_name')
313
311
        if name == 'accessIPv4':
360
358
        if key_name:
361
359
            nova_utils.get_keypair(self.nova(), key_name)
362
360
 
 
361
        # either volume_id or snapshot_id needs to be specified, but not both
 
362
        # for block device mapping.
 
363
        bdm = self.properties.get('block_device_mapping') or []
 
364
        bootable_vol = False
 
365
        for mapping in bdm:
 
366
            if mapping['device_name'] == 'vda':
 
367
                    bootable_vol = True
 
368
 
 
369
            if mapping.get('volume_id') and mapping.get('snapshot_id'):
 
370
                raise exception.ResourcePropertyConflict('volume_id',
 
371
                                                         'snapshot_id')
 
372
            if not mapping.get('volume_id') and not mapping.get('snapshot_id'):
 
373
                msg = _('Either volume_id or snapshot_id must be specified for'
 
374
                        ' device mapping %s') % mapping['device_name']
 
375
                raise exception.StackValidationFailed(message=msg)
 
376
 
363
377
        # make sure the image exists if specified.
364
378
        image = self.properties.get('image', None)
365
379
        if image:
366
380
            nova_utils.get_image_id(self.nova(), image)
367
 
        else:
368
 
            # TODO(sbaker) confirm block_device_mapping is populated
369
 
            # for boot-by-volume (see LP bug #1215267)
370
 
            pass
 
381
        elif not image and not bootable_vol:
 
382
            msg = _('Neither image nor bootable volume is specified for'
 
383
                    ' instance %s') % self.name
 
384
            raise exception.StackValidationFailed(message=msg)
371
385
 
372
386
    def handle_delete(self):
373
387
        '''