Пример #1
0
def translate_etcd_result(etcd_result, model_type):
    """Translate etcd unicode result to etcd models."""
    try:
        data = json.loads(etcd_result.value)
        ret = None
        if model_type == 'container':
            ret = models.Container(data)
        elif model_type == 'zun_service':
            ret = models.ZunService(data)
        elif model_type == 'image':
            ret = models.Image(data)
        elif model_type == 'resource_class':
            ret = models.ResourceClass(data)
        elif model_type == 'compute_node':
            ret = models.ComputeNode(data)
        elif model_type == 'capsule':
            ret = models.Capsule(data)
        elif model_type == 'pcidevice':
            ret = models.PciDevice(data)
        elif model_type == 'volume_mapping':
            ret = models.VolumeMapping(data)
        elif model_type == 'container_action':
            ret = models.ContainerAction(data)
        elif model_type == 'container_action_event':
            ret = models.ContainerActionEvent(data)
        else:
            raise exception.InvalidParameterValue(
                _('The model_type value: %s is invalid.'), model_type)
        return ret
    except (ValueError, TypeError) as e:
        LOG.error("Error occurred while translating etcd result: %s",
                  six.text_type(e))
        raise
Пример #2
0
    def pull_image(self, context, values):
        if not values.get('uuid'):
            values['uuid'] = uuidutils.generate_uuid()
        repo = values.get('repo')
        tag = values.get('tag')

        image = self.get_image_by_repo_and_tag(context, repo, tag)
        if image:
            raise exception.ImageAlreadyExists(repo=repo, tag=tag)

        image = models.Image(values)
        image.save()
        return image
Пример #3
0
def translate_etcd_result(etcd_result, model_type):
    """Translate etcd unicode result to etcd models."""
    try:
        data = json.loads(etcd_result.value)
        ret = None
        if model_type == 'container':
            ret = models.Container(data)
        elif model_type == 'zun_service':
            ret = models.ZunService(data)
        elif model_type == 'image':
            ret = models.Image(data)
        else:
            raise exception.InvalidParameterValue(
                _('The model_type value: %s is invalid.'), model_type)
        return ret
    except (ValueError, TypeError) as e:
        LOG.error(_LE("Error occurred while translating etcd result: %s"),
                  six.text_type(e))
        raise