Skip to content

Commit

Permalink
Implement hyperglass-agent support
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Sep 22, 2020
1 parent 739dcf8 commit 49d269d
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 44 deletions.
50 changes: 50 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

#### Private Classes

* `hyperglass::agent::config`: configures the hyperglass looking agent
* `hyperglass::agent::install`: installs the hyperglass agent on linux nodes
* `hyperglass::agent::service`: manages the hyperglass agent service + unit file
* `hyperglass::gcc`: module to workaround the broken puppetlabs/gcc class. Installs just gcc
* `hyperglass::hyperglassdir`: private class to create the main dir for hyperglass server and agent
* `hyperglass::python`: private class used by server/agent to install python3
* `hyperglass::server::config`: writes the hyperglass config files
* `hyperglass::server::dependencies`: private class that installs all the services hyperglass depends on
* `hyperglass::server::install`: installs the hyperglass server
Expand All @@ -27,6 +33,34 @@ installs the hyperglass linux agent
* **See also**
* https://github.com/checktheroads/hyperglass-agent

#### Parameters

The following parameters are available in the `hyperglass::agent` class.

##### `manage_python`

Data type: `Boolean`

installs python3

Default value: ``true``

##### `manage_gcc`

Data type: `Boolean`

installs gcc

Default value: ``true``

##### `data`

Data type: `Hash`

generic hyperglass configuration hash.

Default value: `{}`

### `hyperglass::server`

installs the hyperglass looking glass
Expand All @@ -46,6 +80,22 @@ if true, installs all other services that hyperglass requires, like redis, yarn,

Default value: ``true``

##### `manage_python`

Data type: `Boolean`

installs python3

Default value: ``true``

##### `manage_gcc`

Data type: `Boolean`

installs gcc

Default value: ``true``

##### `devices`

Data type: `Hash`
Expand Down
14 changes: 14 additions & 0 deletions files/hyperglass-agent.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# THIS FILE IS MANAGED BY PUPPET
[Unit]
Description=hyperglass looking glass agent
After=network.target

[Service]
User=hyperglass-agent
Group=hyperglass-agent
WorkingDirectory=/opt/hyperglass/hyperglass-server
ExecStart=/opt/hyperglass/hyperglass-server/virtualenv/bin/python3 /opt/hyperglass/hyperglass-server/virtualenv/bin/hyperglass-agent start
PrivateTmp=true

[Install]
WantedBy=multi-user.target
6 changes: 3 additions & 3 deletions files/hyperglass.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
[Unit]
Description=hyperglass looking glass server
After=network.target
Requires=rh-redis5-redis
Requires=rh-redis5-redis.service

[Service]
User=hyperglass
Group=hyperglass
WorkingDirectory=/opt/hyperglass
ExecStart=/opt/hyperglass/virtualenv/bin/python3 /opt/hyperglass/virtualenv/bin/hyperglass start
WorkingDirectory=/opt/hyperglass/hyperglass-server
ExecStart=/opt/hyperglass/hyperglass-server/virtualenv/bin/python3 /opt/hyperglass/hyperglass-server/virtualenv/bin/hyperglass start
PrivateTmp=true

[Install]
Expand Down
28 changes: 26 additions & 2 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
# @summary installs the hyperglass linux agent
#
# @param manage_python installs python3
# @param manage_gcc installs gcc
# @param data generic hyperglass configuration hash.
#
# @see https://github.com/checktheroads/hyperglass-agent
#
# @author Tim Meusel <[email protected]>
class hyperglass::agent {}
# @author Tim Meusel <[email protected]>
class hyperglass::agent (
Boolean $manage_python = true,
Boolean $manage_gcc = true,
Hash $data = {
'debug' => true,
'listen_address' => '127.0.0.1',
'mode' => 'bird',
'secret' => fqdn_rand_string(20),
'ssl' => {
'enable' => false,
},
},
) {
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']
}
17 changes: 17 additions & 0 deletions manifests/agent/config.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# @summary configures the hyperglass looking agent
#
# @api private
#
class hyperglass::agent::config (
Hash $data = $hyperglass::agent::data,
) {
assert_private()

file { '/opt/hyperglass/hyperglass-agent/hyperglass-agent/config.yaml':
ensure => 'file',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
mode => '0400',
content => to_yaml($data),
}
}
58 changes: 58 additions & 0 deletions manifests/agent/install.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# @summary installs the hyperglass agent on linux nodes
#
# @api private
#
# @author Tim Meusel <[email protected]>
class hyperglass::agent::install (
Boolean $manage_python = $hyperglass::agent::manage_python,
Boolean $manage_gcc = $hyperglass::agent::manage_gcc,
) {
assert_private()

if $manage_python {
require hyperglass::python
}
if $manage_gcc {
require hyperglass::gcc
}
user { 'hyperglass-agent':
ensure => 'present',
managehome => true,
purge_ssh_keys => true,
system => true,
home => '/opt/hyperglass/hyperglass-agent',
}
group { 'hyperglass-agent':
ensure => 'present',
system => true,
}

file { '/opt/hyperglass/hyperglass-agent':
ensure => 'directory',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
}

# 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'),
}

