Beispiel #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
Beispiel #2
0
Datei: api.py Projekt: zwphit/zun
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)
        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
Beispiel #3
0
 def create_resource_class(self, context, values):
     resource_class = models.ResourceClass(values)
     resource_class.save()
     return resource_class