示例#1
0
文件: node.py 项目: agua/StarCluster
    def stop(self):
        """
        Shutdown EBS-backed instance and put it in the 'stopped' state.
        Only works if this node is EBS-backed, raises
        exception.InvalidOperation otherwise.

        NOTE: The EBS root device will *not* be deleted and the instance can
        be 'started' later on.
        """
        if self.is_spot():
            raise exception.InvalidOperation(
                "spot instances can not be stopped")
        elif not self.is_ebs_backed():
            raise exception.InvalidOperation(
                "Only EBS-backed instances can be stopped")
        log.info("Stopping instance: %s (%s)" % (self.alias, self.id))
        return self.instance.stop()
示例#2
0
    def resize(self, vol, size, dest_zone=None):
        """
        Resize EBS volume

        vol - boto volume object
        size - new volume size
        dest_zone - zone to create the new resized volume in. this must be
        within the original volume's region otherwise a manual copy (rsync)
        is required. this is currently not implemented.
        """
        try:
            self._validate_device(self._aws_block_device)
            self._validate_resize(vol, size)
            zone = vol.zone
            if dest_zone:
                self._validate_zone(dest_zone)
                zone = dest_zone
            host = self._request_instance(zone)
            resizefs_exe = self._resizefs_cmd.split()[0]
            required = [resizefs_exe]
            if resizefs_exe == 'resize2fs':
                required.append('e2fsck')
            self._validate_required_progs(required)
            self._determine_device()
            snap = self._create_snapshot(vol)
            new_vol = self._create_volume(size, zone, snap.id)
            self._attach_volume(new_vol, host.id, self._aws_block_device)
            device = self._get_volume_device()
            devs = filter(lambda x: x.startswith(device), host.ssh.ls('/dev'))
            if len(devs) == 1:
                log.info("No partitions found, resizing entire device")
            elif len(devs) == 2:
                log.info("One partition found, resizing partition...")
                self._repartition_volume()
                device += '1'
            else:
                raise exception.InvalidOperation(
                    "EBS volume %s has more than 1 partition. "
                    "You must resize this volume manually" % vol.id)
            if resizefs_exe == "resize2fs":
                log.info("Running e2fsck on new volume")
                host.ssh.execute("e2fsck -y -f %s" % device)
            log.info("Running %s on new volume" % self._resizefs_cmd)
            host.ssh.execute(' '.join([self._resizefs_cmd, device]))
            self.shutdown()
            return new_vol.id
        except Exception:
            log.error("Failed to resize volume %s" % vol.id)
            self._delete_new_volume()
            raise
        finally:
            snap = self._snapshot
            if snap:
                log_func = log.info if self._volume else log.error
                log_func("Deleting snapshot %s" % snap.id)
                snap.delete()
            self._warn_about_volume_hosts()
示例#3
0
 def start(self):
     """
     Starts EBS-backed instance and puts it in the 'running' state.
     Only works if this node is EBS-backed, raises
     exception.InvalidOperation otherwise.
     """
     if not self.is_ebs_backed():
         raise exception.InvalidOperation(
             "Only EBS-backed instances can be started")
     return self.instance.start()
示例#4
0
    def resize(self, vol, size, dest_zone=None):
        """
        Resize EBS volume

        vol - boto volume object
        size - new volume sze
        dest_zone - zone to create the new resized volume in. this must be
        within the original volume's region otherwise a manual copy (rsync)
        is required. this is currently not implemented.
        """
        try:
            self._validate_device(self._device)
            self._validate_resize(vol, size)
            zone = vol.zone
            if dest_zone:
                self._validate_zone(dest_zone)
                zone = dest_zone
            host = self._request_instance(zone)
            self._validate_required_progs([self._resizefs_cmd.split()[0]])
            self._determine_device()
            snap = self.ec2.create_snapshot(vol, wait_for_snapshot=True)
            new_vol = self._create_volume(size, zone, snap.id)
            self._attach_volume(new_vol, host.id, self._device)
            devs = filter(lambda x: x.startswith(self._device),
                          host.ssh.ls('/dev'))
            device = self._device
            if len(devs) == 1:
                log.info("No partitions found, resizing entire device")
            elif len(devs) == 2:
                log.info("One partition found, resizing partition...")
                self._partition_volume()
                device += '1'
            else:
                raise exception.InvalidOperation(
                    "EBS volume %s has more than 1 partition. "
                    "You must resize this volume manually" % vol.id)
            host.ssh.execute(' '.join([self._resizefs_cmd, device]))
            log.info("Removing generated snapshot %s" % snap.id)
            snap.delete()
            self.shutdown()
            self._warn_about_volume_hosts()
            return new_vol.id
        except Exception:
            self._warn_about_volume_hosts()
            raise