Esempio n. 1
0
    def _execute(self):
        resource_ids = []
        tags = []
        try:

            for param, value in self.parameters.iteritems():
                if param.startswith('ResourceId'):
                    resource_ids.append(value)
                elif param.startswith('Tag.') and param.endswith('Key'):
                    tag_value = self.parameters.get('Tag.' + param[4:-4] +
                                                    '.Value')
                    if value != 'Name':
                        raise InvalidParameterValue
                    if not tag_value:
                        raise MissingParameter(parameter='Tag.' + param[4:-4] +
                                               '.Value')
                    tags.append({'Name': tag_value})
        except KeyError:
            raise MissingParameter(parameter='ImageId')  # TODO
        except ValueError:
            raise InvalidAMIID.Malformed

        for resource in resource_ids:
            if resource.startswith('vol-'):
                for tag in tags:
                    try:
                        volume = self.cluster_manager.user.storage_image.get_by_id(
                            {'storage_image_id': resource[4:]})
                    except CLMException, error:
                        raise InvalidVolume.NotFound

                    self.cluster_manager.user.storage_image.edit({
                        'storage_image_id':
                        resource[4:],
                        'name':
                        tag['Name'],
                        'description':
                        volume['description'],
                        'disk_controller':
                        volume['disk_controller']
                    })
            elif resource.startswith('i-'):
                for tag in tags:
                    try:
                        instance = self.cluster_manager.user.vm.get_by_id(
                            {'vm_id': resource[2:]})
                    except CLMException, error:
                        raise InvalidInstanceID.NotFound(image_id=resource)

                    self.cluster_manager.user.vm.edit({
                        'vm_id':
                        resource[2:],
                        'name':
                        tag['Name'],
                        'description':
                        instance['description']
                    })
Esempio n. 2
0
    def _execute(self):
        resourceIds = parseSequenceArguments(self.parameters, 'ResourceId.')
        tagNames = parseSequenceArguments(self.parameters, 'Tag.', '.Key')
        tagValue = self.parameters.get('Tag.0.Value')

        if not resourceIds:
            raise MissingParameter(parameter='ResourceId.X')

        if not tagNames:
            raise MissingParameter(parameter='Tag.X.Key')

        if len(tagNames) != 1:
            raise InvalidFilter

        if tagNames[0] != 'Name':
            raise InvalidFilter

        # here we have only one tag called Name
        # TODO checking if tagValue was given
        for resource in resourceIds:

            if resource.startswith('i-'):
                instance_id = parseID(resource, Entity.instance)
                if not instance_id:
                    raise InvalidInstanceID.Malformed
                try:
                    instance = self.cluster_manager.user.vm.get_by_id(
                        {'vm_id': instance_id})
                except CLMException, error:
                    raise InvalidInstanceID.NotFound(image_id=instance_id)

                if tagValue and tagValue != 'i-' + instance['vm_id']:
                    continue
                self.cluster_manager.user.vm.edit({
                    'vm_id':
                    instance_id,
                    'name':
                    'i-' + instance_id,
                    'description':
                    instance['description']
                })

            elif resource.startswith('vol-'):
                volume_id = parseID(resource, Entity.volume)
                if not volume_id:
                    raise InvalidVolumeID.Malformed

                try:
                    volume = self.cluster_manager.user.storage_image.get_by_id(
                        {'storage_image_id': volume_id})
                except CLMException, error:
                    raise InvalidVolume.NotFound()
Esempio n. 3
0
    def __new__(cls, parameters, cluster_manager):
        """Return an object of a concrete EC2 action class.

        Args:
            parameters <dict> of the action
            cluster_manager <ClusterManager> the action will be run at
        """
        if cls == Action:
            try:
                action = parameters['Action']
            except KeyError:
                raise MissingParameter(parameter='Action')

            found = False
            for concrete_class in cls.__subclasses__():
                if concrete_class.__name__ == action:
                    found = True
                    break
            if not found:
                raise InvalidAction(action=action)
        else:
            concrete_class = cls
        action = super(Action, cls).__new__(concrete_class, parameters,
                                            cluster_manager)
        return action