python::pip { 'hyperglass-agent':
virtualenv => '/opt/hyperglass/hyperglass-agent/virtualenv',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
}

file { '/opt/hyperglass/hyperglass-agent/hyperglass-agent':
ensure => 'directory',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
}
}
13 changes: 13 additions & 0 deletions manifests/agent/service.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# @summary manages the hyperglass agent service + unit file
#
# @api private
#
# @author Tim Meusel <[email protected]>
class hyperglass::agent::service {
assert_private()
systemd::unit_file { 'hyperglass-agent.service':
source => "puppet:///modules/${module_name}/hyperglass-agent.service",
enable => true,
active => true,
}
}
11 changes: 11 additions & 0 deletions manifests/gcc.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @summary module to workaround the broken puppetlabs/gcc class. Installs just gcc
#
# @api private
#
# @author Tim Meusel <[email protected]>
class hyperglass::gcc {
assert_private()
package { 'gcc':
ensure => 'installed',
}
}
14 changes: 14 additions & 0 deletions manifests/hyperglassdir.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# @summary private class to create the main dir for hyperglass server and agent
#
# @api private
#
# @author Tim Meusel <[email protected]>
class hyperglass::hyperglassdir {
assert_private()

file { '/opt/hyperglass/':
ensure => 'directory',
owner => 'root',
group => 'root',
}
}
13 changes: 13 additions & 0 deletions manifests/python.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# @summary private class used by server/agent to install python3
#
# @api private
#
# @author Tim Meusel <[email protected]>
class hyperglass::python {
assert_private()

class { 'python':
version => '3',
dev => 'present',
}
}
11 changes: 7 additions & 4 deletions manifests/server.pp
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# @summary installs the hyperglass looking glass
#
# @param manage_depended_services if true, installs all other services that hyperglass requires, like redis, yarn, nginx, python
# @param manage_python installs python3
# @param manage_gcc installs gcc
# @param devices hash containing all the devices hyperglass can connect to. Defaults to demo data so the service starts properly.
# @param commands specific commands that can be used by the devices
# @param data generic hyperglass configuration hash.
#
# @see https://hyperglass.io/
#
# @author Tim Meusel <tim@bastelfrek.de>
# @author Tim Meusel <tim@bastelfreak.de>
class hyperglass::server (
Boolean $manage_depended_services = true,
Boolean $manage_python = true,
Boolean $manage_gcc = true,
Hash $data = {},
Hash $commands = {},
Hash $devices = {
Expand Down Expand Up @@ -46,11 +50,10 @@
}

if $manage_depended_services {
contain hyperglass::server::dependencies
Class['hyperglass::server::dependencies']
-> Class['hyperglass::server::install']
require hyperglass::server::dependencies
}

require hyperglass::hyperglassdir
contain hyperglass::server::install
contain hyperglass::server::config
contain hyperglass::server::service
Expand Down
8 changes: 4 additions & 4 deletions manifests/server/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
#
# @api private
#
# @author Tim Meusel <tim@bastelfrek.de>
# @author Tim Meusel <tim@bastelfreak.de>
class hyperglass::server::config (
Hash $devices = $hyperglass::server::devices,
Hash $data = $hyperglass::server::data,
Hash $commands = $hyperglass::server::commands,
) {
assert_private()
file { '/opt/hyperglass/hyperglass/hyperglass.yaml':
file { '/opt/hyperglass/hyperglass-server/hyperglass/hyperglass.yaml':
ensure => 'file',
owner => 'hyperglass',
group => 'hyperglass',
content => to_yaml($data),
}
file { '/opt/hyperglass/hyperglass/commands.yaml':
file { '/opt/hyperglass/hyperglass-server/hyperglass/commands.yaml':
ensure => 'file',
owner => 'hyperglass',
group => 'hyperglass',
content => to_yaml($commands),
}

file { '/opt/hyperglass/hyperglass/devices.yaml':
file { '/opt/hyperglass/hyperglass-server/hyperglass/devices.yaml':
ensure => 'file',
owner => 'hyperglass',
group => 'hyperglass',
Expand Down
15 changes: 10 additions & 5 deletions manifests/server/dependencies.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
#
# @api private
#
# @author Tim Meusel <[email protected]>
class hyperglass::server::dependencies {
# @author Tim Meusel <[email protected]>
class hyperglass::server::dependencies (
Boolean $manage_python = $hyperglass::server::manage_python,
Boolean $manage_gcc = $hyperglass::server::manage_gcc,
) {
assert_private()

package { ['python3-pip', 'python3-devel', 'gcc']:
ensure => 'installed',
if $manage_python {
require hyperglass::python
}
if $manage_gcc {
require hyperglass::gcc
}

class { 'redis::globals':
scl => 'rh-redis5',
}
Expand Down
Loading

0 comments on commit 49d269d

Please sign in to comment.