Project

General

Profile

« Previous | Next » 

Revision b80c6c00

Added by Frank Wall over 10 years ago

fixes #3906 - Support for Junos ZTP

View differences:

app/controllers/unattended_controller.rb
def find_host_by_token
token = params.delete("token")
return nil if token.blank?
# Quirk: ZTP requires the .slax suffix
if ( result = token.match(/^([a-z0-9-]+)(.slax)$/i) )
token, suffix = result.captures
end
Host.for_token(token).first
end
......
@mediapath = os.mediumpath @host
end
def ZTP_attributes
os = @host.operatingsystem
@mediapath = os.mediumpath @host
end
def waik_attributes
end
app/helpers/operatingsystems_helper.rb
"FreeBSD"
when /aix/i
"AIX"
when /Junos/i
"Junos"
else
return "" if record.family.blank?
record.family
app/models/operatingsystem.rb
'Gentoo' => %r{Gentoo}i,
'Solaris' => %r{Solaris}i,
'Freebsd' => %r{FreeBSD}i,
'AIX' => %r{AIX}i }
'AIX' => %r{AIX}i,
'Junos' => %r{Junos}i }
class Jail < Safemode::Jail
allow :name, :media_url, :major, :minor, :family, :to_s, :repos, :==, :release_name, :kernel, :initrd, :pxe_type, :medium_uri
app/models/operatingsystems/junos.rb
class Junos < Operatingsystem
# We don't fetch any files here.
PXEFILES = {}
# Simple output of the media url
def mediumpath host
medium_uri(host).to_s
end
def class
Operatingsystem
end
# The PXE type to use when generating actions and evaluating attributes. jumpstart, kickstart and preseed are currently supported.
def pxe_type
"ZTP"
end
# The variant to use when communicating with the proxy. Syslinux are pxegrub currently supported
def pxe_variant
"ZTP"
end
# The kind of PXE configuration template used. PXELinux and PXEGrub are currently supported
def template_kind
"ZTP"
end
def pxedir
"boot/$arch/images"
end
def url_for_boot(file)
pxedir + "/" + PXEFILES[file]
end
#handle things like gpxelinux/ gpxe / pxelinux here
def boot_filename host=nil
"ztp.cfg/"+host.mac.gsub(/:/,"").upcase
end
def kernel arch
"memdisk"
end
def initrd arch
"none"
end
def display_family
"Junos"
end
end
app/services/facts_parser.rb
elsif os_name[/AIX/i]
majoraix, tlaix, spaix, yearaix = orel.split("-")
orel = majoraix + "." + tlaix + spaix
elsif os_name[/JUNOS/i]
majorjunos, minorjunos = orel.split("R")
orel = majorjunos + "." + minorjunos
end
major, minor = orel.split(".")
major.to_s.gsub!(/\D/,'') unless is_numeric? major
......
end
def architecture
# On solaris architecture fact is harwareisa
# On solaris and junos architecture fact is hardwareisa
name = case os_name
when /(sunos|solaris)/i
when /(sunos|solaris|junos)/i
facts[:hardwareisa]
else
facts[:architecture] || facts[:hardwareisa]
app/views/unattended/ztp/ZTP.erb
<%#
kind: ZTP
name: Community Junos ZTP Config
%>
system {
host-name <%= @host.shortname %>;
root-authentication {
encrypted-password "<%= root_pass %>"; ## SECRET-DATA
}
static-host-mapping {
<%= Setting['foreman_url'] %> alias ztpserver;
}
services {
ssh;
netconf {
ssh;
}
}
ntp {
boot-server 0.pool.ntp.org;
server 0.pool.ntp.org;
server 1.pool.ntp.org;
}
syslog {
user * {
any emergency;
user info;
}
file messages {
any notice;
authorization info;
}
console {
user info;
}
}
}
interfaces {
vme {
unit 0 {
family inet {
dhcp;
}
}
}
}
event-options {
generate-event {
fmztp time-interval 90;
}
policy fmztp {
events fmztp;
then {
execute-commands {
commands {
"op url <%= foreman_url("provision")%>.slax";
}
}
}
}
}
protocols {
igmp-snooping {
vlan all;
}
rstp;
lldp {
interface all;
}
lldp-med {
interface all;
}
}
ethernet-switching-options {
storm-control {
interface all;
}
}
app/views/unattended/ztp/finish.erb
<%#
kind: finish
name: Community Junos Finish
%>
system {
host-name <%= @host %>;
#time-zone Europe/Berlin;
root-authentication {
encrypted-password "<%= root_pass %>"; ## SECRET-DATA
}
static-host-mapping {
<%= Setting['foreman_url'] %> alias ztpserver;
}
#name-server {
# 10.0.0.1;
# 10.10.0.1;
#}
login {
message "This device was provisioned by using The Foreman!\nSee http://theforeman.org/ for further information.\n";
class automation {
permissions all;
}
user puppet {
uid 2001;
class automation;
authentication {
encrypted-password "<%= root_pass %>"; ## SECRET-DATA
}
shell csh;
}
}
services {
ssh {
protocol-version v2;
}
netconf {
ssh;
}
}
syslog {
user * {
any emergency;
}
file messages {
any notice;
authorization info;
}
file interactive-commands {
interactive-commands any;
}
}
ntp {
boot-server 0.pool.ntp.org;
server 0.pool.ntp.org;
server 1.pool.ntp.org;
}
extensions {
providers {
juniper {
license-type juniper deployment-scope commercial;
}
}
}
}
chassis {
alarm {
management-ethernet {
link-down ignore;
}
}
}
interfaces {
interface-range ACCESS-PORT {
member ge-0/0/0;
unit 0 {
family ethernet-switching {
port-mode access;
}
}
}
interface-range UPLINK-PORT {
member ge-0/0/47;
unit 0 {
family ethernet-switching {
port-mode trunk;
vlan {
members all;
}
}
}
}
vlan {
unit 37 {
family inet;
}
}
vme {
unit 0 {
family inet {
dhcp;
}
}
}
}
protocols {
igmp-snooping {
vlan all;
}
rstp;
lldp {
interface all;
}
lldp-med {
interface all;
}
}
ethernet-switching-options {
storm-control {
interface all;
}
bpdu-block {
interface ACCESS-PORT;
disable-timeout 120;
}
}
vlans {
testlan {
vlan-id 37;
l3-interface vlan.37;
}
}
groups {
fmztp {
apply-macro conf {
package jinstall-<%= @host.architecture %>-4200-<%= @host.operatingsystem.major %>R<%= @host.operatingsystem.minor %>-domestic-signed.tgz;
puppet jpuppet-<%= @host.architecture %>-1.0R1.1.tgz;
}
}
}
db/seeds.rb
# Template kinds
kinds = {}
[:PXELinux, :PXEGrub, :iPXE, :provision, :finish, :script, :user_data].each do |type|
[:PXELinux, :PXEGrub, :iPXE, :provision, :finish, :script, :user_data, :ZTP].each do |type|
kinds[type] = TemplateKind.find_by_name(type)
kinds[type] ||= TemplateKind.create :name => type
raise "Unable to create template kind: #{format_errors kinds[type]}" if kinds[type].nil? || kinds[type].errors.any?
end
# Find known operating systems for associations
os_junos = Operatingsystem.find_all_by_type "Junos" || Operatingsystem.where("name LIKE ?", "junos")
os_solaris = Operatingsystem.find_all_by_type "Solaris"
os_suse = Operatingsystem.find_all_by_type "Suse" || Operatingsystem.where("name LIKE ?", "suse")
os_windows = Operatingsystem.find_all_by_type "Windows"
......
{ :name => 'Preseed default finish', :source => 'preseed/finish.erb', :template_kind => kinds[:finish] },
{ :name => 'Preseed default PXELinux', :source => 'preseed/PXELinux.erb', :template_kind => kinds[:PXELinux] },
{ :name => 'WAIK default PXELinux', :source => 'waik/PXELinux.erb', :template_kind => kinds[:PXELinux], :operatingsystems => os_windows },
{ :name => "Junos default ZTP config", :source => 'ztp/ZTP.erb', :template_kind => kinds[:ZTP], :operatingsystems => os_junos },
{ :name => "Junos default finish", :source => 'ztp/finish.erb', :template_kind => kinds[:finish], :operatingsystems => os_junos },
# snippets
{ :name => 'epel', :source => 'snippets/_epel.erb', :snippet => true },
{ :name => 'http_proxy', :source => 'snippets/_http_proxy.erb', :snippet => true },
test/unit/operatingsystem_test.rb
test "families_as_collection contains correct names and values" do
families = Operatingsystem.families_as_collection
assert_equal ["AIX", "Arch Linux", "Debian", "FreeBSD", "Gentoo", "Red Hat", "SUSE", "Solaris", "Windows"], families.map(&:name).sort
assert_equal ["AIX", "Archlinux", "Debian", "Freebsd", "Gentoo", "Redhat", "Solaris", "Suse", "Windows"], families.map(&:value).sort
assert_equal ["AIX", "Arch Linux", "Debian", "FreeBSD", "Gentoo", "Junos", "Red Hat", "SUSE", "Solaris", "Windows"], families.map(&:name).sort
assert_equal ["AIX", "Archlinux", "Debian", "Freebsd", "Gentoo", "Junos", "Redhat", "Solaris", "Suse", "Windows"], families.map(&:value).sort
end
end

Also available in: Unified diff