Esempio n. 4
0
 def _execute(self):
     import base64
     try:
         key_name = self.parameters['KeyName']
         id_rsa_pub = base64.b64decode(self.parameters['PublicKeyMaterial'])
     except KeyError, error:
         raise MissingParameter(parameter=error.args[0])
Esempio n. 5
0
 def _execute(self):
     try:
         volume_id = self.parameters['VolumeId']
         volume_id = parseID(volume_id, Entity.volume)
         if not volume_id:
             raise InvalidParameterValue
         volume_id = int(volume_id)
     except KeyError, error:
         raise MissingParameter(parameter=error.args[0])
Esempio n. 6
0
    def _execute(self):
        try:
            instance_id = parseID(self.parameters['InstanceId'], Entity.instance)
            if not instance_id:
                raise InvalidParameterValue
            instance_id = int(instance_id)

            public_ip = self.parameters['PublicIp']
        except KeyError, error:
            raise MissingParameter(parameter=error.args[0])
Esempio n. 7
0
    def _execute(self):
        try:
            image_id = self.parameters['ImageId']
            image_id = parseID(image_id, Entity.image)
            if not image_id:
                raise InvalidAMIID.Malformed

            image_id = int(image_id)
        except KeyError:
            raise MissingParameter(parameter='ImageId')
        except ValueError:
            raise InvalidAMIID.Malformed

        instance_type = self.parameters.get('InstanceType', 'm1.small')
        key_name = self.parameters.get('KeyName')
        user_data = self.parameters.get('UserData', None)

        template_id = None
        for template in self.cluster_manager.user.template.get_list():
            if template.get('ec2name') == ec2names.get(instance_type):
                dir(template)
                template_id = int(template['template_id'])
                break

        machine = {
            'count': int(self.parameters.get('MinCount', 1)),
            'description': 'created by EC2 API',
            'image_id': image_id,
            'name': 'noname',
            'template_id': template_id if template_id is not None else 1,
            'public_ip_id': None,
            'iso_list': None,
            'disk_list': None,
            'vnc': None,
            'user_data': user_data
        }

        if key_name:
            try:
                key = self.cluster_manager.user.key.get({'name': key_name})
            except CLMException, error:
                if error.status == 'ssh_key_get':
                    raise InvalidKeyPair.NotFound(key_name=key_name)
            machine['ssh_key'] = key['data']
            machine['ssh_username'] = '******'
Esempio n. 8
0
    def _execute(self):
        try:
            try:
                volume_id_ec2 = self.parameters['VolumeId']
                volume_id = parseID(volume_id_ec2, Entity.volume)
                if not volume_id:
                    raise InvalidParameterValue
                volume_id = int(volume_id)
            except KeyError, error:
                raise InvalidVolumeID.Malformed

            try:
                instance_id_ec2 = self.parameters['InstanceId']
                instance_id = parseID(instance_id_ec2, Entity.instance)
                if not instance_id:
                    raise InvalidParameterValue
                instance_id = int(instance_id)
            except KeyError, error:
                raise MissingParameter(parameter=error.args[0])
Esempio n. 9
0
    def _execute(self):
        try:
            volume_id = self.parameters['VolumeId']
            volume_id = parseID(volume_id, Entity.volume)
            if not volume_id:
                raise InvalidParameterValue
            volume_id = int(volume_id)
        except KeyError:
            raise MissingParameter(parameter='VolumeId')
        except ValueError:
            raise InvalidVolumeID.Malformed(image_id=volume_id)

        try:
            self.cluster_manager.user.storage_image.delete({'storage_image_id' : volume_id})
        except CLMException, error:
            if error.status == 'image_get' or error.status == 'image_permission':
                raise InvalidVolume.NotFound
            if error.status == 'image_attached':
                raise VolumeInUse
            raise UndefinedError
