~fred-yang/nova/TrustedComputingPools

« back to all changes in this revision

Viewing changes to nova/vsa/api.py

  • Committer: vladimir.p
  • Date: 2011-07-24 07:07:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1502.
  • Revision ID: vladimir@zadarastorage.com-20110724070700-1hrilg0nylnumswg
some cosmetic changes. Prior to merge proposal

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
            num_disks = node.get('num_drives', 1)
75
75
 
76
76
            if name is None:
77
 
                raise exception.ApiError(_("No drive_name param found in %s"),
78
 
                                            node)
 
77
                raise exception.ApiError(_("No drive_name param found in %s")
 
78
                                            % node)
79
79
 
80
80
            # find DB record for this disk
81
81
            try:
82
82
                drive_ref = drive_types.get_by_name(context, name)
83
83
            except exception.NotFound:
84
 
                raise exception.ApiError(_("Invalid drive type name %s"),
85
 
                                            name)
 
84
                raise exception.ApiError(_("Invalid drive type name %s")
 
85
                                            % name)
86
86
 
87
87
            # if size field present - override disk size specified in DB
88
88
            size = node.get('size', drive_ref['size_gb'])
149
149
            vc_image = image_service.show_by_name(context, image_name)
150
150
            vc_image_href = vc_image['id']
151
151
        except exception.ImageNotFound:
152
 
            raise exception.ApiError(_("Failed to find configured image %s"),
153
 
                                        image_name)
 
152
            raise exception.ApiError(_("Failed to find configured image %s")
 
153
                                        % image_name)
154
154
 
155
155
        options = {
156
156
            'display_name': display_name,
258
258
        """
259
259
        LOG.info(_("VSA ID %(vsa_id)d: Update VSA call"), locals())
260
260
 
 
261
        updatable_fields = ['status', 'vc_count', 'vol_count',
 
262
                            'display_name', 'display_description']
 
263
        changes = {}
 
264
        for field in updatable_fields:
 
265
            if field in kwargs:
 
266
                changes[field] = kwargs[field]
 
267
 
261
268
        vc_count = kwargs.get('vc_count', None)
262
269
        if vc_count is not None:
263
270
            # VP-TODO: This request may want to update number of VCs
264
271
            # Get number of current VCs and add/delete VCs appropriately
265
272
            vsa = self.get(context, vsa_id)
266
273
            vc_count = int(vc_count)
 
274
            if vc_count > FLAGS.max_vcs_in_vsa:
 
275
                LOG.warning(_("Requested number of VCs (%d) is too high."\
 
276
                              " Setting to default"), vc_count)
 
277
                vc_count = FLAGS.max_vcs_in_vsa
 
278
 
267
279
            if vsa['vc_count'] != vc_count:
268
280
                self.update_num_vcs(context, vsa, vc_count)
 
281
                changes['vc_count'] = vc_count
269
282
 
270
 
        return self.db.vsa_update(context, vsa_id, kwargs)
 
283
        return self.db.vsa_update(context, vsa_id, changes)
271
284
 
272
285
    def update_num_vcs(self, context, vsa, vc_count):
273
 
        if vc_count > FLAGS.max_vcs_in_vsa:
274
 
            LOG.warning(_("Requested number of VCs (%d) is too high."\
275
 
                          " Setting to default"), vc_count)
276
 
            vc_count = FLAGS.max_vcs_in_vsa
277
 
 
278
286
        vsa_name = vsa['name']
279
 
        old_vc_count = vsa['vc_count']
 
287
        old_vc_count = int(vsa['vc_count'])
280
288
        if vc_count > old_vc_count:
281
289
            add_cnt = vc_count - old_vc_count
282
 
            LOG.debug(_("Adding %(add_cnt)d VCs to VSA %(vsa_name)s."),
 
290
            LOG.debug(_("Adding %(add_cnt)s VCs to VSA %(vsa_name)s."),
283
291
                        locals())
284
292
            # VP-TODO: actual code for adding new VCs
285
293
 
286
294
        elif vc_count < old_vc_count:
287
295
            del_cnt = old_vc_count - vc_count
288
 
            LOG.debug(_("Deleting %(add_cnt)d VCs from VSA %(vsa_name)s."),
 
296
            LOG.debug(_("Deleting %(del_cnt)s VCs from VSA %(vsa_name)s."),
289
297
                        locals())
290
298
            # VP-TODO: actual code for deleting extra VCs
291
299
 
372
380
        e_vsa_detail = SubElement(e_vsa, "vc_count")
373
381
        e_vsa_detail.text = str(vsa['vc_count'])
374
382
        e_vsa_detail = SubElement(e_vsa, "auth_user")
375
 
        e_vsa_detail.text = str(context.user.name)
 
383
        if context.user is not None:
 
384
            e_vsa_detail.text = str(context.user.name)
376
385
        e_vsa_detail = SubElement(e_vsa, "auth_access_key")
377
 
        e_vsa_detail.text = str(context.user.access)
 
386
        if context.user is not None:
 
387
            e_vsa_detail.text = str(context.user.access)
378
388
 
379
389
        e_volumes = SubElement(e_vsa, "volumes")
380
390
        for volume in volumes: