~ubuntu-branches/ubuntu/natty/nova/natty

« back to all changes in this revision

Viewing changes to nova/compute/api.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short, Chuck Short, Thierry Carrez
  • Date: 2011-02-25 14:01:06 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110225140106-0gfh4sof7wafe9ra
Tags: 2011.2~bzr740-0ubuntu1

[Chuck Short]
* New upstream release.

[Thierry Carrez]
* Add python-distutils-extra as build-dep (for i18n)
* Ship .mo files in /usr/share/locale
* Add lvdisplay to nova_sudoers, clean up dupe entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
               min_count=1, max_count=1,
86
86
               display_name='', display_description='',
87
87
               key_name=None, key_data=None, security_group='default',
88
 
               availability_zone=None, user_data=None,
 
88
               availability_zone=None, user_data=None, metadata=[],
89
89
               onset_files=None):
90
90
        """Create the number of instances requested if quota and
91
91
        other arguments check out ok.
100
100
                                     "run %s more instances of this type.") %
101
101
                                   num_instances, "InstanceLimitExceeded")
102
102
 
103
 
        is_vpn = image_id == FLAGS.vpn_image_id
104
 
        if not is_vpn:
105
 
            image = self.image_service.show(context, image_id)
106
 
            if kernel_id is None:
107
 
                kernel_id = image.get('kernel_id', None)
108
 
            if ramdisk_id is None:
109
 
                ramdisk_id = image.get('ramdisk_id', None)
110
 
            # No kernel and ramdisk for raw images
111
 
            if kernel_id == str(FLAGS.null_kernel):
112
 
                kernel_id = None
113
 
                ramdisk_id = None
114
 
                LOG.debug(_("Creating a raw instance"))
115
 
            # Make sure we have access to kernel and ramdisk (if not raw)
116
 
            logging.debug("Using Kernel=%s, Ramdisk=%s" %
117
 
                           (kernel_id, ramdisk_id))
118
 
            if kernel_id:
119
 
                self.image_service.show(context, kernel_id)
120
 
            if ramdisk_id:
121
 
                self.image_service.show(context, ramdisk_id)
 
103
        num_metadata = len(metadata)
 
104
        quota_metadata = quota.allowed_metadata_items(context, num_metadata)
 
105
        if quota_metadata < num_metadata:
 
106
            pid = context.project_id
 
107
            msg = (_("Quota exceeeded for %(pid)s,"
 
108
                     " tried to set %(num_metadata)s metadata properties")
 
109
                   % locals())
 
110
            LOG.warn(msg)
 
111
            raise quota.QuotaError(msg, "MetadataLimitExceeded")
 
112
 
 
113
        # Because metadata is stored in the DB, we hard-code the size limits
 
114
        # In future, we may support more variable length strings, so we act
 
115
        #  as if this is quota-controlled for forwards compatibility
 
116
        for metadata_item in metadata:
 
117
            k = metadata_item['key']
 
118
            v = metadata_item['value']
 
119
            if len(k) > 255 or len(v) > 255:
 
120
                pid = context.project_id
 
121
                msg = (_("Quota exceeeded for %(pid)s,"
 
122
                         " metadata property key or value too long")
 
123
                       % locals())
 
124
                LOG.warn(msg)
 
125
                raise quota.QuotaError(msg, "MetadataLimitExceeded")
 
126
 
 
127
        image = self.image_service.show(context, image_id)
 
128
        if kernel_id is None:
 
129
            kernel_id = image.get('kernel_id', None)
 
130
        if ramdisk_id is None:
 
131
            ramdisk_id = image.get('ramdisk_id', None)
 
132
        # No kernel and ramdisk for raw images
 
133
        if kernel_id == str(FLAGS.null_kernel):
 
134
            kernel_id = None
 
135
            ramdisk_id = None
 
136
            LOG.debug(_("Creating a raw instance"))
 
137
        # Make sure we have access to kernel and ramdisk (if not raw)
 
138
        logging.debug("Using Kernel=%s, Ramdisk=%s" %
 
139
                       (kernel_id, ramdisk_id))
 
140
        if kernel_id:
 
141
            self.image_service.show(context, kernel_id)
 
142
        if ramdisk_id:
 
143
            self.image_service.show(context, ramdisk_id)
122
144
 
123
145
        if security_group is None:
124
146
            security_group = ['default']
156
178
            'key_name': key_name,
157
179
            'key_data': key_data,
158
180
            'locked': False,
 
181
            'metadata': metadata,
159
182
            'availability_zone': availability_zone}
160
183
        elevated = context.elevated()
161
184
        instances = []
449
472
                 {'method': 'authorize_ajax_console',
450
473
                  'args': {'token': output['token'], 'host': output['host'],
451
474
                  'port': output['port']}})
452
 
        return {'url': '%s?token=%s' % (FLAGS.ajax_console_proxy_url,
 
475
        return {'url': '%s/?token=%s' % (FLAGS.ajax_console_proxy_url,
453
476
                output['token'])}
454
477
 
455
478
    def get_console_output(self, context, instance_id):
478
501
        """
479
502
        self._cast_compute_message('reset_network', context, instance_id)
480
503
 
 
504
    def inject_network_info(self, context, instance_id):
 
505
        """
 
506
        Inject network info for the instance.
 
507
 
 
508
        """
 
509
        self._cast_compute_message('inject_network_info', context, instance_id)
 
510
 
481
511
    def attach_volume(self, context, instance_id, volume_id, device):
482
512
        if not re.match("^/dev/[a-z]d[a-z]+$", device):
483
513
            raise exception.ApiError(_("Invalid device specified: %s. "