Skip to content

Instantly share code, notes, and snippets.

@sorenisanerd
Forked from hkumarmk/gist:2cd18c36f4059d8ba4d0
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save sorenisanerd/e53277ec95bbed3bb8eb to your computer and use it in GitHub Desktop.

Select an option

Save sorenisanerd/e53277ec95bbed3bb8eb to your computer and use it in GitHub Desktop.
Puppet::Type.type(:contrail_vgw).provide(
:provisioner
) do
# commands :provision_vgw => setCommand
# commands :provision_vgw => 'export PYTHONPATH=/usr/lib/python2.7/dist-packages/contrail_vrouter_api/gen_py/instance_service;/usr/sbin/contrail-provision-vgw-interface'
# commands :provision_vgw => '/usr/sbin/contrail-provision-vgw-interface'
# Stolen from Keystone provider
# the path to withenv changes between versions of puppet, so redefining this function here,
# Run some code with a specific environment. Resets the environment at the end of the code.
def self.withenv(hash, &block)
saved = ENV.to_hash
hash.each do |name, val|
ENV[name.to_s] = val
end
block.call
ensure
ENV.clear
saved.each do |name, val|
ENV[name] = val
end
end
def provision_vgw(*args)
# path=`find /usr/lib/python2.7/ -name instance_service -type d| grep contrail | head -1`.chomp.strip
# command = "export PYTHONPATH=#{path};/usr/sbin/contrail-provision-vgw-interfaces " + args.join(' ')
command = "export PYTHONPATH=/usr/lib/python2.7/dist-packages/contrail_vrouter_api/gen_py/instance_service;/usr/sbin/contrail-provision-vgw-interfaces " + args.join(' ')
puts "HHHHHHHHHHHHH"
begin
puts "before execute"
execute(command, :failonfail => true, :override_locale => false, :squelch => true, :combine => true)
puts "after exec"
rescue Puppet::ExecutionFailure => detail
puts "in rescue"
@resource.fail Puppet::Error, "Could not #{@resource.ref}: #{detail}", detail
end
nil
end
def exists?
Facter.value(:interfaces).split(',').include?(resource[:name])
end
def create_or_update
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
env = {:PYTHONPATH => '/usr/lib/python2.7/dist-packages/contrail_vrouter_api/gen_py/instance_service'}
withenv env do
provision_vgw(
'--interface', resource[:name],
'--subnets', resource[:subnets],
'--routes', resource[:dest_net],
'--vrf', resource[:vrf] ,
'--oper create')
puts "END CREATE"
end
end
def destroy
provision_vgw(
'--interface', resource[:name],
'--subnets', resource[:subnets],
'--routes', resource[:dest_net],
'--vrf', resource[:vrf],
'--oper delete')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment