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 21, 2020
1 parent c022d13 commit 8417aec
Show file tree
Hide file tree
Showing 19 changed files with 288 additions and 34 deletions.
41 changes: 41 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

#### Private Classes

* `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 +32,26 @@ 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``

### `hyperglass::server`

installs the hyperglass looking glass
Expand All @@ -46,6 +71,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 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
17 changes: 16 additions & 1 deletion manifests/agent.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# @summary installs the hyperglass linux agent
#
# @param manage_python installs python3
# @param manage_gcc installs gcc
#
# @see https://github.com/checktheroads/hyperglass-agent
#
# @author Tim Meusel <[email protected]>
class hyperglass::agent {}
class hyperglass::agent (
Boolean $manage_python = true,
Boolean $manage_gcc = true,
) {
include hyperglass::hyperglassdir
contain hyperglass::agent::install
contain hyperglass::agent::config
contain hyperglass::agent::service
Class['hyperglass::hyperglassdir']
-> Class['hyperglass::agent::install']
-> Class['hyperglass::agent::config']
~> Class['hyperglass::agent::service']
}
22 changes: 22 additions & 0 deletions manifests/agent/config.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# @summary configures the hyperglass looking agent
#
# @api private
#
class hyperglass::agent::config {
assert_private()
file { '/opt/hyperglass/hyperglass-agent/hyperglass-agent/agent_cert.pem':
ensure => 'file',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
mode => '0400',
source => "/etc/puppetlabs/puppet/ssl/certs/${trusted['certname']}.pem",
}

file { '/opt/hyperglass/hyperglass-agent/hyperglass-agent/agent_key.pem':
ensure => 'file',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
mode => '0400',
source => "/etc/puppetlabs/puppet/ssl/private_keys/${trusted['certname']}.pem",
}
}
62 changes: 62 additions & 0 deletions manifests/agent/install.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# @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 {
include hyperglass::python
Class['hyperglass::python']
-> Class['hyperglass::agent::install']
}
if $manage_gcc {
include hyperglass::gcc
Class['hyperglass::gcc']
-> Class['hyperglass::agent::install']
}
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,
}
}
10 changes: 10 additions & 0 deletions manifests/gcc.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# @summary module to workaround the broken puppetlabs/gcc class. Installs just gcc
#
# @api private
#
# @author Tim Meusel <[email protected]>
class hyperglass::gcc {
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',
}
}
8 changes: 7 additions & 1 deletion manifests/server.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# @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.
Expand All @@ -10,6 +12,8 @@
# @author Tim Meusel <[email protected]>
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 @@ -51,11 +55,13 @@
-> Class['hyperglass::server::install']
}

include hyperglass::hyperglassdir
contain hyperglass::server::install
contain hyperglass::server::config
contain hyperglass::server::service

Class['hyperglass::server::install']
Class['hyperglass::hyperglassdir']
-> Class['hyperglass::server::install']
-> Class['hyperglass::server::config']
~> Class['hyperglass::server::service']
}
6 changes: 3 additions & 3 deletions manifests/server/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
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
17 changes: 13 additions & 4 deletions manifests/server/dependencies.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
# @api private
#
# @author Tim Meusel <[email protected]>
class hyperglass::server::dependencies {
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 {
include hyperglass::python
Class['hyperglass::python']
-> Class['hyperglass::server::dependencies']
}
if $manage_gcc {
include hyperglass::gcc
Class['hyperglass::gcc']
-> Class['hyperglass::server::dependencies']
}

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

0 comments on commit 8417aec

Please sign in to comment.