Last active
August 29, 2015 14:07
-
-
Save hkumarmk/e825df21126db62cc5c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type/contrail_provisioner.rb | |
================================== | |
Puppet::Type.newtype(:contrail_provisioner) do | |
@doc = <<-'EOD' | |
Provision contrail BGP peers (contrail control, edge routers), | |
xmpp peers (Vrouters) and linklocal services. | |
EOD | |
feature :control, "just feature" | |
ensurable | |
newparam(:name, :namevar => true) do | |
desc 'Name of the service to be added.' | |
munge do |v| | |
v.strip | |
end | |
end | |
newparam(:api_server_address) do | |
desc 'Contrail api server address' | |
defaultto '127.0.0.1' | |
munge do |v| | |
v.strip | |
end | |
end | |
newparam(:api_server_port) do | |
desc 'Contrail api server port' | |
defaultto '8082' | |
newvalues(/^\d+$/) | |
munge do |v| | |
v.strip | |
end | |
end | |
newparam(:object) do | |
desc 'The object to be provisioned. | |
The values vrouter,linklocal,control,router are valid' | |
newvalues(/^(vrouter|linklocal|control|router)$/) | |
munge do |v| | |
v.strip | |
end | |
end | |
newparam(:admin_user) do | |
desc 'Keystone admin user name' | |
defaultto 'admin' | |
newvalues(/\S+/) | |
munge do |v| | |
v.strip | |
end | |
end | |
newparam(:admin_password) do | |
desc 'Keystone admin user password' | |
munge do |v| | |
v.strip | |
end | |
end | |
newproperty(:service_address) do | |
desc 'Local IP address on vrouter to listen for linklocal service. e.g for | |
metadata it is 169.254.169.254' | |
munge do |v| | |
v.strip | |
end | |
end | |
newproperty(:service_port) do | |
desc 'Local port number on vrouter to be listen the linklocal service.' | |
end | |
newproperty(:ipfabric_service_address) do | |
desc 'Real IP address of linklocal service' | |
end | |
newproperty(:ipfabric_service_port) do | |
desc 'The port on real server for linklocal service' | |
end | |
newproperty(:hostname, :required_features => :control) do | |
desc 'hostname to provision control nodes. Default: hostname fact' | |
defaultto Facter.value('hostname') | |
newvalues(/\S+/) | |
end | |
end | |
prover/contrail_provisioner/provisioner.rb | |
========================================== | |
## This provider need curb | |
require 'json' | |
require 'curb' | |
Puppet::Type.type(:contrail_provisioner).provide(:provisioner) do | |
commands :provision_linklocal => '/usr/sbin/contrail-provision-linklocal' | |
def getUrlData | |
url = 'http://' + resource[:api_server_address] + ':' + resource[:api_server_port] + '/global-vrouter-configs' | |
json_data = Curl::Easy.perform(url).body_str | |
hash_data = JSON.parse(json_data) | |
return hash_data | |
end | |
def getLinklocal | |
hash_data=getUrlData | |
hash_data['global-vrouter-configs'].each do |i| | |
vrouterconfig_url = i['href'] | |
vrouterconfig_json = Curl::Easy.perform(vrouterconfig_url).body_str | |
vrouterconfig_hash = JSON.parse(vrouterconfig_json) | |
if vrouterconfig_hash['global-vrouter-config']['linklocal_services'] | |
vrouterconfig_hash['global-vrouter-config']['linklocal_services']['linklocal_service_entry'].each do |ll_service| | |
if ll_service['linklocal_service_name'].eql?resource[:name] | |
puts ll_service | |
return ll_service | |
end | |
end | |
end | |
end | |
end | |
def getElement(element_name) | |
if resource[:object].eql?'linklocal' | |
linklocal_data = getLinklocal | |
return linklocal_data[element_name] | |
end | |
end | |
def exists? | |
if resource[:object].eql?'linklocal' | |
return getLinklocal.is_a?(Hash) | |
end | |
end | |
def create_linklocal | |
fail "Provisioning linklocal service require ipfabric_service_address" unless resource[:ipfabric_service_address] | |
fail "Provisioning linklocal service require ipfabric_service_port" unless resource[:ipfabric_service_port] | |
fail "Provisioning linklocal service require admin_password" unless resource[:admin_password] | |
fail "Provisioning linklocal service require service_address" unless resource[:service_address] | |
fail "Provisioning linklocal service require service_port" unless resource[:service_port] | |
provision_linklocal('--admin_user',resource[:admin_user],'--admin_password',resource[:admin_password],'--api_server_ip', | |
resource[:api_server_address],'--api_server_port',resource[:api_server_port],'--linklocal_service_name',resource[:name], | |
'--linklocal_service_ip',resource[:service_address],'--linklocal_service_port',resource[:service_port], | |
'--ipfabric_service_ip',resource[:ipfabric_service_address],'--ipfabric_service_port',resource[:ipfabric_service_port], | |
'--oper add') | |
end | |
def create | |
puts "in create" | |
if resource[:object].eql?'linklocal' | |
create_linklocal | |
end | |
end | |
def service_address | |
puts "START" | |
puts resource[:hostname] | |
getElement('linklocal_service_ip') | |
end | |
def service_address=(value) | |
create_linklocal | |
end | |
def service_port | |
getElement('linklocal_service_port') | |
end | |
def service_port=(value) | |
create_linklocal | |
end | |
def ipfabric_service_address | |
getElement('ip_fabric_service_ip') | |
end | |
def ipfabric_service_address=(value) | |
create_linklocal | |
end | |
def ipfabric_service_port | |
getElement('ip_fabric_service_port') | |
end | |
def ipfabric_service_port=(value) | |
create_linklocal | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment