Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Style/TrailingCommaInLiteral:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened voxpupuli/voxpupuli-test#31 as I think that's where this file is now managed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is merged, though not sure about the release process for that gem. Anyhow, this should probably stay in the commit as it will just get overwritten in the next sync and keep doing the same thing.

Enabled: false
inherit_gem:
voxpupuli-test: rubocop.yml
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,59 @@ class { 'hyperglass::server':
}
```

An example showing devices populated.

```puppet
class { 'hyperglass::server':
data => {...},
commands => {...},
devices => {
'routers' => [
{
'name' => 'atl_router01',
'address' => '10.0.0.2',
'network' => {
'name' => 'secondary',
'display_name' => 'That Other Network',
},
'credential' => {
'username' => 'user2',
'password' => ' secret2',
},
'display_name' => 'Atlanta, GA',
'port' => 22,
'nos' => 'juniper',
'vrfs' => [
{
'name' => 'default',
'display_name' => 'Global',
'ipv4' => {
'source_address' => '192.0.2.2',
},
},
],
},
],
},
}
```

Please take a look at the official
[hyperglass documentation](https://hyperglass.io/docs/parameters).

It explains the three different options very well. You can pass the hashes
from the documentation 1:1 to the three parameters.

### Beginning with Hyperglass

This module provides Vagrant definitions that can be used to get started
with Hyperglass. The following will produce VM's for a Hyperglass server
and an agent.

```bash
vagrant up
```

## Tests

This module has several unit tests and linters configured. You can execute them
Expand Down
53 changes: 53 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Environment variables may be used to control the behavior of the Vagrant VM's
# defined in this file. This is intended as a special-purpose affordance and
# should not be necessary in normal situations. If there is a need to run
# multiple backend instances simultaneously, avoid the IP conflict by setting
# the ALTERNATE_IP environment variable:
#
# ALTERNATE_IP=192.168.52.9 vagrant up hyperglass-server
#
# NOTE: The agent VM instances assume the backend VM is accessible on the
# default IP address, therefore using an ALTERNATE_IP is not expected to behave
# well with agent instances.
if not Vagrant.has_plugin?('vagrant-vbguest')
abort <<-EOM

vagrant plugin vagrant-vbguest >= 0.16.0 is required.
https://github.com/dotless-de/vagrant-vbguest
To install the plugin, please run, 'vagrant plugin install vagrant-vbguest'.

EOM
end

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.synced_folder ".", "/vagrant", type: "virtualbox"

config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
end

config.vm.define "hyperglass-server", primary: true, autostart: true do |c|
c.vm.box = "centos/7"
c.vm.hostname = 'hyperglass-server.example.com'
c.vm.network :private_network, ip: ENV['ALTERNATE_IP'] || '192.168.73.10'
c.vm.network :forwarded_port, guest: 8001, host: 8001, auto_correct: true
c.vm.provision :shell, :path => "vagrant/provision_basic_el.sh"
c.vm.provision :shell, :inline => "puppet apply /vagrant/vagrant/server.pp"
end

config.vm.define "el7-agent", primary: true, autostart: true do |c|
c.vm.box = "centos/7"
c.vm.hostname = 'el7-agent.example.com'
c.vm.network :private_network, ip: ENV['ALTERNATE_IP'] || '192.168.73.20'
c.vm.network :forwarded_port, guest: 8080, host: 8080, auto_correct: true
c.vm.provision :shell, :path => "vagrant/provision_basic_el.sh"
c.vm.provision :shell, :inline => "puppet apply /vagrant/vagrant/agent.pp"
end
end
22 changes: 22 additions & 0 deletions data/beaker/true.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
hyperglass::server::data:
listen_address: 0.0.0.0

hyperglass::server::devices:
routers:
- name: atl_router01
address: 10.0.0.2
network:
name: secondary
display_name: That Other Network
credential:
username: user2
password: " secret2"
display_name: Atlanta, GA
port: 22
nos: juniper
vrfs:
- name: default
display_name: Global
ipv4:
source_address: 192.0.2.2
1 change: 1 addition & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--- {}
11 changes: 11 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: 5
defaults:
datadir: data
data_hash: yaml_data
hierarchy:
- name: "Acceptance testing with Beaker"
path: "beaker/%{facts.beaker}.yaml"
- name: "common"
path: "common.yaml"

103 changes: 90 additions & 13 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# @summary installs the hyperglass linux agent
#
# @param manage_python installs python3
# @param manage_gcc installs gcc
# @param data generic hyperglass configuration hash.
# @param manage_python
# installs python3
# @param manage_gcc
# installs gcc
# @param manage_user
# When true, the user 'hyperglass-agent' is managed.
# @param manage_group
# When true, the group 'hyperglass-agent' is managed.
# @param data
# generic hyperglass configuration hash.
#
# @see https://github.com/checktheroads/hyperglass-agent
#
# @author Tim Meusel <tim@bastelfreak.de>
class hyperglass::agent (
Boolean $manage_python = true,
Boolean $manage_gcc = true,
Hash $data = {
Boolean $manage_gcc = true,
Boolean $manage_user = true,
Boolean $manage_group = true,
Hash $data = {
'debug' => true,
'listen_address' => '127.0.0.1',
'mode' => 'bird',
Expand All @@ -20,11 +28,80 @@
},
},
) {
require hyperglass::hyperglassdir
contain hyperglass::agent::install
contain hyperglass::agent::config
contain hyperglass::agent::service
Class['hyperglass::agent::install']
-> Class['hyperglass::agent::config']
~> Class['hyperglass::agent::service']
include hyperglass

if $manage_python {
ensure_resource('class', 'python', { 'version' => '3', 'dev' => 'present' })
}

if $manage_gcc {
ensure_resource('package', 'gcc', { 'ensure' => 'installed' })
}

if $manage_user {
user { 'hyperglass-agent':
ensure => 'present',
managehome => true,
purge_ssh_keys => true,
system => true,
home => '/opt/hyperglass/hyperglass-agent',
}
}

if $manage_group {
group { 'hyperglass-agent':
ensure => 'present',
system => true,
}
}

file { '/opt/hyperglass/hyperglass-agent':
ensure => 'directory',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
mode => '0700',
notify => Systemd::Unit_file['hyperglass-agent.service'],
}

# we need to explicitly set the version here. During the first puppet run, python3 will be installed but isn't present yet
# due to that the fact is undef and fails. the default of the `version` attribute is the fact. We workaround this by hardcoding
# the python version
python::pyvenv { '/opt/hyperglass/hyperglass-agent/virtualenv':
ensure => 'present',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
systempkgs => false,
version => pick($facts['python3_version'], '3.6'),
notify => Systemd::Unit_file['hyperglass-agent.service'],
}

python::pip { 'hyperglass-agent':
virtualenv => '/opt/hyperglass/hyperglass-agent/virtualenv',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
notify => Systemd::Unit_file['hyperglass-agent.service'],
}

file { '/opt/hyperglass/hyperglass-agent/hyperglass-agent':
ensure => 'directory',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
mode => '0755',
notify => Systemd::Unit_file['hyperglass-agent.service'],
}

file { '/opt/hyperglass/hyperglass-agent/hyperglass-agent/config.yaml':
ensure => 'file',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
mode => '0400',
content => to_yaml($data),
notify => Systemd::Unit_file['hyperglass-agent.service'],
}

systemd::unit_file { 'hyperglass-agent.service':
source => 'puppet:///modules/hyperglass/hyperglass-agent.service',
enable => true,
active => true,
}
}
17 changes: 0 additions & 17 deletions manifests/agent/config.pp

This file was deleted.

58 changes: 0 additions & 58 deletions manifests/agent/install.pp

This file was deleted.

13 changes: 0 additions & 13 deletions manifests/agent/service.pp

This file was deleted.

11 changes: 0 additions & 11 deletions manifests/gcc.pp

This file was deleted.

14 changes: 0 additions & 14 deletions manifests/hyperglassdir.pp

This file was deleted.

Loading