コード例 #1
0
ファイル: cloud.py プロジェクト: bopopescu/cc-1
 def terminate_instances(self, context, instance_id, **kwargs):
     logging.debug("Going to start terminating instances")
     for i in instance_id:
         logging.debug("Going to try and terminate %s" % i)
         try:
             instance = self._get_instance(context, i)
         except exception.NotFound:
             logging.warning("Instance %s was not found during terminate" %
                             i)
             continue
         try:
             self.network.disassociate_address(
                 instance.get('public_dns_name', 'bork'))
         except:
             pass
         if instance.get('private_dns_name', None):
             logging.debug("Deallocating address %s" %
                           instance.get('private_dns_name', None))
             try:
                 self.network.deallocate_ip(
                     instance.get('private_dns_name', None))
             except Exception, _err:
                 pass
         if instance.get(
                 'node_name',
                 'unassigned') != 'unassigned':  #It's also internal default
             rpc.cast(
                 '%s.%s' % (FLAGS.compute_topic, instance['node_name']), {
                     "method": "terminate_instance",
                     "args": {
                         "instance_id": i
                     }
                 })
         else:
             instance.destroy()
コード例 #2
0
ファイル: manager.py プロジェクト: septimius/nova
    def prep_resize(self, context, instance_id, flavor_id):
        """Initiates the process of moving a running instance to another
        host, possibly changing the RAM and disk size in the process"""
        context = context.elevated()
        instance_ref = self.db.instance_get(context, instance_id)
        if instance_ref['host'] == FLAGS.host:
            raise exception.Error(
                _('Migration error: destination same as source!'))

        instance_type = self.db.instance_type_get_by_flavor_id(
            context, flavor_id)
        migration_ref = self.db.migration_create(
            context, {
                'instance_id': instance_id,
                'source_compute': instance_ref['host'],
                'dest_compute': FLAGS.host,
                'dest_host': self.driver.get_host_ip_addr(),
                'old_flavor_id': instance_type['flavorid'],
                'new_flavor_id': flavor_id,
                'status': 'pre-migrating'
            })

        LOG.audit(_('instance %s: migrating to '),
                  instance_id,
                  context=context)
        topic = self.db.queue_get_for(context, FLAGS.compute_topic,
                                      instance_ref['host'])
        rpc.cast(
            context, topic, {
                'method': 'resize_instance',
                'args': {
                    'migration_id': migration_ref['id'],
                    'instance_id': instance_id,
                },
            })
コード例 #3
0
ファイル: cloud.py プロジェクト: bopopescu/cc-1
 def detach_volume(self, context, volume_id, **kwargs):
     # TODO(joshua): Make sure the updated state has been received first
     volume = self._get_volume(context, volume_id)
     storage_node = volume['node_name']
     if 'instance_id' in volume.keys():
         instance_id = volume['instance_id']
         try:
             instance = self._get_instance(context, instance_id)
             compute_node = instance['node_name']
             mountpoint = volume['mountpoint']
             rpc.cast(
                 '%s.%s' % (FLAGS.compute_topic, compute_node), {
                     "method": "detach_volume",
                     "args": {
                         "instance_id": instance_id,
                         "mountpoint": mountpoint
                     }
                 })
         except exception.NotFound:
             pass
     rpc.cast('%s.%s' % (FLAGS.storage_topic, storage_node), {
         "method": "detach_volume",
         "args": {
             "volume_id": volume_id
         }
     })
     return defer.succeed(True)
コード例 #4
0
ファイル: cloud.py プロジェクト: bopopescu/cc-1
 def attach_volume(self, context, volume_id, instance_id, device, **kwargs):
     volume = self._get_volume(context, volume_id)
     storage_node = volume['node_name']
     # TODO: (joshua) Fix volumes to store creator id
     instance = self._get_instance(context, instance_id)
     compute_node = instance['node_name']
     aoe_device = volume['aoe_device']
     # Needs to get right node controller for attaching to
     # TODO: Maybe have another exchange that goes to everyone?
     rpc.cast(
         '%s.%s' % (FLAGS.compute_topic, compute_node), {
             "method": "attach_volume",
             "args": {
                 "aoe_device": aoe_device,
                 "instance_id": instance_id,
                 "mountpoint": device
             }
         })
     rpc.cast(
         '%s.%s' % (FLAGS.storage_topic, storage_node), {
             "method": "attach_volume",
             "args": {
                 "volume_id": volume_id,
                 "instance_id": instance_id,
                 "mountpoint": device
             }
         })
     return defer.succeed(True)
コード例 #5
0
ファイル: vsa.py プロジェクト: AsherBond/dodai-compute
    def _provision_volume(self, context, vol, vsa_id, availability_zone):

        if availability_zone is None:
            availability_zone = FLAGS.storage_availability_zone

        now = utils.utcnow()
        options = {
            'size': vol['size'],
            'user_id': context.user_id,
            'project_id': context.project_id,
            'snapshot_id': None,
            'availability_zone': availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': vol['name'],
            'display_description': vol['description'],
            'volume_type_id': vol['volume_type_id'],
            'metadata': dict(to_vsa_id=vsa_id),
            'host': vol['host'],
            'scheduled_at': now
            }

        size = vol['size']
        host = vol['host']
        name = vol['name']
        LOG.debug(_("Provision volume %(name)s of size %(size)s GB on "\
                    "host %(host)s"), locals())

        volume_ref = db.volume_create(context, options)
        rpc.cast(context,
                 db.queue_get_for(context, "volume", vol['host']),
                 {"method": "create_volume",
                  "args": {"volume_id": volume_ref['id'],
                           "snapshot_id": None}})
コード例 #6
0
ファイル: manager.py プロジェクト: septimius/nova
    def resize_instance(self, context, instance_id, migration_id):
        """Starts the migration of a running instance to another host"""
        migration_ref = self.db.migration_get(context, migration_id)
        instance_ref = self.db.instance_get(context, instance_id)
        self.db.migration_update(context, migration_id, {
            'status': 'migrating',
        })

        disk_info = self.driver.migrate_disk_and_power_off(
            instance_ref, migration_ref['dest_host'])
        self.db.migration_update(context, migration_id, {
            'status': 'post-migrating',
        })

        service = self.db.service_get_by_host_and_topic(
            context, migration_ref['dest_compute'], FLAGS.compute_topic)
        topic = self.db.queue_get_for(context, FLAGS.compute_topic,
                                      migration_ref['dest_compute'])
        rpc.cast(
            context, topic, {
                'method': 'finish_resize',
                'args': {
                    'migration_id': migration_id,
                    'instance_id': instance_id,
                    'disk_info': disk_info,
                },
            })
コード例 #7
0
def cast_to_network_host(context, host, method, update_db=False, **kwargs):
    """Cast request to a network host queue"""

    rpc.cast(context,
            db.queue_get_for(context, 'network', host),
            {"method": method, "args": kwargs})
    LOG.debug(_("Casted '%(method)s' to network '%(host)s'") % locals())
コード例 #8
0
def notify(message):
    """Sends a notification to the RabbitMQ"""
    context = nova.context.get_admin_context()
    priority = message.get('priority', FLAGS.default_notification_level)
    priority = priority.lower()
    topic = '%s.%s' % (FLAGS.notification_topic, priority)
    rpc.cast(context, topic, message)
コード例 #9
0
    def _create_snapshot(self,
                         context,
                         volume,
                         name,
                         description,
                         force=False):
        check_policy(context, 'create_snapshot', volume)

        if ((not force) and (volume['status'] != "available")):
            msg = _("must be available")
            raise exception.InvalidVolume(reason=msg)

        options = {
            'volume_id': volume['id'],
            'user_id': context.user_id,
            'project_id': context.project_id,
            'status': "creating",
            'progress': '0%',
            'volume_size': volume['size'],
            'display_name': name,
            'display_description': description
        }

        snapshot = self.db.snapshot_create(context, options)
        host = volume['host']
        rpc.cast(
            context, rpc.queue_get_for(context, FLAGS.volume_topic, host), {
                "method": "create_snapshot",
                "args": {
                    "volume_id": volume['id'],
                    "snapshot_id": snapshot['id']
                }
            })
        return snapshot
コード例 #10
0
    def delete(self, context, volume):
        volume_id = volume['id']
        if not volume['host']:
            # NOTE(vish): scheduling failed, so delete it
            self.db.volume_destroy(context, volume_id)
            return
        if volume['status'] not in ["available", "error"]:
            msg = _("Volume status must be available or error")
            raise exception.InvalidVolume(reason=msg)

        snapshots = self.db.snapshot_get_all_for_volume(context, volume_id)
        if len(snapshots):
            msg = _("Volume still has %d dependent snapshots") % len(snapshots)
            raise exception.InvalidVolume(reason=msg)

        now = timeutils.utcnow()
        self.db.volume_update(context, volume_id, {
            'status': 'deleting',
            'terminated_at': now
        })
        host = volume['host']
        rpc.cast(context, rpc.queue_get_for(context, FLAGS.volume_topic, host),
                 {
                     "method": "delete_volume",
                     "args": {
                         "volume_id": volume_id
                     }
                 })
