Partial handling for automatic conversion
With basic dictionary available, we can now do automatic conversion for direct property conversion. Still need to update to handle hierarchy. Change-Id: Idafce7cf6d6cd539c8724b64939d402497a9e074
This commit is contained in:
parent
09c98674f0
commit
7630b0443c
@ -20,6 +20,7 @@ import glob
|
||||
import json
|
||||
import os
|
||||
|
||||
from graffiti.api.model.v1.capability import Capability
|
||||
from graffiti.api.model.v1.derived_type import DerivedType
|
||||
|
||||
|
||||
@ -139,3 +140,36 @@ def get_qualifier(property_name, property_value):
|
||||
return property_dict[key2]
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def resolve_capability(key, value, target_resource,
|
||||
default_namespace=None,
|
||||
default_name=None):
|
||||
resolved_type = None
|
||||
resolved_namespace = None
|
||||
|
||||
cap_and_namespace = get_qualifier(
|
||||
key,
|
||||
value
|
||||
)
|
||||
if cap_and_namespace:
|
||||
resolved_type = cap_and_namespace.name
|
||||
resolved_namespace = cap_and_namespace.namespace
|
||||
else:
|
||||
resolved_namespace = default_namespace
|
||||
resolved_type = default_name
|
||||
|
||||
resolved_capability = None
|
||||
for capability in target_resource.capabilities:
|
||||
if capability.capability_type_namespace == resolved_namespace \
|
||||
and capability.capability_type == resolved_type:
|
||||
resolved_capability = capability
|
||||
|
||||
if not resolved_capability:
|
||||
resolved_capability = Capability()
|
||||
resolved_capability.capability_type_namespace = resolved_namespace
|
||||
resolved_capability.capability_type = resolved_type
|
||||
resolved_capability.properties = {}
|
||||
target_resource.capabilities.append(resolved_capability)
|
||||
|
||||
resolved_capability.properties[key] = value
|
||||
|
@ -16,6 +16,7 @@
|
||||
from graffiti.api.model.v1.capability import Capability
|
||||
from graffiti.api.model.v1.resource import Resource
|
||||
from graffiti.common import exception
|
||||
from graffiti.common import utils
|
||||
from graffiti.drivers import base
|
||||
|
||||
from novaclient.v1_1 import client
|
||||
@ -33,7 +34,6 @@ class NovaResourceDriver(base.ResourceInterface):
|
||||
self.endpoint_type = 'publicURL'
|
||||
self.default_namespace = "OS::COMPUTE::CPU"
|
||||
self.default_resource_type = "OS::Nova::Flavor"
|
||||
self.default_extraspec_key = "capabilities:cpu_info"
|
||||
|
||||
def get_resource(self, resource_type, resource_id, auth_token,
|
||||
endpoint_id=None, **kwargs):
|
||||
@ -202,6 +202,11 @@ class NovaResourceDriver(base.ResourceInterface):
|
||||
property_name = None
|
||||
property_value = None
|
||||
|
||||
if not key.startswith("capabilities:cpu_info"):
|
||||
utils.resolve_capability(
|
||||
key, extra_spec_keys[key], flavor_resource)
|
||||
else:
|
||||
#TODO(Facundo)This can be automatic using dictionary
|
||||
if key in extraspecs_key_map:
|
||||
capability_type, property_name, property_value = \
|
||||
extraspecs_key_map[key](key, extra_spec_keys[key])
|
||||
@ -209,40 +214,53 @@ class NovaResourceDriver(base.ResourceInterface):
|
||||
capability_type, property_name, property_value = \
|
||||
extractSimpleValue(key, extra_spec_keys[key])
|
||||
|
||||
capability_property = {property_name: property_value}
|
||||
capability = Capability()
|
||||
capability.capability_type_namespace = capability_namespace
|
||||
capability.capability_type = capability_type
|
||||
capability.properties = {property_name: property_value}
|
||||
|
||||
flavor_capability = Capability()
|
||||
flavor_capability.properties = {}
|
||||
flavor_resource.capabilities.append(capability)
|
||||
|
||||
flavor_capability.capability_type_namespace = capability_namespace
|
||||
flavor_capability.capability_type = capability_type
|
||||
flavor_capability.properties.update(capability_property)
|
||||
|
||||
flavor_resource.capabilities.append(flavor_capability)
|
||||
return flavor_resource
|
||||
|
||||
def transform_resource_to_extraspecs(self, resource):
|
||||
extraspec = {}
|
||||
for capability in resource.capabilities:
|
||||
|
||||
topology_properties = {
|
||||
"cores": "topology:cores",
|
||||
"threads": "topology:threads",
|
||||
"sockets": "topoloy:sockets",
|
||||
"sockets": "topology:sockets",
|
||||
}
|
||||
|
||||
extraspec = {}
|
||||
|
||||
for capability in resource.capabilities:
|
||||
|
||||
base_key = ""
|
||||
if capability.capability_type_namespace == self.default_namespace:
|
||||
base_key = "capabilities:cpu_info"
|
||||
|
||||
for property_name, property_value in capability.properties.items():
|
||||
for property_name, property_value \
|
||||
in capability.properties.items():
|
||||
if property_name == "features":
|
||||
key = base_key + ':' + property_name
|
||||
extraspec[key] = '<in> ' + property_value
|
||||
continue
|
||||
if property_name in topology_properties:
|
||||
key = base_key + ':' + topology_properties[property_name]
|
||||
key = base_key + ':' \
|
||||
+ topology_properties[property_name]
|
||||
extraspec[key] = property_value
|
||||
continue
|
||||
key = base_key + ':' + property_name
|
||||
extraspec[key] = property_value
|
||||
else:
|
||||
if not capability.properties:
|
||||
#if capability doesnt have properties add as TAG
|
||||
key = capability.capability_type
|
||||
extraspec[key] = utils.TAG_IDENTIFIER
|
||||
else:
|
||||
for property_name, property_value \
|
||||
in capability.properties.items():
|
||||
key = property_name
|
||||
extraspec[key] = str(property_value)
|
||||
|
||||
return extraspec
|
||||
|
Loading…
Reference in New Issue
Block a user