<commit_before>#
# Cookbook Name:: contrail
# Recipe:: contrail-vrouter
#
# Copyright 2014, Juniper Networks
#

if node['contrail']['manage_nova_compute'] then
    pkgs = %w( contrail-openstack-vrouter )
else 
    if platform?("redhat", "centos", "fedora")
        pkgs = %w( contrail-nodemgr contrail-nova-vif contrail-setup contrail-vrouter contrail-vrouter-init linux-crashdump python-iniparse )
    else
        pkgs = %w( abrt contrail-nodemgr contrail-nova-vif contrail-setup contrail-vrouter contrail-vrouter-init openstack-utils python-thrift )
    end
end

if node['contrail']['haproxy'] then
    pkgs << :haproxy
end

if platform?("ubuntu") then
    File.open("/etc/init/supervisor-vrouter.override", 'a') {|f| f.write("manual") }
end

pkgs.each do |pkg|
    package pkg do
        action :upgrade
    end
end

bash "enable-vrouter" do
    user "root"
    vrouter_mod="/lib/modules/#{`uname -r`.chomp}/extra/net/vrouter/vrouter.ko"
    interface=node['contrail']['compute']['interface']
    macaddr=`cat /sys/class/net/#{interface}/address`.chomp
    code <<-EOC
        insmod #{vrouter_mod}
        sed --in-place '/^vrouter$/d' /etc/modules
        echo 'vrouter' >> /etc/modules
        vif --create vhost0 --mac #{macaddr}
        vif --add #{interface} --mac #{macaddr} --vrf 0 --vhost-phys --type physical
        vif --add vhost0 --mac #{macaddr} --vrf 0 --xconnect #{interface} --type vhost
    EOC
    not_if "grep -e '^vrouter$' /etc/modules"
end

service 'network'

template "/etc/sysconfig/network-scripts/ifcfg-vhost0" do
    source "network.vhost.erb"
    owner "root"
    group "root"
    mode 00644
    variables(
        :interface => node['contrail']['compute']['interface'],
        :ip => node['contrail']['compute']['ip'],
        :netmask => node['contrail']['compute']['netmask'],
        :gateway => node['contrail']['compute']['gateway'],
        :dns1 => node['contrail']['compute']['dns1'],
        :dns2 => node['contrail']['compute']['dns2'],
        :dns3 => node['contrail']['compute']['dns3'],
        :domain => node['contrail']['compute']['domain']
    )
#    notifies :restart, "service[network]", :delayed
end

template "/etc/sysconfig/network-scripts/ifcfg-#{node['contrail']['compute']['interface']}" do
    source "network.eth.erb"
    variables(
        :interface => node['contrail']['compute']['interface'],
    )
#    notifies :restart, "service[network]", :delayed
end

bash "vhost0-up" do
    user "root"
    code <<-EOC
        route add default gw #{node['contrail']['compute']['gateway']} dev vhost0
        service network restart
    EOC
end

template "/etc/contrail/contrail-vrouter-agent.conf" do
    source "contrail-vrouter-agent.conf.erb"
    owner "contrail"
    group "contrail"
    mode 00644
    notifies :restart, "service[contrail-vrouter-agent]", :immediately
end

%w{ contrail-vrouter-agent }.each do |pkg|
    service pkg do
        action [:enable, :start]
    end
end

%w{ supervisor-vrouter }.each do |pkg|
    service pkg do
        action [:enable, :start]
    end
end<commit_msg>fix vrouter recipe to have vhost0 up and running<commit_after>#
# Cookbook Name:: contrail
# Recipe:: contrail-vrouter
#
# Copyright 2014, Juniper Networks
#

if node['contrail']['manage_nova_compute'] then
    pkgs = %w( contrail-openstack-vrouter )
else 
    if platform?("redhat", "centos", "fedora")
        pkgs = %w( contrail-nodemgr contrail-nova-vif contrail-setup contrail-vrouter contrail-vrouter-init linux-crashdump python-iniparse )
    else
        pkgs = %w( abrt contrail-nodemgr contrail-nova-vif contrail-setup contrail-vrouter contrail-vrouter-init openstack-utils python-thrift )
    end
end

if node['contrail']['haproxy'] then
    pkgs << :haproxy
end

if platform?("ubuntu") then
    File.open("/etc/init/supervisor-vrouter.override", 'a') {|f| f.write("manual") }
end

pkgs.each do |pkg|
    package pkg do
        action :upgrade
    end
end

service 'network'

template "/etc/sysconfig/network-scripts/ifcfg-vhost0" do
    source "network.vhost.erb"
    owner "root"
    group "root"
    mode 00644
    variables(
        :interface => node['contrail']['compute']['interface'],
        :ip => node['contrail']['compute']['ip'],
        :netmask => node['contrail']['compute']['netmask'],
        :gateway => node['contrail']['compute']['gateway'],
        :dns1 => node['contrail']['compute']['dns1'],
        :dns2 => node['contrail']['compute']['dns2'],
        :dns3 => node['contrail']['compute']['dns3'],
        :domain => node['contrail']['compute']['domain']
    )
end

template "/etc/sysconfig/network-scripts/ifcfg-#{node['contrail']['compute']['interface']}" do
    source "network.eth.erb"
    variables(
        :interface => node['contrail']['compute']['interface'],
    )
end

bash "enable-vrouter" do
    user "root"
    vrouter_mod="/lib/modules/#{`uname -r`.chomp}/extra/net/vrouter/vrouter.ko"
    interface=node['contrail']['compute']['interface']
    macaddr=`cat /sys/class/net/#{interface}/address`.chomp
    code <<-EOC
        insmod #{vrouter_mod}
        sed --in-place '/^vrouter$/d' /etc/modules
        echo 'vrouter' >> /etc/modules
        vif --create vhost0 --mac #{macaddr}
        vif --add #{interface} --mac #{macaddr} --vrf 0 --vhost-phys --type physical
        vif --add vhost0 --mac #{macaddr} --vrf 0 --xconnect #{interface} --type vhost
        service network restart
    EOC
    not_if "grep -e '^vrouter$' /etc/modules"
end

template "/etc/contrail/contrail-vrouter-agent.conf" do
    source "contrail-vrouter-agent.conf.erb"
    owner "contrail"
    group "contrail"
    mode 00644
    notifies :restart, "service[contrail-vrouter-agent]", :immediately
end

%w{ contrail-vrouter-agent }.each do |pkg|
    service pkg do
        action [:enable, :start]
    end
end

%w{ supervisor-vrouter }.each do |pkg|
    service pkg do
        action [:enable, :start]
    end
end
{'fraction_non_alphanumeric': 0.1672314469671298, 'fraction_numerical': 0.008980006777363606, 'mean_word_length': 3.271345875542692, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6328594', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1966, 'n_words': 443}