コード例 #11
0
ファイル: api.py プロジェクト: kavanista/nova
    def _ask_scheduler_to_create_instance(self, context, base_options,
                                          instance_type, zone_blob,
                                          availability_zone, injected_files,
                                          admin_password,
                                          instance_id=None, num_instances=1):
        """Send the run_instance request to the schedulers for processing."""
        pid = context.project_id
        uid = context.user_id
        if instance_id:
            LOG.debug(_("Casting to scheduler for %(pid)s/%(uid)s's"
                    " instance %(instance_id)s (single-shot)") % locals())
        else:
            LOG.debug(_("Casting to scheduler for %(pid)s/%(uid)s's"
                    " (all-at-once)") % locals())

        filter_class = 'nova.scheduler.host_filter.InstanceTypeFilter'
        request_spec = {
            'instance_properties': base_options,
            'instance_type': instance_type,
            'filter': filter_class,
            'blob': zone_blob,
            'num_instances': num_instances,
        }

        rpc.cast(context,
                 FLAGS.scheduler_topic,
                 {"method": "run_instance",
                  "args": {"topic": FLAGS.compute_topic,
                           "instance_id": instance_id,
                           "request_spec": request_spec,
                           "availability_zone": availability_zone,
                           "admin_password": admin_password,
                           "injected_files": injected_files}})
コード例 #12
0
    def create(self, context, size, name, description):
        if quota.allowed_volumes(context, 1, size) < 1:
            pid = context.project_id
            LOG.warn(
                _("Quota exceeeded for %(pid)s, tried to create"
                  " %(size)sG volume") % locals())
            raise quota.QuotaError(
                _("Volume quota exceeded. You cannot "
                  "create a volume of size %sG") % size)

        options = {
            'size': size,
            'user_id': context.user_id,
            'project_id': context.project_id,
            'availability_zone': FLAGS.storage_availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': name,
            'display_description': description
        }

        volume = self.db.volume_create(context, options)
        rpc.cast(
            context, FLAGS.scheduler_topic, {
                "method": "create_volume",
                "args": {
                    "topic": FLAGS.volume_topic,
                    "volume_id": volume['id']
                }
            })
        return volume
コード例 #13
0
    def mounted_on_same_shared_storage(self, context, instance_ref, dest):
        """Check if the src and dest host mount same shared storage.

        At first, dest host creates temp file, and src host can see
        it if they mounts same shared storage. Then src host erase it.

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host

        """

        src = instance_ref['host']
        dst_t = db.queue_get_for(context, FLAGS.compute_topic, dest)
        src_t = db.queue_get_for(context, FLAGS.compute_topic, src)

        filename = rpc.call(context, dst_t,
                            {"method": 'create_shared_storage_test_file'})

        try:
            # make sure existence at src host.
            ret = rpc.call(context, src_t,
                        {"method": 'check_shared_storage_test_file',
                        "args": {'filename': filename}})

        finally:
            rpc.cast(context, dst_t,
                    {"method": 'cleanup_shared_storage_test_file',
                    "args": {'filename': filename}})

        return ret
コード例 #14
0
def cast_to_network_host(context, host, method, update_db=False, **kwargs):
    """Cast request to a network host queue"""

    rpc.cast(context,
            db.queue_get_for(context, 'network', host),
            {"method": method, "args": kwargs})
    LOG.debug(_("Casted '%(method)s' to network '%(host)s'") % locals())
コード例 #15
0
ファイル: api.py プロジェクト: apowers/openstack-nova
    def create(self, context, size, snapshot_id, name, description):
        if snapshot_id != None:
            snapshot = self.get_snapshot(context, snapshot_id)
            if snapshot['status'] != "available":
                raise exception.ApiError(
                    _("Snapshot status must be available"))
            if not size:
                size = snapshot['volume_size']

        if quota.allowed_volumes(context, 1, size) < 1:
            pid = context.project_id
            LOG.warn(_("Quota exceeded for %(pid)s, tried to create"
                    " %(size)sG volume") % locals())
            raise quota.QuotaError(_("Volume quota exceeded. You cannot "
                                     "create a volume of size %sG") % size)

        options = {
            'size': size,
            'user_id': context.user_id,
            'project_id': context.project_id,
            'snapshot_id': snapshot_id,
            'availability_zone': FLAGS.storage_availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': name,
            'display_description': description}

        volume = self.db.volume_create(context, options)
        rpc.cast(context,
                 FLAGS.scheduler_topic,
                 {"method": "create_volume",
                  "args": {"topic": FLAGS.volume_topic,
                           "volume_id": volume['id'],
                           "snapshot_id": snapshot_id}})
        return volume
コード例 #16
0
ファイル: cloud.py プロジェクト: jxta/cc
 def terminate_instances(self, context, instance_id, **kwargs):
     logging.debug("Going to start terminating instances")
     for i in instance_id:
         logging.debug("Going to try and terminate %s" % i)
         try:
             instance = self._get_instance(context, i)
         except exception.NotFound:
             logging.warning("Instance %s was not found during terminate" % i)
             continue
         try:
             self.network.disassociate_address(
                 instance.get('public_dns_name', 'bork'))
         except:
             pass
         if instance.get('private_dns_name', None):
             logging.debug("Deallocating address %s" % instance.get('private_dns_name', None))
             try:
                 self.network.deallocate_ip(instance.get('private_dns_name', None))
             except Exception, _err:
                 pass
         if instance.get('node_name', 'unassigned') != 'unassigned':  #It's also internal default
             rpc.cast('%s.%s' % (FLAGS.compute_topic, instance['node_name']),
                          {"method": "terminate_instance",
                           "args" : {"instance_id": i}})
         else:
             instance.destroy()
