Пример #1
0
 def print_status(self, roles=None):
   if roles == None:
     storage_filename = self._get_storage_filename()
     volume_manager = JsonVolumeManager(storage_filename)
     roles = volume_manager.get_roles()
   for role in roles:
     mountable_volumes_list = self._get_mountable_volumes(role)
     ec2_volumes = self._get_ec2_volumes_dict(mountable_volumes_list)
     for mountable_volumes in mountable_volumes_list:
       for mountable_volume in mountable_volumes:
         self._print_volume(role, ec2_volumes[mountable_volume.volume_id])
Пример #2
0
 def print_status(self, roles=None):
     if roles == None:
         storage_filename = self._get_storage_filename()
         volume_manager = JsonVolumeManager(storage_filename)
         roles = volume_manager.get_roles()
     for role in roles:
         mountable_volumes_list = self._get_mountable_volumes(role)
         ec2_volumes = self._get_ec2_volumes_dict(mountable_volumes_list)
         for mountable_volumes in mountable_volumes_list:
             for mountable_volume in mountable_volumes:
                 self._print_volume(role,
                                    ec2_volumes[mountable_volume.volume_id])
Пример #3
0
 def create(self, role, number_of_instances, availability_zone, spec_filename):
     spec_file = open(spec_filename, "r")
     volume_spec_manager = JsonVolumeSpecManager(spec_file)
     volume_manager = JsonVolumeManager(self._get_storage_filename())
     for dummy in range(number_of_instances):
         mountable_volumes = []
         volume_specs = volume_spec_manager.volume_specs_for_role(role)
         for spec in volume_specs:
             logger.info(
                 "Creating volume of size %s in %s from snapshot %s"
                 % (spec.size, availability_zone, spec.snapshot_id)
             )
             volume = self.cluster.ec2Connection.create_volume(spec.size, availability_zone, spec.snapshot_id)
             mountable_volumes.append(MountableVolume(volume.id, spec.mount_point, spec.device))
         volume_manager.add_instance_storage_for_role(role, mountable_volumes)
Пример #4
0
 def create(self, role, number_of_instances, availability_zone,
            spec_filename):
     spec_file = open(spec_filename, 'r')
     volume_spec_manager = JsonVolumeSpecManager(spec_file)
     volume_manager = JsonVolumeManager(self._get_storage_filename())
     for dummy in range(number_of_instances):
         mountable_volumes = []
         volume_specs = volume_spec_manager.volume_specs_for_role(role)
         for spec in volume_specs:
             logger.info("Creating volume of size %s in %s from snapshot %s" % \
                         (spec.size, availability_zone, spec.snapshot_id))
             volume = self.cluster.ec2Connection.create_volume(
                 spec.size, availability_zone, spec.snapshot_id)
             mountable_volumes.append(
                 MountableVolume(volume.id, spec.mount_point, spec.device))
         volume_manager.add_instance_storage_for_role(
             role, mountable_volumes)
Пример #5
0
 def delete(self, roles=[]):
   storage_filename = self._get_storage_filename()
   volume_manager = JsonVolumeManager(storage_filename)
   for role in roles:
     mountable_volumes_list = volume_manager.get_instance_storage_for_role(role)
     ec2_volumes = self._get_ec2_volumes_dict(mountable_volumes_list)
     all_available = True
     for volume in ec2_volumes.itervalues():
       if volume.status != 'available':
         all_available = False
         logger.warning("Volume %s is not available.", volume)
     if not all_available:
       logger.warning("Some volumes are still in use for role %s.\
         Aborting delete.", role)
       return
     for volume in ec2_volumes.itervalues():
       volume.delete()
     volume_manager.remove_instance_storage_for_role(role)
