Commit 449ba19a authored by Spiros Koulouzis's avatar Spiros Koulouzis

set cloud storm interfaces

parent 0ff9c39b
artifact_types: null
capability_types: null
data_types: null
description: null
dsl_definitions: null
group_types: null
imports:
- nodes: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/nodes.yaml
- capabilities: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/capabilities.yaml
- policies: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/policies.yaml
- interfaces: https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/types/interfaces.yml
interface_types: null
node_types: null
policy_types: null
relationship_templates: null
relationship_types: null
repositories: null
template_author: null
template_name: null
template_version: null
topology_template:
description: null
groups: null
inputs: null
node_templates:
compute:
interfaces:
Standard:
create: dumy.yaml
properties:
disk_size: 50000 MB
mem_size: 6000 MB
num_cores: 2
os: ubuntu 14.04
type: tosca.nodes.ARTICONF.VM.Compute
compute_1:
interfaces:
Standard:
create: dumy.yaml
properties:
disk_size: 50000 MB
mem_size: 6000 MB
num_cores: 2
os: ubuntu 14.04
type: tosca.nodes.ARTICONF.VM.Compute
compute_2:
interfaces:
Standard:
create: dumy.yaml
properties:
disk_size: 50000 MB
mem_size: 6000 MB
num_cores: 2
os: ubuntu 14.04.04
type: tosca.nodes.ARTICONF.VM.Compute
kubernetes:
interfaces:
Standard:
create: interfaces/playbooks/kubernetes_install.yaml
properties:
min_masters_num: 1
min_workers_num: 1
requirements:
- host:
capability: tosca.capabilities.ARTICONF.VM.topology
node: topology
relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Orchestrator.Kubernetes
logspout:
artifacts:
image:
file: gliderlabs/logspout:latest
repository: docker_hub
type: tosca.artifacts.Deployment.Image.Container.Docker
properties:
environment:
publish: 127.0.0.1:8000:80
ports:
- 8000:80
volumes:
- /etc/hostname:/etc/host_hostname:ro
- /var/run/docker.sock:/var/run/docker.sock
requirements:
- host:
capability: tosca.capabilities.ARTICONF.Orchestrator
node: kubernetes
relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Container.Application.Docker
mysql:
artifacts:
image:
file: mysql:5.7
repository: docker_hub
type: tosca.artifacts.Deployment.Image.Container.Docker
properties:
environment:
MYSQL_DATABASE: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_USER: wordpress
ports:
- 3306:3306
volumes:
- db_data:/var/lib/mysql
requirements:
- host:
capability: tosca.capabilities.ARTICONF.Orchestrator
node: kubernetes
relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Container.Application.Docker
topology:
attributes:
credential:
cloud_provider_name: ExoGeni
keys:
key1: eeeeeeavovfouirveiuvbepuyb8rwqovd8boacbdbvwy8oqry7f08r3euadinanzxcjc078yn0183xoqedw
protocol: protocol
token: ijwbfciweubfriw
token_type: passwrd
user: user
interfaces:
CloudsStorm:
provision:
inputs:
- code_type: SEQ
- object_type: SubTopology
- objects:
- subtopology
- command: null
- options: null
- count: null
- duration: null
- deadline: null
properties:
domain: UvA (Amsterdam, The Netherlands) XO Rack
provider: ExoGeni
requirements:
- vm:
capability: tosca.capabilities.ARTICONF.VM
node: compute
relationship: tosca.relationships.DependsOn
- vm:
capability: tosca.capabilities.ARTICONF.VM
node: compute_1
relationship: tosca.relationships.DependsOn
type: tosca.nodes.ARTICONF.VM.topology
topology_1:
attributes:
credential:
cloud_provider_name: ExoGeni
keys:
key1: eeeeeeavovfouirveiuvbepuyb8rwqovd8boacbdbvwy8oqry7f08r3euadinanzxcjc078yn0183xoqedw
protocol: protocol
token: ijwbfciweubfriw
token_type: passwrd
user: user
interfaces:
tosca.interfaces.ARTICONF.CloudsStorm:
provision:
inputs:
- code_type: SEQ
- object_type: SubTopology
- objects:
- subtopology
- command: null
- options: null
- count: null
- duration: null
- deadline: null
properties:
domain: UNC BEN (Chapel Hill, NC USA)
provider: ExoGeni
requirements:
- vm:
capability: tosca.capabilities.ARTICONF.VM
node: compute_2
relationship: tosca.relationships.DependsOn
type: tosca.nodes.ARTICONF.VM.topology
wordpress:
artifacts:
image:
file: wordpress:latest
repository: docker_hub
type: tosca.artifacts.Deployment.Image.Container.Docker
properties:
environment:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_USER: wordpress
ports:
- 8000:80
requirements:
- service:
node: mysql
relationship:
type: tosca.relationships.DependsOn
- host:
capability: tosca.capabilities.ARTICONF.Orchestrator
node: kubernetes
relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Container.Application.Docker
outputs:
private_ip_compute:
description: "The private IP address of the application\u2019s first tier."
value:
get_attribute:
- compute
- private_ip
private_ip_compute_1:
description: "The private IP address of the application\u2019s second tier."
value:
get_attribute:
- compute_1
- private_ip
private_ip_compute_2:
description: "The private IP address of the application\u2019s second tier."
value:
get_attribute:
- compute_2
- private_ip
policies:
- scalability:
properties:
constraint_name: cpu_load
max_value: 90
targets:
- wordpress
type: tosca.policies.ARTICONF.Performance.CPU
- faultTolerance:
properties:
level: 1
targets:
- mysql
type: tosca.policies.ARTICONF.FaultTolerance
relationship_templates: null
substitution_mappings: null
tosca_default_namespace: null
tosca_definitions_version: tosca_simple_yaml_1_0
...@@ -117,8 +117,11 @@ node_types: ...@@ -117,8 +117,11 @@ node_types:
type: tosca.datatypes.ARTICONF.Credential type: tosca.datatypes.ARTICONF.Credential
required: false required: false
interfaces: interfaces:
Standard: tosca.interfaces.ARTICONF.CloudsStorm:
create: dumy.yaml provision:
inputs:
- code_type: SEQ
- object_type: SubTopology
tosca.nodes.ARTICONF.VM.Compute: tosca.nodes.ARTICONF.VM.Compute:
derived_from: tosca.nodes.ARTICONF.Infrastructure derived_from: tosca.nodes.ARTICONF.Infrastructure
......
...@@ -219,12 +219,7 @@ public class ToscaHelper { ...@@ -219,12 +219,7 @@ public class ToscaHelper {
return toscaTemplate; return toscaTemplate;
} }
public NodeTemplateMap setProvisionerInterfaceInVMTopology(NodeTemplateMap vmTopologyMap, Provisioner provisioner, String operation) throws ApiException { public NodeTemplateMap setProvisionerInterfaceInVMTopology(NodeTemplateMap vmTopologyMap, Map<String, Object> provisionInterface) throws ApiException {
List<String> toscaInterfaceTypes = new ArrayList<>();
toscaInterfaceTypes.add(provisioner.getToscaInterfaceType());
List<Map<String, Object>> definitions = getProvisionInterfaceDefinitions(toscaInterfaceTypes);
Map<String, Object> definition = getBestProvisionInterfaceDefinition(definitions);
Map<String, Object> provisionInterface = getProvisionInterfaceInstance(definition, operation);
vmTopologyMap.getNodeTemplate().setInterfaces(provisionInterface); vmTopologyMap.getNodeTemplate().setInterfaces(provisionInterface);
return vmTopologyMap; return vmTopologyMap;
} }
...@@ -238,11 +233,19 @@ public class ToscaHelper { ...@@ -238,11 +233,19 @@ public class ToscaHelper {
return null; return null;
} }
private Map<String, Object> getProvisionInterfaceInstance(Map<String, Object> definition, String operation) throws ApiException { private Map<String, Object> getProvisionInterfaceInstanceDefaultValues(Map<String, Object> definition, String operation) throws ApiException {
String type = definition.keySet().iterator().next(); String type = definition.keySet().iterator().next();
String[] typeArray = type.split("\\."); String[] typeArray = type.split("\\.");
Map<String, Object> provisionInterface = api.getDefaultInterface(String.valueOf(id), type, typeArray[typeArray.length - 1].toLowerCase(), operation); Map<String, Object> provisionInterface = api.getDefaultInterface(String.valueOf(id), type, typeArray[typeArray.length - 1], operation);
return provisionInterface; return provisionInterface;
} }
public Map<String, Object> getProvisionInterface(Provisioner provisioner, String operation) throws ApiException {
List<String> toscaInterfaceTypes = new ArrayList<>();
toscaInterfaceTypes.add(provisioner.getToscaInterfaceType());
List<Map<String, Object>> definitions = getProvisionInterfaceDefinitions(toscaInterfaceTypes);
Map<String, Object> definition = getBestProvisionInterfaceDefinition(definitions);
Map<String, Object> provisionInterface = getProvisionInterfaceInstanceDefaultValues(definition, operation);
return provisionInterface;
}
} }
...@@ -179,7 +179,7 @@ public class ToscaHelperTest { ...@@ -179,7 +179,7 @@ public class ToscaHelperTest {
* @throws java.lang.Exception * @throws java.lang.Exception
*/ */
@Test @Test
public void testSetCredentialsInVMTopology() throws Exception { public void testSetCredentialsAndInterface() throws Exception {
if (serviceUp) { if (serviceUp) {
toscaTemplateWithCredentials = null; toscaTemplateWithCredentials = null;
...@@ -221,13 +221,28 @@ public class ToscaHelperTest { ...@@ -221,13 +221,28 @@ public class ToscaHelperTest {
vmTopologies = instance.getVMTopologyTemplates(); vmTopologies = instance.getVMTopologyTemplates();
ToscaTemplate toscaTemplateWithInterface = null; ToscaTemplate toscaTemplateWithInterface = null;
Provisioner provisioner = new Provisioner();
provisioner.setName("CloudsStorm");
provisioner.setDescription("Interface for VM topology management with CloudsStorm. More at https://cloudsstorm.github.io/");
provisioner.setToscaInterfaceType("tosca.interfaces.ARTICONF.CloudsStorm");
String operation = "provision";
for (NodeTemplateMap vmTopologyMap : vmTopologies) { for (NodeTemplateMap vmTopologyMap : vmTopologies) {
Provisioner provisioner = new Provisioner();
provisioner.setName("CloudsStorm"); Map<String, Object> provisionInterface = instance.getProvisionInterface(provisioner, operation);
provisioner.setDescription("Interface for VM topology management with CloudsStorm. More at https://cloudsstorm.github.io/"); List<String> objects = new ArrayList<>();
provisioner.setToscaInterfaceType("tosca.interfaces.ARTICONF.CloudsStorm"); objects.add("subtopology");
String operation = "provision"; String key = provisionInterface.keySet().iterator().next();
vmTopologyMap = instance.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisioner, operation); Map<String, Object> provisionOperation = (Map<String, Object>) provisionInterface.get(key);
Map<String, Object> operationMap = (Map<String, Object>) provisionOperation.get(operation);
List<Map<String, Object>> inputs = (List<Map<String, Object>>) operationMap.get("inputs");
for (Map<String, Object> input : inputs) {
if (input.containsKey("objects")) {
input.put("objects", objects);
break;
}
}
vmTopologyMap = instance.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisionInterface);
toscaTemplateWithInterface = instance.setVMTopologyInToscaTemplate(toscaTemplate, vmTopologyMap); toscaTemplateWithInterface = instance.setVMTopologyInToscaTemplate(toscaTemplate, vmTopologyMap);
} }
instance.uploadToscaTemplate(toscaTemplateWithInterface); instance.uploadToscaTemplate(toscaTemplateWithInterface);
......
...@@ -88,19 +88,20 @@ def purge_all_tables(): ...@@ -88,19 +88,20 @@ def purge_all_tables():
def save(file): def save(file):
try: # try:
# tosca_template_file_path = os.path.join(db_dir_path, file.filename) # tosca_template_file_path = os.path.join(db_dir_path, file.filename)
purge_all_tables() purge_all_tables()
dictionary = yaml.safe_load(file.stream) dictionary = yaml.safe_load(file.stream)
print(yaml.dump(dictionary)) print(yaml.dump(dictionary))
tosca_template = ToscaTemplate(yaml_dict_tpl=copy.deepcopy(dictionary)) tosca_template = ToscaTemplate(yaml_dict_tpl=copy.deepcopy(dictionary))
tosca_template_model = ToscaTemplateModel.from_dict(dictionary) # all_custom_def = tosca_template.nodetemplates[0].custom_def
doc_id = tosca_templates_db.insert(dictionary) tosca_template_model = ToscaTemplateModel.from_dict(dictionary)
# tosca_templates_db.close() doc_id = tosca_templates_db.insert(dictionary)
return doc_id # tosca_templates_db.close()
except Exception as e: return doc_id
logging.error(str(e)) # except Exception as e:
return str(e), 400 # logging.error(str(e))
# return str(e), 400
def get_interface_types(id, interface_type=None): def get_interface_types(id, interface_type=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment