From d314a03a59321d2e91933d7057816eb4156028fb Mon Sep 17 00:00:00 2001 From: Madhu Mohan Nelemane Date: Mon, 14 Nov 2016 17:20:54 +0100 Subject: [PATCH] Initial commit - Heat Translator for TOSCA templates --- bin/crowbar_tosca | 21 ++++ chef/cookbooks/tosca/attributes/default.rb | 21 ++++ chef/cookbooks/tosca/metadata.rb | 24 ++++ chef/cookbooks/tosca/recipes/default.rb | 34 ++++++ .../tosca/recipes/role_tosca_parser.rb | 17 +++ .../tosca/templates/default/jetty.xml.erb | 107 ++++++++++++++++++ chef/data_bags/crowbar/template-tosca.json | 34 ++++++ chef/data_bags/crowbar/template-tosca.schema | 94 +++++++++++++++ chef/roles/tosca-parser.rb | 6 + .../barclamps/tosca/application.js | 15 +++ .../app/controllers/tosca_controller.rb | 23 ++++ .../app/helpers/barclamp/tosca_helper.rb | 20 ++++ crowbar_framework/app/models/tosca_service.rb | 55 +++++++++ .../barclamp/tosca/_edit_attributes.html.haml | 7 ++ crowbar_framework/config/locales/tosca/en.yml | 25 ++++ tosca.yml | 32 ++++++ 16 files changed, 535 insertions(+) create mode 100755 bin/crowbar_tosca create mode 100644 chef/cookbooks/tosca/attributes/default.rb create mode 100644 chef/cookbooks/tosca/metadata.rb create mode 100644 chef/cookbooks/tosca/recipes/default.rb create mode 100644 chef/cookbooks/tosca/recipes/role_tosca_parser.rb create mode 100644 chef/cookbooks/tosca/templates/default/jetty.xml.erb create mode 100644 chef/data_bags/crowbar/template-tosca.json create mode 100644 chef/data_bags/crowbar/template-tosca.schema create mode 100644 chef/roles/tosca-parser.rb create mode 100644 crowbar_framework/app/assets/javascripts/barclamps/tosca/application.js create mode 100644 crowbar_framework/app/controllers/tosca_controller.rb create mode 100644 crowbar_framework/app/helpers/barclamp/tosca_helper.rb create mode 100644 crowbar_framework/app/models/tosca_service.rb create mode 100644 crowbar_framework/app/views/barclamp/tosca/_edit_attributes.html.haml create mode 100644 crowbar_framework/config/locales/tosca/en.yml create mode 100644 tosca.yml diff --git a/bin/crowbar_tosca b/bin/crowbar_tosca new file mode 100755 index 0000000..ac1f862 --- /dev/null +++ b/bin/crowbar_tosca @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby +# +# Copyright 2016, SUSE LINUX Products GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.join(File.expand_path(File.dirname(__FILE__)), "barclamp_lib") +@barclamp = "tosca" + +main diff --git a/chef/cookbooks/tosca/attributes/default.rb b/chef/cookbooks/tosca/attributes/default.rb new file mode 100644 index 0000000..d4a01ef --- /dev/null +++ b/chef/cookbooks/tosca/attributes/default.rb @@ -0,0 +1,21 @@ +# +# Cookbook Name:: opendaylight +# Attributes:: default +# +# Copyright 2016, SUSE LINUX Products GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +default[:tosca][:verbose] = true +default[:tosca][:debug] = true diff --git a/chef/cookbooks/tosca/metadata.rb b/chef/cookbooks/tosca/metadata.rb new file mode 100644 index 0000000..f048875 --- /dev/null +++ b/chef/cookbooks/tosca/metadata.rb @@ -0,0 +1,24 @@ +# +# Copyright 2016, SUSE LINUX Products GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +maintainer "Crowbar Project" +maintainer_email "crowbar@dell.com" +license "Apache 2.0" +description "TOSCA-Template parser and translator to HOT" +long_description "" +version "0.0.1" + +recipe "tosca", "VNF Template parser for TOSCA-template and translator to HOT" diff --git a/chef/cookbooks/tosca/recipes/default.rb b/chef/cookbooks/tosca/recipes/default.rb new file mode 100644 index 0000000..3eb6309 --- /dev/null +++ b/chef/cookbooks/tosca/recipes/default.rb @@ -0,0 +1,34 @@ +# +# Cookbook Name:: opendaylight +# Recipe:: default +# +# Copyright 2016, SUSE LINUX Products GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +if node[:platform_family] == "suse" + + package "python-tosca-parser" do + owner "root" + group "root" + mode "0640" + end + + package "openstack-heat-translator" do + owner "root" + group "root" + mode "0640" + end +end + diff --git a/chef/cookbooks/tosca/recipes/role_tosca_parser.rb b/chef/cookbooks/tosca/recipes/role_tosca_parser.rb new file mode 100644 index 0000000..1be2503 --- /dev/null +++ b/chef/cookbooks/tosca/recipes/role_tosca_parser.rb @@ -0,0 +1,17 @@ +# +# Copyright 2016, SUSE LINUX GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +include_recipe "tosca::default" diff --git a/chef/cookbooks/tosca/templates/default/jetty.xml.erb b/chef/cookbooks/tosca/templates/default/jetty.xml.erb new file mode 100644 index 0000000..e7c1604 --- /dev/null +++ b/chef/cookbooks/tosca/templates/default/jetty.xml.erb @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + 300000 + 2 + false + 8543 + 20000 + 5000 + + + + + + + + + + + + + 300000 + 2 + false + 8443 + 20000 + 5000 + + + + + + + + + + + + + + + karaf + karaf + + + org.apache.karaf.jaas.boot.principal.RolePrincipal + + + + + + + + + + default + karaf + + + org.apache.karaf.jaas.boot.principal.RolePrincipal + + + + + + + + + diff --git a/chef/data_bags/crowbar/template-tosca.json b/chef/data_bags/crowbar/template-tosca.json new file mode 100644 index 0000000..f776b3e --- /dev/null +++ b/chef/data_bags/crowbar/template-tosca.json @@ -0,0 +1,34 @@ +{ + "id": "template-tosca", + "description": "TOSCA Templates for Virtual Network Functions", + "attributes": { + "tosca": { + "verbose" : true, + "debug" : true + } + }, + "deployment": { + "tosca": { + "crowbar-revision": 0, + "crowbar-applied": false, + "schema-revision": 100, + "element_states": { + "tosca": [ "readying", "ready", "applying" ] + }, + "elements": {}, + "element_order": [ + [ "tosca" ] + ], + "element_run_list_order": { + "tosca": 81 + }, + "config": { + "environment": "tosca-config-base", + "mode": "full", + "transitions": false, + "transition_list": [ + ] + } + } + } +} diff --git a/chef/data_bags/crowbar/template-tosca.schema b/chef/data_bags/crowbar/template-tosca.schema new file mode 100644 index 0000000..59c2728 --- /dev/null +++ b/chef/data_bags/crowbar/template-tosca.schema @@ -0,0 +1,94 @@ +{ + "type": "map", + "required": true, + "mapping": { + "id": { "type": "str", "required": true, "pattern": "/^tosca-|^template-tosca$/" }, + "description": { "type": "str", "required": true }, + "attributes": { + "type": "map", + "required": true, + "mapping": { + "tosca": { + "type": "map", + "required": true, + "mapping": { + "verbose": { "type": "bool", "required": false }, + "debug": { "type": "bool", "required": false } + } + } + } + }, + "deployment": { + "type": "map", + "required": true, + "mapping": { + "tosca": { + "type": "map", + "required": true, + "mapping": { + "crowbar-revision": { "type": "int", "required": true }, + "schema-revision": { "type": "int" }, + "crowbar-committing": { "type": "bool" }, + "crowbar-applied": { "type": "bool" }, + "crowbar-status": { "type": "str" }, + "crowbar-failed": { "type": "str" }, + "crowbar-queued": { "type": "bool" }, + "element_states": { + "type": "map", + "mapping": { + = : { + "type": "seq", + "required": true, + "sequence": [ { "type": "str" } ] + } + } + }, + "elements": { + "type": "map", + "required": true, + "mapping": { + = : { + "type": "seq", + "required": true, + "sequence": [ { "type": "str" } ] + } + } + }, + "element_order": { + "type": "seq", + "required": true, + "sequence": [ { + "type": "seq", + "sequence": [ { "type": "str" } ] + } ] + }, + "element_run_list_order": { + "type": "map", + "required": false, + "mapping": { + = : { + "type": "int", + "required": true + } + } + }, + "config": { + "type": "map", + "required": true, + "mapping": { + "environment": { "type": "str", "required": true }, + "mode": { "type": "str", "required": true }, + "transitions": { "type": "bool", "required": true }, + "transition_list": { + "type": "seq", + "required": true, + "sequence": [ { "type": "str" } ] + } + } + } + } + } + } + } + } +} diff --git a/chef/roles/tosca-parser.rb b/chef/roles/tosca-parser.rb new file mode 100644 index 0000000..7da065a --- /dev/null +++ b/chef/roles/tosca-parser.rb @@ -0,0 +1,6 @@ +name "tosca-parser" +description "Tosca Role - Node registered as a TOSCA-template parser" +run_list("recipe[tosca::role_tosca_parser]") +default_attributes() +override_attributes() + diff --git a/crowbar_framework/app/assets/javascripts/barclamps/tosca/application.js b/crowbar_framework/app/assets/javascripts/barclamps/tosca/application.js new file mode 100644 index 0000000..da7c20e --- /dev/null +++ b/crowbar_framework/app/assets/javascripts/barclamps/tosca/application.js @@ -0,0 +1,15 @@ +/** + * Copyright 2016, SUSE LINUX GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ diff --git a/crowbar_framework/app/controllers/tosca_controller.rb b/crowbar_framework/app/controllers/tosca_controller.rb new file mode 100644 index 0000000..0da40d3 --- /dev/null +++ b/crowbar_framework/app/controllers/tosca_controller.rb @@ -0,0 +1,23 @@ +# +# Copyright 2016, SUSE LINUX Products GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +class ToscaController < BarclampController + protected + + def initialize_service + @service_object = ToscaService.new logger + end +end diff --git a/crowbar_framework/app/helpers/barclamp/tosca_helper.rb b/crowbar_framework/app/helpers/barclamp/tosca_helper.rb new file mode 100644 index 0000000..6555a4c --- /dev/null +++ b/crowbar_framework/app/helpers/barclamp/tosca_helper.rb @@ -0,0 +1,20 @@ +# +# Copyright 2016, SUSE LINUX Products GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +module Barclamp + module ToscaHelper + end +end diff --git a/crowbar_framework/app/models/tosca_service.rb b/crowbar_framework/app/models/tosca_service.rb new file mode 100644 index 0000000..1948f86 --- /dev/null +++ b/crowbar_framework/app/models/tosca_service.rb @@ -0,0 +1,55 @@ +# +# Copyright 2016, SUSE LINUX Products GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +class ToscaService < ServiceObject + def initialize(thelogger) + super(thelogger) + @bc_name = "tosca" + end + + class << self + def role_constraints + { + "tosca" => { + "unique" => false, + "count" => -1, + "admin" => false, + "exclude_platform" => { + "windows" => "/.*/" + } + } + } + end + end + + def create_proposal + @logger.debug("tosca create_proposal: entering") + base = super + + nodes = NodeObject.all + # Don't include the admin node by default, you never know... + nodes.delete_if { |n| n.nil? or n.admin? } + + # Ignore nodes that are being discovered + base["deployment"]["tosca"]["elements"] = { + "updater" => nodes.select { |x| not ["discovering", "discovered"].include?(x.status) }.map { |x| x.name } + } + + @logger.debug("tosca create_proposal: exiting") + base + end + +end diff --git a/crowbar_framework/app/views/barclamp/tosca/_edit_attributes.html.haml b/crowbar_framework/app/views/barclamp/tosca/_edit_attributes.html.haml new file mode 100644 index 0000000..343ce83 --- /dev/null +++ b/crowbar_framework/app/views/barclamp/tosca/_edit_attributes.html.haml @@ -0,0 +1,7 @@ += attributes_for @proposal do + .panel-sub + = header show_raw_deployment?, true + + .panel-body + = boolean_field :debug + = boolean_field :verbose diff --git a/crowbar_framework/config/locales/tosca/en.yml b/crowbar_framework/config/locales/tosca/en.yml new file mode 100644 index 0000000..1efee27 --- /dev/null +++ b/crowbar_framework/config/locales/tosca/en.yml @@ -0,0 +1,25 @@ +# +# Copyright 2016, SUSE LINUX Products GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +en: + nav: + tosca: 'TOSCA Template Parser and Translator' + barclamp: + tosca: + edit_attributes: + verbose: true + debug: true + diff --git a/tosca.yml b/tosca.yml new file mode 100644 index 0000000..793d206 --- /dev/null +++ b/tosca.yml @@ -0,0 +1,32 @@ +# +# Copyright 2016, SUSE LINUX Products GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +barclamp: + name: 'tosca' + display: 'Tosca Translator Service' + description: 'TOSCA Template parser and Heat Translator' + version: 0 + user_managed: true + member: + - 'openstack' + - 'nfv' + +crowbar: + layout: 1 + order: 82 + run_order: 82 + chef_order: 82 + proposal_schema_version: 0