コード例 #17
0
ファイル: api.py プロジェクト: BillTheBest/nova
 def disassociate_floating_ip(self, context, address,
                              affect_auto_assigned=False):
     """Disassociates a floating ip from fixed ip it is associated with."""
     rpc.cast(context,
              FLAGS.network_topic,
              {'method': 'disassociate_floating_ip',
               'args': {'address': address}})
コード例 #18
0
ファイル: api.py プロジェクト: BillTheBest/nova
 def remove_fixed_ip_from_instance(self, context, instance_id, address):
     """Removes a fixed ip from instance from specified network."""
     args = {'instance_id': instance_id,
             'address': address}
     rpc.cast(context, FLAGS.network_topic,
              {'method': 'remove_fixed_ip_from_instance',
               'args': args})
コード例 #19
0
ファイル: api.py プロジェクト: hiteshwadekar/nova
    def _create_snapshot(self, context, volume, name, description, force=False):
        check_policy(context, "create_snapshot", volume)

        if (not force) and (volume["status"] != "available"):
            msg = _("must be available")
            raise exception.InvalidVolume(reason=msg)

        options = {
            "volume_id": volume["id"],
            "user_id": context.user_id,
            "project_id": context.project_id,
            "status": "creating",
            "progress": "0%",
            "volume_size": volume["size"],
            "display_name": name,
            "display_description": description,
        }

        snapshot = self.db.snapshot_create(context, options)
        host = volume["host"]
        rpc.cast(
            context,
            self.db.queue_get_for(context, FLAGS.volume_topic, host),
            {"method": "create_snapshot", "args": {"volume_id": volume["id"], "snapshot_id": snapshot["id"]}},
        )
        return snapshot
コード例 #20
0
ファイル: test_scheduler.py プロジェクト: termie/nova
 def test_with_two_zones(self):
     scheduler = manager.SchedulerManager()
     ctxt = context.get_admin_context()
     service_list = [
         self._create_service_model(id=1, host='host1', zone='zone1'),
         self._create_service_model(id=2, host='host2', zone='zone2'),
         self._create_service_model(id=3, host='host3', zone='zone2'),
         self._create_service_model(id=4, host='host4', zone='zone2'),
         self._create_service_model(id=5, host='host5', zone='zone2')
     ]
     self.mox.StubOutWithMock(db, 'service_get_all_by_topic')
     arg = IgnoreArg()
     db.service_get_all_by_topic(arg, arg).AndReturn(service_list)
     self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True)
     rpc.cast(
         ctxt, 'compute.host1', {
             'method': 'run_instance',
             'args': {
                 'instance_id': 'i-ffffffff',
                 'availability_zone': 'zone1'
             }
         })
     self.mox.ReplayAll()
     scheduler.run_instance(ctxt,
                            'compute',
                            instance_id='i-ffffffff',
                            availability_zone='zone1')
コード例 #21
0
ファイル: test_scheduler.py プロジェクト: pombredanne/nova
 def test_with_two_zones(self):
     scheduler = manager.SchedulerManager()
     ctxt = context.get_admin_context()
     service_list = [self._create_service_model(id=1,
                                                host='host1',
                                                zone='zone1'),
                     self._create_service_model(id=2,
                                                host='host2',
                                                zone='zone2'),
                     self._create_service_model(id=3,
                                                host='host3',
                                                zone='zone2'),
                     self._create_service_model(id=4,
                                                host='host4',
                                                zone='zone2'),
                     self._create_service_model(id=5,
                                                host='host5',
                                                zone='zone2')]
     self.mox.StubOutWithMock(db, 'service_get_all_by_topic')
     arg = IgnoreArg()
     db.service_get_all_by_topic(arg, arg).AndReturn(service_list)
     self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True)
     rpc.cast(ctxt,
              'compute.host1',
              {'method': 'run_instance',
               'args': {'instance_id': 'i-ffffffff',
                        'availability_zone': 'zone1'}})
     self.mox.ReplayAll()
     scheduler.run_instance(ctxt,
                            'compute',
                            instance_id='i-ffffffff',
                            availability_zone='zone1')
コード例 #22
0
ファイル: api.py プロジェクト: MirantisDellCrowbar/nova
    def _create_snapshot(self, context, volume, name, description,
                         force=False):
        check_policy(context, 'create_snapshot', volume)

        if ((not force) and (volume['status'] != "available")):
            msg = _("must be available")
            raise exception.InvalidVolume(reason=msg)

        options = {
            'volume_id': volume['id'],
            'user_id': context.user_id,
            'project_id': context.project_id,
            'status': "creating",
            'progress': '0%',
            'volume_size': volume['size'],
            'display_name': name,
            'display_description': description}

        snapshot = self.db.snapshot_create(context, options)
        host = volume['host']
        rpc.cast(context,
                 rpc.queue_get_for(context, FLAGS.volume_topic, host),
                 {"method": "create_snapshot",
                  "args": {"volume_id": volume['id'],
                           "snapshot_id": snapshot['id']}})
        return snapshot
