コード例 #1
0
ファイル: volume.py プロジェクト: mresnick/StarCluster
 def _request_instance(self, zone):
     for i in self.security_group.instances():
         if i.state in ['pending','running'] and i.placement == zone:
             log.info("Using existing instance %s in group %s" % \
                      (i.id,self.security_group.name))
             self._instance = Node(i, self._key_location, 'vol_host')
             break
     if not self._instance:
         log.info("No instance in group %s for zone %s, launching one now." % \
                  (self.security_group.name, zone))
         self._resv = self._ec2.run_instances(image_id=self._image_id,
             instance_type=self._instance_type,
             min_count=1, max_count=1,
             security_groups=[self.security_group.name],
             key_name=self._keypair,
             placement=zone)
         instance = self._resv.instances[0]
         self._instance = Node(instance, self._key_location, 'vol_host')
     s = Spinner()
     log.info("Waiting for instance %s to come up..." % self._instance.id)
     s.start()
     while not self._instance.is_up():
         time.sleep(15)
     s.stop()
     return self._instance
コード例 #2
0
ファイル: cluster.py プロジェクト: samof76/StarCluster
 def _start(self, create=True):
     """
     Start cluster from this cluster template's settings
     Handles creating and configuring a cluster
     Does not attempt to validate before running
     """
     log.info("Starting cluster...")
     if create:
         self.create_cluster()
     s = Spinner()
     log.log(INFO_NO_NEWLINE, "Waiting for cluster to start...")
     s.start()
     while not self.is_cluster_up():
         time.sleep(30)
     s.stop()
     log.info("The master node is %s" % self.master_node.dns_name)
     if self.volumes:
         self.attach_volumes_to_master()
     log.info("Setting up the cluster...")
     default_setup = clustersetup.DefaultClusterSetup().run(
         self.nodes, self.master_node, self.cluster_user, self.cluster_shell, self.volumes
     )
     self.create_receipt()
     self.run_plugins()
     log.info(
         user_msgs.cluster_started_msg
         % {
             "master": self.master_node.dns_name,
             "user": self.cluster_user,
             "key": self.key_location,
             "tag": self.cluster_tag,
         }
     )
コード例 #3
0
ファイル: image.py プロジェクト: lstewart-git/StarCluster
 def _create_image_from_ebs(self, size=15):
     log.info("Creating new EBS AMI...")
     imgid = self.ec2.create_image(self.host.id, self.name, self.description)
     img = self.ec2.get_image(imgid)
     log.info("New EBS AMI created: %s" % imgid)
     root_dev = self.host.root_device_name
     if root_dev in self.host.block_device_mapping:
         log.info("Fetching block device mapping for %s" % imgid, extra=dict(__nonewline__=True))
         s = Spinner()
         try:
             s.start()
             while root_dev not in img.block_device_mapping:
                 img = self.ec2.get_image(imgid)
                 time.sleep(5)
         finally:
             s.stop()
         snapshot_id = img.block_device_mapping[root_dev].snapshot_id
         snap = self.ec2.get_snapshot(snapshot_id)
         self.ec2.wait_for_snapshot(snap)
     else:
         log.warn("Unable to find root device - cant wait for snapshot")
     log.info("Waiting for %s to become available..." % imgid, extra=dict(__nonewline__=True))
     s = Spinner()
     try:
         s.start()
         while img.state == "pending":
             time.sleep(15)
             if img.update() == "failed":
                 raise exception.AWSError("EBS image creation failed for %s" % imgid)
     finally:
         s.stop()
     return imgid
コード例 #4
0
ファイル: volume.py プロジェクト: leadtune/StarCluster
 def _request_instance(self, zone):
     alias = self._alias_tmpl % zone
     if self._instance:
         i = self._instance
         if i.state not in ['pending', 'running']:
             raise exception.InstanceNotRunning(i.id)
         if i.placement != zone:
             raise exception.ValidationError(
                 "specified host instance %s is not in zone %s" %
                 (i.id, zone))
         self._instance = Node(i, self._key_location, alias)
     else:
         self._instance = self._get_existing_instance(zone)
     if not self._instance:
         self._validate_image_and_type(self._image_id, self._instance_type)
         log.info(
             "No instance in group %s for zone %s, launching one now." % \
             (self.security_group.name, zone))
         self._resv = self._ec2.run_instances(
             image_id=self._image_id,
             instance_type=self._instance_type,
             min_count=1, max_count=1,
             security_groups=[self.security_group.name],
             key_name=self._keypair,
             placement=zone,
             user_data=alias)
         instance = self._resv.instances[0]
         self._instance = Node(instance, self._key_location, alias)
     s = Spinner()
     log.log(INFO_NO_NEWLINE,
              "Waiting for instance %s to come up..." % self._instance.id)
     s.start()
     while not self._instance.is_up():
         time.sleep(15)
     s.stop()
     return self._instance
コード例 #5
0
ファイル: image.py プロジェクト: mmcclellan/StarCluster
 def _create_image_from_ebs(self, size=15):
     log.info("Creating EBS image...")
     imgid = self.ec2.create_image(self.host.id, self.name,
                                   self.description)
     log.info("Waiting for AMI %s to become available..." % imgid,
              extra=dict(__nonewline__=True))
     img = self.ec2.get_image(imgid)
     s = Spinner()
     s.start()
     while img.state == "pending":
         time.sleep(15)
         if img.update() == "failed":
             raise exception.AWSError(
                 "EBS image creation failed for AMI %s" % imgid)
     s.stop()
     return imgid
コード例 #6
0
ファイル: image.py プロジェクト: gabekron/StarCluster
 def _create_image_from_ebs(self, size=15):
     log.info("Creating new EBS AMI...")
     imgid = self.ec2.create_image(self.host.id, self.name,
                                   self.description)
     img = self.ec2.get_image(imgid)
     log.info("New EBS AMI created: %s" % imgid)
     root_dev = self.host.root_device_name
     if root_dev in self.host.block_device_mapping:
         log.info("Fetching block device mapping for %s" % imgid,
                  extra=dict(__nonewline__=True))
         s = Spinner()
         try:
             s.start()
             while root_dev not in img.block_device_mapping:
                 img = self.ec2.get_image(imgid)
                 time.sleep(5)
         finally:
             s.stop()
         snapshot_id = img.block_device_mapping[root_dev].snapshot_id
         snap = self.ec2.get_snapshot(snapshot_id)
         self.ec2.wait_for_snapshot(snap)
     else:
         log.warn("Unable to find root device - cant wait for snapshot")
     log.info("Waiting for %s to become available..." % imgid,
              extra=dict(__nonewline__=True))
     s = Spinner()
     try:
         s.start()
         while img.state == "pending":
             time.sleep(15)
             if img.update() == "failed":
                 raise exception.AWSError(
                     "EBS image creation failed for %s" % imgid)
     finally:
         s.stop()
     return imgid
コード例 #7
0
 def create_image(self, size=15):
     host = self.host
     host_ssh = self.host_ssh
     self.clean_private_data()
     if self.host.root_device_type == "ebs":
         log.info("Creating EBS image...")
         imgid = self.ec2.create_image(host.id, self.name,
                                       self.description)
         s = Spinner()
         log.log(INFO_NO_NEWLINE,
                 "Waiting for AMI %s to become available..." % imgid)
         s.start()
         img = self.ec2.get_image(imgid)
         while img.update() == "pending":
             time.sleep(15)
         s.stop()
         if img.update() == "failed":
             raise exception.AWSError(
                 "EBS image creation failed for AMI %s" % imgid)
         return imgid
     log.info("Creating new EBS-backed image from instance-store instance")
     log.info("Creating new root volume...")
     vol = self.ec2.create_volume(size, host.placement)
     log.info("Created new volume: %s" % vol.id)
     while vol.update() != 'available':
         time.sleep(5)
     dev = None
     for i in string.ascii_lowercase[::-1]:
         dev = '/dev/sd%s' % i
         if not dev in host.block_device_mapping:
             break
     log.info("Attaching volume %s to instance %s on %s" %
              (vol.id, host.id, dev))
     vol.attach(host.id, dev)
     while vol.update() != 'in-use':
         time.sleep(5)
     while not host_ssh.path_exists(dev):
         time.sleep(5)
     host_ssh.execute('mkfs.ext3 -F %s' % dev)
     mount_point = '/ebs'
     while host_ssh.path_exists(mount_point):
         mount_point += '1'
     host_ssh.mkdir(mount_point)
     log.info("Mounting %s on %s" % (dev, mount_point))
     host_ssh.execute('mount %s %s' % (dev, mount_point))
     log.info("Configuring /etc/fstab")
     host_ssh.remove_lines_from_file('/etc/fstab', '/mnt')
     fstab = host_ssh.remote_file('/etc/fstab', 'a')
     fstab.write('/dev/sdb1 /mnt auto defaults,nobootwait 0 0\n')
     fstab.close()
     log.info("Syncing root filesystem to new volume (%s)" % vol.id)
     host_ssh.execute(
         'rsync -avx --exclude %(mpt)s --exclude /root/.ssh / %(mpt)s' % \
         {'mpt': mount_point})
     log.info("Unmounting %s from %s" % (dev, mount_point))
     host_ssh.execute('umount %s' % mount_point)
     log.info("Detaching volume %s from %s" % (dev, mount_point))
     vol.detach()
     while vol.update() != 'available':
         time.sleep(5)
     snap = self.ec2.create_snapshot(vol,
                                     description=self.snapshot_description,
                                     wait_for_snapshot=True)
     log.info("New snapshot created: %s" % snap.id)
     bmap = self.ec2.create_root_block_device_map(snap.id,
                                                  add_ephemeral_drives=True)
     log.info("Registering new image...")
     img_id = self.ec2.register_image(name=self.name,
                                      description=self.description,
                                      architecture=host.architecture,
                                      kernel_id=self.kernel_id,
                                      ramdisk_id=self.ramdisk_id,
                                      root_device_name='/dev/sda1',
                                      block_device_map=bmap)
     return img_id