Пример #6
0
 def delete(self, roles=[]):
     storage_filename = self._get_storage_filename()
     volume_manager = JsonVolumeManager(storage_filename)
     for role in roles:
         mountable_volumes_list = volume_manager.get_instance_storage_for_role(
             role)
         ec2_volumes = self._get_ec2_volumes_dict(mountable_volumes_list)
         all_available = True
         for volume in ec2_volumes.itervalues():
             if volume.status != 'available':
                 all_available = False
                 logger.warning("Volume %s is not available.", volume)
         if not all_available:
             logger.warning(
                 "Some volumes are still in use for role %s.\
       Aborting delete.", role)
             return
         for volume in ec2_volumes.itervalues():
             volume.delete()
         volume_manager.remove_instance_storage_for_role(role)
Пример #7
0
 def get_roles(self):
   storage_filename = self._get_storage_filename()
   volume_manager = JsonVolumeManager(storage_filename)
   return volume_manager.get_roles()
Пример #8
0
 def _get_mountable_volumes(self, role):
   storage_filename = self._get_storage_filename()
   volume_manager = JsonVolumeManager(storage_filename)
   return volume_manager.get_instance_storage_for_role(role)
Пример #9
0
    def test_add_instance_storage_for_role(self):
        volume_manager = JsonVolumeManager("volumemanagertest.json")
        self.assertEqual(
            0, len(volume_manager.get_instance_storage_for_role("master")))
        self.assertEqual(0, len(volume_manager.get_roles()))

        volume_manager.add_instance_storage_for_role(
            "master", [MountableVolume("vol_1", "/", "/dev/sdj")])
        master_storage = volume_manager.get_instance_storage_for_role("master")
        self.assertEqual(1, len(master_storage))
        master_storage_instance0 = master_storage[0]
        self.assertEqual(1, len(master_storage_instance0))
        master_storage_instance0_vol0 = master_storage_instance0[0]
        self.assertEqual("vol_1", master_storage_instance0_vol0.volume_id)
        self.assertEqual("/", master_storage_instance0_vol0.mount_point)
        self.assertEqual("/dev/sdj", master_storage_instance0_vol0.device)

        volume_manager.add_instance_storage_for_role(
            "slave", [MountableVolume("vol_2", "/", "/dev/sdj")])
        self.assertEqual(
            1, len(volume_manager.get_instance_storage_for_role("master")))
        slave_storage = volume_manager.get_instance_storage_for_role("slave")
        self.assertEqual(1, len(slave_storage))
        slave_storage_instance0 = slave_storage[0]
        self.assertEqual(1, len(slave_storage_instance0))
        slave_storage_instance0_vol0 = slave_storage_instance0[0]
        self.assertEqual("vol_2", slave_storage_instance0_vol0.volume_id)
        self.assertEqual("/", slave_storage_instance0_vol0.mount_point)
        self.assertEqual("/dev/sdj", slave_storage_instance0_vol0.device)

        volume_manager.add_instance_storage_for_role("slave", [
            MountableVolume("vol_3", "/", "/dev/sdj"),
            MountableVolume("vol_4", "/data1", "/dev/sdk")
        ])
        self.assertEqual(
            1, len(volume_manager.get_instance_storage_for_role("master")))
        slave_storage = volume_manager.get_instance_storage_for_role("slave")
        self.assertEqual(2, len(slave_storage))
        slave_storage_instance0 = slave_storage[0]
        slave_storage_instance1 = slave_storage[1]
        self.assertEqual(1, len(slave_storage_instance0))
        self.assertEqual(2, len(slave_storage_instance1))
        slave_storage_instance1_vol0 = slave_storage_instance1[0]
        slave_storage_instance1_vol1 = slave_storage_instance1[1]
        self.assertEqual("vol_3", slave_storage_instance1_vol0.volume_id)
        self.assertEqual("/", slave_storage_instance1_vol0.mount_point)
        self.assertEqual("/dev/sdj", slave_storage_instance1_vol0.device)
        self.assertEqual("vol_4", slave_storage_instance1_vol1.volume_id)
        self.assertEqual("/data1", slave_storage_instance1_vol1.mount_point)
        self.assertEqual("/dev/sdk", slave_storage_instance1_vol1.device)

        roles = volume_manager.get_roles()
        self.assertEqual(2, len(roles))
        self.assertTrue("slave" in roles)
        self.assertTrue("master" in roles)