コード例 #23
0
ファイル: test_scheduler.py プロジェクト: anotherjesse/nova
 def test_named_method(self):
     scheduler = manager.SchedulerManager()
     self.mox.StubOutWithMock(rpc, "cast", use_mock_anything=True)
     ctxt = context.get_admin_context()
     rpc.cast(ctxt, "topic.named_host", {"method": "named_method", "args": {"num": 7}})
     self.mox.ReplayAll()
     scheduler.named_method(ctxt, "topic", num=7)
コード例 #24
0
ファイル: api.py プロジェクト: termie/nova-migration-demo
 def associate_floating_ip(self, context, floating_ip, fixed_ip,
                           affect_auto_assigned=False):
     if isinstance(fixed_ip, str) or isinstance(fixed_ip, unicode):
         fixed_ip = self.db.fixed_ip_get_by_address(context, fixed_ip)
     floating_ip = self.db.floating_ip_get_by_address(context, floating_ip)
     if not affect_auto_assigned and floating_ip.get('auto_assigned'):
         return
     # Check if the floating ip address is allocated
     if floating_ip['project_id'] is None:
         raise exception.ApiError(_("Address (%s) is not allocated") %
                                    floating_ip['address'])
     # Check if the floating ip address is allocated to the same project
     if floating_ip['project_id'] != context.project_id:
         LOG.warn(_("Address (%(address)s) is not allocated to your "
                    "project (%(project)s)"),
                    {'address': floating_ip['address'],
                    'project': context.project_id})
         raise exception.ApiError(_("Address (%(address)s) is not "
                                    "allocated to your project"
                                    "(%(project)s)") %
                                     {'address': floating_ip['address'],
                                     'project': context.project_id})
     # NOTE(vish): Perhaps we should just pass this on to compute and
     #             let compute communicate with network.
     host = fixed_ip['network']['host']
     rpc.cast(context,
              self.db.queue_get_for(context, FLAGS.network_topic, host),
              {"method": "associate_floating_ip",
               "args": {"floating_address": floating_ip['address'],
                        "fixed_address": fixed_ip['address']}})
コード例 #25
0
 def disassociate_floating_ip(self, context, address,
                              affect_auto_assigned=False):
     """Disassociates a floating ip from fixed ip it is associated with."""
     rpc.cast(context,
              FLAGS.network_topic,
              {'method': 'disassociate_floating_ip',
               'args': {'address': address}})
コード例 #26
0
    def mounted_on_same_shared_storage(self, context, instance_ref, dest):
        """Check if the src and dest host mount same shared storage.

        At first, dest host creates temp file, and src host can see
        it if they mounts same shared storage. Then src host erase it.

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host

        """

        src = instance_ref['host']
        dst_t = db.queue_get_for(context, FLAGS.compute_topic, dest)
        src_t = db.queue_get_for(context, FLAGS.compute_topic, src)

        filename = rpc.call(context, dst_t,
                            {"method": 'create_shared_storage_test_file'})

        try:
            # make sure existence at src host.
            ret = rpc.call(context, src_t,
                        {"method": 'check_shared_storage_test_file',
                        "args": {'filename': filename}})

        finally:
            rpc.cast(context, dst_t,
                    {"method": 'cleanup_shared_storage_test_file',
                    "args": {'filename': filename}})

        return ret
コード例 #27
0
 def remove_fixed_ip_from_instance(self, context, instance_id, address):
     """Removes a fixed ip from instance from specified network."""
     args = {'instance_id': instance_id,
             'address': address}
     rpc.cast(context, FLAGS.network_topic,
              {'method': 'remove_fixed_ip_from_instance',
               'args': args})
コード例 #28
0
ファイル: manager.py プロジェクト: yosh/nova
    def prep_resize(self, context, instance_id):
        """Initiates the process of moving a running instance to another
        host, possibly changing the RAM and disk size in the process"""
        context = context.elevated()
        instance_ref = self.db.instance_get(context, instance_id)
        if instance_ref["host"] == FLAGS.host:
            raise exception.Error(_("Migration error: destination same as source!"))

        migration_ref = self.db.migration_create(
            context,
            {
                "instance_id": instance_id,
                "source_compute": instance_ref["host"],
                "dest_compute": FLAGS.host,
                "dest_host": self.driver.get_host_ip_addr(),
                "status": "pre-migrating",
            },
        )
        LOG.audit(_("instance %s: migrating to "), instance_id, context=context)
        topic = self.db.queue_get_for(context, FLAGS.compute_topic, instance_ref["host"])
        rpc.cast(
            context,
            topic,
            {"method": "resize_instance", "args": {"migration_id": migration_ref["id"], "instance_id": instance_id}},
        )
