From 4a9d6b863d1c77af21a1c5ea278c8cba3386a45f Mon Sep 17 00:00:00 2001 From: Feng Pan Date: Fri, 28 Apr 2017 17:35:57 -0400 Subject: Add support for interface role mapping Change-Id: I88a01914304f5e32840810c03646d9cda1ae7fff Signed-off-by: Feng Pan --- manifests/honeycomb.pp | 27 ++++++++++++++--- manifests/honeycomb/configure_role_mappings.pp | 40 ++++++++++++++++++++++++++ spec/acceptance/fdio_spec.rb | 2 +- templates/honeycomb.json.erb | 4 +-- 4 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 manifests/honeycomb/configure_role_mappings.pp diff --git a/manifests/honeycomb.pp b/manifests/honeycomb.pp index 6ea88b5..25739f2 100644 --- a/manifests/honeycomb.pp +++ b/manifests/honeycomb.pp @@ -39,6 +39,14 @@ # (optional) Node ID for binding VPP to Opendaylight # Defaults to $::fqdn # +# [*interface_role_map*] +# (optional) List of interface role mapping in the format +# of : +# Example: +# [ 'GigabitEthernet0/5/0:public-interface', +# 'GigabitEthernet0/6/0:tenant-interface' ] +# Defaults to undef +# class fdio::honeycomb ( $opendaylight_ip = '', $opendaylight_port = '8081', @@ -50,8 +58,11 @@ class fdio::honeycomb ( $password = 'admin', $bind_ip = '127.0.0.1', $node_id = $::fqdn, + $interface_role_map = [], ) { + validate_array($interface_role_map) + include ::fdio package { 'honeycomb': @@ -91,15 +102,23 @@ class fdio::honeycomb ( tries => 5, try_sleep => 30, path => '/usr/sbin:/usr/bin:/sbin:/bin', - notify => Service['honeycomb'], - } - + require => Service['honeycomb'], + }-> exec { 'Check VPP was mounted into ODL operational DS': command => "curl --fail -u ${opendaylight_username}:${opendaylight_password} ${oper_mount_url} | grep ${node_id}", tries => 5, try_sleep => 30, path => '/usr/sbin:/usr/bin:/sbin:/bin', - subscribe => Service['honeycomb'], + } + + if !empty($interface_role_map) { + configure_role_mappings { $interface_role_map: + honeycomb_username => $user, + honeycomb_password => $password, + honeycomb_url => "http://${bind_ip}:${rest_port}", + require => Service['honeycomb'], + before => Exec['VPP Mount into ODL'], + } } } } diff --git a/manifests/honeycomb/configure_role_mappings.pp b/manifests/honeycomb/configure_role_mappings.pp new file mode 100644 index 0000000..826f6e6 --- /dev/null +++ b/manifests/honeycomb/configure_role_mappings.pp @@ -0,0 +1,40 @@ +# == Define: fdio::honeycomb::configure_role_mappings +# +# Defined type to configure interface role mapping in OpenDaylight +# +# === Parameters: +# [*honeycomb_username*] +# User name for Honeycomb. +# +# [*honeycomb_password*] +# Password for Honeycomb. +# +# [*honeycomb_url*] +# Honeycomb restconf binding URL. +# +# [*interface_role_mapping*] +# List of interface role mapping in the format +# of : +# Example: +# [ 'GigabitEthernet0/5/0:public-interface', +# 'GigabitEthernet0/6/0:tenant-interface' ] +# +define fdio::honeycomb::configure_role_mappings ( + $honeycomb_username, + $honeycomb_password, + $honeycomb_url, + $interface_role_mapping = $title, +) { + $mapping = split($interface_role_mapping, ':') + $vpp_int = regsubst($mapping[0], '/', '%2F', 'G') + $role_name = $mapping[1] + $config_url = "${honeycomb_url}/restconf/config/ietf-interfaces:interfaces/interface/${vpp_int}" + + exec { "Register interface ${mapping[0]} with role ${role_name}": + command => "curl -XPOST --fail -H 'Content-Type: application/json' -u ${honeycomb_username}:${honeycomb_password} ${config_url} -d \"{'description': '${role_name}'}\"", + tries => 5, + try_sleep => 30, + path => '/usr/sbin:/usr/bin:/sbin:/bin', + unless => "curl -u ${honeycomb_username}:${honeycomb_password} ${config_url} | grep '${role_name}'", + } +} diff --git a/spec/acceptance/fdio_spec.rb b/spec/acceptance/fdio_spec.rb index 3cc88ad..6e2ec8d 100644 --- a/spec/acceptance/fdio_spec.rb +++ b/spec/acceptance/fdio_spec.rb @@ -7,7 +7,7 @@ describe 'fdio' do it 'should work with no errors' do pp= <<-EOS class { '::fdio': - repo_branch => 'master' + repo_branch => 'release' } EOS diff --git a/templates/honeycomb.json.erb b/templates/honeycomb.json.erb index 7addc09..601dd28 100644 --- a/templates/honeycomb.json.erb +++ b/templates/honeycomb.json.erb @@ -8,10 +8,10 @@ "restconf-http-enabled": "true", "restconf-root-path": "/restconf", - "restconf-binding-address": "127.0.0.1", + "restconf-binding-address": "<%= scope['fdio::honeycomb::bind_ip'] %>", "restconf-port": <%= scope['fdio::honeycomb::rest_port'] %>, "restconf-https-enabled": "true", - "restconf-https-binding-address": "0.0.0.0", + "restconf-https-binding-address": "<%= scope['fdio::honeycomb::bind_ip'] %>", "restconf-https-port": 8443, "restconf-keystore": "/honeycomb-keystore", "restconf-keystore-password": "OBF:1v9s1unr1unn1vv51zlk1t331vg91x1b1vgl1t331zly1vu51uob1uo71v8u", -- cgit 1.2.3-korg