Пример #10
0
    def test_add_instance_storage_for_role(self):
        volume_manager = JsonVolumeManager("volumemanagertest.json")
        self.assertEqual(0, len(volume_manager.get_instance_storage_for_role("master")))
        self.assertEqual(0, len(volume_manager.get_roles()))

        volume_manager.add_instance_storage_for_role("master", [MountableVolume("vol_1", "/", "/dev/sdj")])
        master_storage = volume_manager.get_instance_storage_for_role("master")
        self.assertEqual(1, len(master_storage))
        master_storage_instance0 = master_storage[0]
        self.assertEqual(1, len(master_storage_instance0))
        master_storage_instance0_vol0 = master_storage_instance0[0]
        self.assertEqual("vol_1", master_storage_instance0_vol0.volume_id)
        self.assertEqual("/", master_storage_instance0_vol0.mount_point)
        self.assertEqual("/dev/sdj", master_storage_instance0_vol0.device)

        volume_manager.add_instance_storage_for_role("slave", [MountableVolume("vol_2", "/", "/dev/sdj")])
        self.assertEqual(1, len(volume_manager.get_instance_storage_for_role("master")))
        slave_storage = volume_manager.get_instance_storage_for_role("slave")
        self.assertEqual(1, len(slave_storage))
        slave_storage_instance0 = slave_storage[0]
        self.assertEqual(1, len(slave_storage_instance0))
        slave_storage_instance0_vol0 = slave_storage_instance0[0]
        self.assertEqual("vol_2", slave_storage_instance0_vol0.volume_id)
        self.assertEqual("/", slave_storage_instance0_vol0.mount_point)
        self.assertEqual("/dev/sdj", slave_storage_instance0_vol0.device)

        volume_manager.add_instance_storage_for_role(
            "slave", [MountableVolume("vol_3", "/", "/dev/sdj"), MountableVolume("vol_4", "/data1", "/dev/sdk")]
        )
        self.assertEqual(1, len(volume_manager.get_instance_storage_for_role("master")))
        slave_storage = volume_manager.get_instance_storage_for_role("slave")
        self.assertEqual(2, len(slave_storage))
        slave_storage_instance0 = slave_storage[0]
        slave_storage_instance1 = slave_storage[1]
        self.assertEqual(1, len(slave_storage_instance0))
        self.assertEqual(2, len(slave_storage_instance1))
        slave_storage_instance1_vol0 = slave_storage_instance1[0]
        slave_storage_instance1_vol1 = slave_storage_instance1[1]
        self.assertEqual("vol_3", slave_storage_instance1_vol0.volume_id)
        self.assertEqual("/", slave_storage_instance1_vol0.mount_point)
        self.assertEqual("/dev/sdj", slave_storage_instance1_vol0.device)
        self.assertEqual("vol_4", slave_storage_instance1_vol1.volume_id)
        self.assertEqual("/data1", slave_storage_instance1_vol1.mount_point)
        self.assertEqual("/dev/sdk", slave_storage_instance1_vol1.device)

        roles = volume_manager.get_roles()
        self.assertEqual(2, len(roles))
        self.assertTrue("slave" in roles)
        self.assertTrue("master" in roles)
Пример #11
0
 def get_roles(self):
     storage_filename = self._get_storage_filename()
     volume_manager = JsonVolumeManager(storage_filename)
     return volume_manager.get_roles()
Пример #12
0
 def _get_mountable_volumes(self, role):
     storage_filename = self._get_storage_filename()
     volume_manager = JsonVolumeManager(storage_filename)
     return volume_manager.get_instance_storage_for_role(role)