コード例 #29
0
ファイル: api.py プロジェクト: catchex/nova
    def _create_snapshot(self, context, volume, name, description,
                         force=False):
        check_policy(context, 'create_snapshot', volume)

        if ((not force) and (volume['status'] != "available")):
            raise exception.ApiError(_("Volume status must be available"))

        options = {
            'volume_id': volume['id'],
            'user_id': context.user_id,
            'project_id': context.project_id,
            'status': "creating",
            'progress': '0%',
            'volume_size': volume['size'],
            'display_name': name,
            'display_description': description}

        snapshot = self.db.snapshot_create(context, options)
        rpc.cast(context,
                 FLAGS.scheduler_topic,
                 {"method": "create_snapshot",
                  "args": {"topic": FLAGS.volume_topic,
                           "volume_id": volume['id'],
                           "snapshot_id": snapshot['id']}})
        return snapshot
コード例 #30
0
ファイル: api.py プロジェクト: jingsu/openstack
    def launch_instance(self, context, instance_uuid):
        pid = context.project_id
        uid = context.user_id

        self._check_quota(context, instance_uuid)
        instance = self.get(context, instance_uuid)

        if not(self._is_instance_blessed(context, instance_uuid)):
            # The instance is not blessed. We can't launch new instances from it.
            raise exception.Error(
                  _(("Instance %s is not blessed. " +
                     "Please bless the instance before launching from it.") % instance_uuid))

        # Create a new launched instance.
        new_instance_ref = self._copy_instance(context, instance_uuid, "clone", launch=True)

        LOG.debug(_("Casting to scheduler for %(pid)s/%(uid)s's"
                    " instance %(instance_uuid)s") % locals())
        rpc.cast(context,
                     FLAGS.scheduler_topic,
                     {"method": "launch_instance",
                      "args": {"topic": FLAGS.gridcentric_topic,
                               "instance_uuid": new_instance_ref['uuid']}})

        return self.get(context, new_instance_ref['uuid'])
コード例 #31
0
ファイル: api.py プロジェクト: cp16net/reddwarf
    def _create_snapshot(self,
                         context,
                         volume_id,
                         name,
                         description,
                         force=False):
        volume = self.get(context, volume_id)
        if ((not force) and (volume['status'] != "available")):
            raise exception.ApiError(_("Volume status must be available"))

        options = {
            'volume_id': volume_id,
            'user_id': context.user_id,
            'project_id': context.project_id,
            'status': "creating",
            'progress': '0%',
            'volume_size': volume['size'],
            'display_name': name,
            'display_description': description
        }

        snapshot = self.db.snapshot_create(context, options)
        rpc.cast(
            context, FLAGS.scheduler_topic, {
                "method": "create_snapshot",
                "args": {
                    "topic": FLAGS.volume_topic,
                    "volume_id": volume_id,
                    "snapshot_id": snapshot['id']
                }
            })
        return snapshot
コード例 #32
0
ファイル: api.py プロジェクト: rbenali/nova
    def create(self,
               context,
               size,
               snapshot_id,
               name,
               description,
               volume_type=None,
               metadata=None,
               availability_zone=None):
        if snapshot_id is not None:
            snapshot = self.get_snapshot(context, snapshot_id)
            if snapshot['status'] != "available":
                raise exception.ApiError(
                    _("Snapshot status must be available"))
            if not size:
                size = snapshot['volume_size']

        if quota.allowed_volumes(context, 1, size) < 1:
            pid = context.project_id
            LOG.warn(
                _("Quota exceeded for %(pid)s, tried to create"
                  " %(size)sG volume") % locals())
            raise exception.QuotaError(
                _("Volume quota exceeded. You cannot "
                  "create a volume of size %sG") % size)

        if availability_zone is None:
            availability_zone = FLAGS.storage_availability_zone

        if volume_type is None:
            volume_type_id = None
        else:
            volume_type_id = volume_type.get('id', None)

        options = {
            'size': size,
            'user_id': context.user_id,
            'project_id': context.project_id,
            'snapshot_id': snapshot_id,
            'availability_zone': availability_zone,
            'status': "creating",
            'attach_status': "detached",
            'display_name': name,
            'display_description': description,
            'volume_type_id': volume_type_id,
            'metadata': metadata,
        }

        volume = self.db.volume_create(context, options)
        rpc.cast(
            context, FLAGS.scheduler_topic, {
                "method": "create_volume",
                "args": {
                    "topic": FLAGS.volume_topic,
                    "volume_id": volume['id'],
                    "snapshot_id": snapshot_id
                }
            })
        return volume