Esempio n. 10
0
    def _execute(self):
        try:
            image_id = parseID(self.parameters['ImageId'], Entity.image)
            if not image_id:
                raise InvalidParameterValue
            image_id = int(image_id)
        except KeyError:
            raise MissingParameter(parameter='ImageId')
        except ValueError:
            raise InvalidAMIID.Malformed

        try:
            none = self.cluster_manager.user.system_image.delete(
                {'system_image_id': image_id})
        except CLMException, error:
            if error.status == 'image_get' or error.status == 'image_unavailable':
                raise InvalidAMIID.NotFound(image_id=image_id)
            if error.status == 'image_delete':
                raise InternalError
            raise UndefinedError
Esempio n. 11
0
    def _execute(self):
        try:
            instances = parseSequenceArguments(self.parameters, 'InstanceId.')
            if not instances:
                raise MissingParameter(parameter='InstanceId')
            instances = parseIDs(instances, Entity.instance)
            if not instances:
                raise InvalidParameterValue
            # nie powinno się tutaj rzutować na inta?
        except ValueError:
            raise InvalidInstanceID.Malformed(
                image_id=0)  # TODO wykrywanie który instance jest zly

        try:
            none = self.cluster_manager.user.vm.reset({'vm_ids': instances})
        except CLMException, error:
            if error.status == 'user_permission' or error.status == 'vm_get':
                raise InvalidInstanceID.NotFound(
                    image_id=0)  # TODO wykrywanie która dokładnie to instancja
            print error.status
            raise InternalError
Esempio n. 12
0
    def _execute(self):
        try:
            public_ip = unicode(self.parameters['PublicIp'])
        except KeyError:
            raise MissingParameter(parameter='PublicIp')
        print type(public_ip)

        addresses = self.cluster_manager.user.public_ip.get_list()

        return_address = {}
        return_address['address'] = -1
        for address in addresses :
            if address.get('address') == public_ip:
                return_address = address

        if return_address['address'] == -1:
            raise InvalidAddress.NotFound

        # TODO sprawdzic czy tu nie trzeba sprawdzac wyjatkow
        none = self.cluster_manager.user.public_ip.release({'public_ip_id':return_address['public_ip_id']})

        return None
Esempio n. 13
0
    def _execute(self):
        instance_ids = []
        for param, value in self.parameters.iteritems():
            if param.startswith('InstanceId'):
                try:
                    value = parseID(value, Entity.instance)
                    if not value:
                        raise InvalidParameterValue
                    instance_ids.append(int(value))
                except ValueError:
                    raise InvalidInstanceID.Malformed(image_id=value)
        if not instance_ids:
            raise MissingParameter(parameter='InstanceId')

        try:
            none = self.cluster_manager.user.vm.destroy(
                {'vm_ids': instance_ids})
        except CLMException, error:
            if error.status == 'vm_get' or error.status == 'user_permission':
                raise InvalidInstanceID.NotFound(
                    image_id=0)  # TODO wykrywanie który instance jest zly
            print error.status
            raise InternalError  # destroy should throw no exception, however, we check and raise InternalError just in case
Esempio n. 14
0
 def _execute(self):
     try:
         key_name = self.parameters['KeyName']
     except KeyError, error:
         raise MissingParameter(parameter=error.args[0])
Esempio n. 15
0
 def _execute(self):
     try:
         size = int(self.parameters['Size']);
     except KeyError, error:
         raise MissingParameter(parameter=error.args[0])
Esempio n. 16
0
def merge_and_upload(cluster_manager, parameters):
    try:
        manifest_url = parameters['ImageLocation']
    except KeyError, e:
        raise MissingParameter(parameter=e.message)
Esempio n. 17
0
 def _execute(self):
     try:
         public_ip = self.parameters['PublicIp']
     except KeyError, error:
         raise MissingParameter(parameter=error.args[0])