コード例 #33
0
ファイル: api.py プロジェクト: derekhiggins/nova
 def remove_fixed_ip_from_instance(self, context, instance_id, address):
     """Removes a fixed ip from instance from specified network."""
     # NOTE(tr3buchet): poorly written, broken in all but flat manager
     args = {'instance_id': instance_id,
             'address': address}
     rpc.cast(context, FLAGS.network_topic,
              {'method': 'remove_fixed_ip_from_instance',
               'args': args})
コード例 #34
0
ファイル: api.py プロジェクト: termie/nova-migration-demo
    def set_admin_password(self, context, instance_id, password=None):
        """Set the root/admin password for the given instance."""
        host = self._find_host(context, instance_id)

        rpc.cast(context,
                 self.db.queue_get_for(context, FLAGS.compute_topic, host),
                 {"method": "set_admin_password",
                  "args": {"instance_id": instance_id, "new_pass": password}})
コード例 #35
0
ファイル: cloud.py プロジェクト: sorenh/cc
 def reboot_instances(self, context, instance_id, **kwargs):
     """instance_id is a list of instance ids"""
     for i in instance_id:
         instance = self._get_instance(context, i)
         rpc.cast('%s.%s' % (FLAGS.compute_topic, instance['node_name']),
                          {"method": "reboot_instance",
                           "args" : {"instance_id": i}})
     return defer.succeed(True)
コード例 #36
0
ファイル: api.py プロジェクト: tomchill/reddwarf
 def delete_instance_entry(self, context, instance, content):
     """Make an asynchronous call to delete an entry for an instance."""
     LOG.debug("Deleting instance entry for instance %s, with content %s" % \
               (instance, content))
     rpc.cast(context,  FLAGS.dns_topic,
              {'method': 'delete_instance_entry',
               'args': {'instance': self.convert_instance(instance),
                        'content': content}})
コード例 #37
0
def notify(message):
    """Sends a notification to the RabbitMQ"""
    context = nova.context.get_admin_context()
    priority = message.get('priority',
                           FLAGS.default_notification_level)
    priority = priority.lower()
    topic = '%s.%s' % (FLAGS.notification_topic, priority)
    rpc.cast(context, topic, message)
コード例 #38
0
 def add_fixed_ip_to_instance(self, context, instance_id, host, network_id):
     """Adds a fixed ip to instance from specified network."""
     args = {'instance_id': instance_id,
             'host': host,
             'network_id': network_id}
     rpc.cast(context, FLAGS.network_topic,
              {'method': 'add_fixed_ip_to_instance',
               'args': args})
コード例 #39
0
ファイル: cloud.py プロジェクト: joshuamckenty/pinet
 def delete_volume(self, context, volume_id, **kwargs):
     # TODO: return error if not authorized
     storage_node, volume = self._get_volume(volume_id)
     if context.user.is_authorized(volume.get('user_id', None)):
         rpc.cast('%s.%s' % (FLAGS.storage_topic, storage_node),
                             {"method": "delete_volume",
                              "args" : {"volume_id": volume_id}})
     return defer.succeed(True)
コード例 #40
0
ファイル: api.py プロジェクト: xtoddx/nova
 def add_network_to_project(self, context, project_id):
     """Force adds another network to a project."""
     rpc.cast(context, FLAGS.network_topic, {
         'method': 'add_network_to_project',
         'args': {
             'project_id': project_id
         }
     })
コード例 #41
0
 def release_floating_ip(self, context, address,
                         affect_auto_assigned=False):
     """Removes floating ip with address from a project. (deallocates)"""
     rpc.cast(context,
              FLAGS.network_topic,
              {'method': 'deallocate_floating_ip',
               'args': {'address': address,
                        'affect_auto_assigned': affect_auto_assigned}})
コード例 #42
0
 def deallocate_for_instance(self, context, instance, **kwargs):
     """Deallocates all network structures related to instance."""
     args = kwargs
     args['instance_id'] = instance['id']
     args['project_id'] = instance['project_id']
     rpc.cast(context, FLAGS.network_topic,
              {'method': 'deallocate_for_instance',
               'args': args})
コード例 #43
0
ファイル: cloud.py プロジェクト: jxta/cc
 def delete_volume(self, context, volume_id, **kwargs):
     # TODO: return error if not authorized
     volume = self._get_volume(context, volume_id)
     storage_node = volume['node_name']
     rpc.cast('%s.%s' % (FLAGS.storage_topic, storage_node),
                         {"method": "delete_volume",
                          "args" : {"volume_id": volume_id}})
     return defer.succeed(True)
コード例 #44
0
def notify(message):
    """Notifies the recipient of the desired event given the model.
    Log notifications using nova's default logging system"""
    context = nova.context.get_admin_context()
    message['method'] = 'notify'
    priority = message.get('priority',
                           FLAGS.default_notification_level)
    priority = priority.lower()
    rpc.cast(context, FLAGS.notification_topic, {'method':'notify','args':{'message':message}})
コード例 #45
0
ファイル: api.py プロジェクト: derekhiggins/nova
 def add_fixed_ip_to_instance(self, context, instance_id, host, network_id):
     """Adds a fixed ip to instance from specified network."""
     # NOTE(tr3buchet): poorly written, broken in all but flat manager
     args = {'instance_id': instance_id,
             'host': host,
             'network_id': network_id}
     rpc.cast(context, FLAGS.network_topic,
              {'method': 'add_fixed_ip_to_instance',
               'args': args})
コード例 #46
0
ファイル: api.py プロジェクト: nicoleLiu/nova
 def delete_console(self, context, instance_id, console_id):
     instance_id = self._translate_uuid_if_necessary(context, instance_id)
     console = self.db.console_get(context, console_id, instance_id)
     pool = console["pool"]
     rpc.cast(
         context,
         self.db.queue_get_for(context, FLAGS.console_topic, pool["host"]),
         {"method": "remove_console", "args": {"console_id": console["id"]}},
     )
コード例 #47
0
ファイル: api.py プロジェクト: tomchill/reddwarf
 def create_instance_entry(self, context, instance, content):
     """Make an asynchronous call to create a new entry for an instance."""
     converted_instance = self.convert_instance(instance)
     LOG.debug("Creating instance entry for instance %s, with content %s" % \
               (converted_instance, content))
     rpc.cast(context,  FLAGS.dns_topic,
              {'method': 'create_instance_entry',
               'args': {'instance': converted_instance,
                        'content': content}})
コード例 #48
0
ファイル: api.py プロジェクト: yamahata/nova
 def delete_snapshot(self, context, snapshot_id):
     snapshot = self.get_snapshot(context, snapshot_id)
     if snapshot['status'] != "available":
         raise exception.ApiError(_("Snapshot status must be available"))
     self.db.snapshot_update(context, snapshot_id, {'status': 'deleting'})
     rpc.cast(context,
              FLAGS.scheduler_topic,
              {"method": "delete_snapshot",
               "args": {"topic": FLAGS.volume_topic,
                        "snapshot_id": snapshot_id}})
コード例 #49
0
ファイル: test_scheduler.py プロジェクト: septimius/nova
 def test_fallback(self):
     scheduler = manager.SchedulerManager()
     self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True)
     ctxt = context.get_admin_context()
     rpc.cast(ctxt,
              'topic.fallback_host',
              {'method': 'noexist',
               'args': {'num': 7}})
     self.mox.ReplayAll()
     scheduler.noexist(ctxt, 'topic', num=7)
コード例 #50
0
 def report_state(self):
     logging.debug("Reporting State")
     rpc.cast(
         "cloud", {
             "method": "update_state",
             "args": {
                 "topic": "volumes",
                 "value": self.describe_volumes()
             }
         })
コード例 #51
0
ファイル: api.py プロジェクト: bopopescu/extra-specs-1
 def create_console(self, context, instance_id):
     #NOTE(mdragon): If we wanted to return this the console info
     #               here, as we would need to do a call.
     #               They can just do an index later to fetch
     #               console info. I am not sure which is better
     #               here.
     instance = self._get_instance(context, instance_id)
     rpc.cast(context,
              self._get_console_topic(context, instance['host']),
              {'method': 'add_console',
               'args': {'instance_id': instance['id']}})
コード例 #52
0
ファイル: api.py プロジェクト: septimius/nova
 def create_console(self, context, instance_id):
     instance = self.db.instance_get(context, instance_id)
     #NOTE(mdragon): If we wanted to return this the console info
     #               here, as we would need to do a call.
     #               They can just do an index later to fetch
     #               console info. I am not sure which is better
     #               here.
     rpc.cast(context,
              self._get_console_topic(context, instance['host']),
              {"method": "add_console",
               "args": {"instance_id": instance_id}})
コード例 #53
0
 def reboot_instances(self, context, instance_id, **kwargs):
     """instance_id is a list of instance ids"""
     for i in instance_id:
         instance = self._get_instance(context, i)
         rpc.cast('%s.%s' % (FLAGS.compute_topic, instance['node_name']), {
             "method": "reboot_instance",
             "args": {
                 "instance_id": i
             }
         })
     return defer.succeed(True)
コード例 #54
0
 def delete_volume(self, context, volume_id, **kwargs):
     # TODO: return error if not authorized
     storage_node, volume = self._get_volume(volume_id)
     if context.user.is_authorized(volume.get('user_id', None)):
         rpc.cast('%s.%s' % (FLAGS.storage_topic, storage_node), {
             "method": "delete_volume",
             "args": {
                 "volume_id": volume_id
             }
         })
     return defer.succeed(True)
コード例 #55
0
 def delete_volume(self, context, volume_id, **kwargs):
     # TODO: return error if not authorized
     volume = self._get_volume(context, volume_id)
     storage_node = volume['node_name']
     rpc.cast('%s.%s' % (FLAGS.storage_topic, storage_node), {
         "method": "delete_volume",
         "args": {
             "volume_id": volume_id
         }
     })
     return defer.succeed(True)