Skip to content

Instantly share code, notes, and snippets.

@kelchm
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelchm/fa7f748d41d916d6ba0a to your computer and use it in GitHub Desktop.
Save kelchm/fa7f748d41d916d6ba0a to your computer and use it in GitHub Desktop.
Reactor Troubleshooting
add_node:
cmd.run:
- name: "php /usr/local/solusvm/scripts/addnode.php {% for key, value in pillar['node'].items() %} --{{ key }}={{ value }}{% endfor %}"
update_ips:
cmd.run:
- name: "php /usr/local/solusvm/scripts/updateips.php"
#!/usr/bin/env python
import socket
import os
import platform
import math
import time
from psutil import virtual_memory
import salt
import salt.client
from salt.modules.network import ip_addrs
from salt.modules.network import interfaces
# Config
solusvm_config_path = "/usr/local/solusvm/data/solusvm.conf"
priv_ip_cidr = "10.0.0.0/8"
# End Config
def getsolusdata(path):
with open(path) as f:
content = f.readline().rstrip('\n').split(':',1)
id = content[0]
key = content[1]
return id, key
def getshorthostname():
fqdn = socket.gethostname()
hostname = fqdn.split('.',1)
return hostname[0]
def getprivateip():
priv_ip = salt.modules.network.ip_addrs(cidr=priv_ip_cidr)
return priv_ip[0]
def getnodeport():
# TODO: Parse this from the sshd config
node_port = 495
return node_port
def getnodetype():
# TODO: Expand to cover other SolusVM host node types
node_type = ''
if os.path.isdir('/proc/vz'):
if os.path.isfile('/proc/vz/version'):
node_type = 'openvz'
return node_type
def getpublicinterface():
interface_speed = "eth0"
return interface_speed
def getinterfacespeed():
interface_speed = 1000
return interface_speed
def getmaxmemory():
mem = virtual_memory()
# Convert to MB
mem_mb = mem.total/1000/1000
# Round to nearest 1024MB
mem_rnd = int(math.floor(mem_mb/1000)*1024)
return mem_rnd
def getmaxdisk():
st = os.statvfs("/vz")
disk_size = st.f_blocks * st.f_frsize/1024/1024/1024
# Floor to nearest 100GB
disk_rnd = int(math.floor(disk_size/100)*100*1024)
return disk_rnd
def getmaxvps():
if getshorthostname().upper().startswith("DVS"):
max_vps = 1
else:
max_vps = 50
return max_vps
def getlicensetype():
license_type = 0
max_vps = getmaxvps()
if max_vps <= 2:
license_type = 2
return license_type
def getosversion():
os_version = 6
return os_version
def getploopstatus():
ploop_status = "true"
return ploop_status
def getvswapstatus():
vswap_status = "true"
return vswap_status
def getfriendlyname():
friendly_name = ""
max_memory = getmaxmemory()/1024
if getshorthostname().upper().startswith("DVS"):
friendly_name += `max_memory` + "G"
else:
friendly_name += "VH"
return friendly_name
def getnodegroup():
groupmapping = {
"4G":"8",
"8G":"6",
"12G":"7",
"24G":"4",
"48G":"5",
"128G":"9",
"64GB":"10",
"VH":"1"}
return groupmapping[getfriendlyname()]
# Grab solus data
(solus_id, solus_key) = getsolusdata(solusvm_config_path)
# Setup dict for event
nodedata = {'node': {}}
nodedata['node']['name'] = getshorthostname().upper()
nodedata['node']['host'] = socket.gethostname()
nodedata['node']['ip'] = getprivateip()
nodedata['node']['type'] = getnodetype()
nodedata['node']['nodegroup'] = getnodegroup()
nodedata['node']['id'] = solus_id
nodedata['node']['key'] = solus_key
nodedata['node']['port'] = getnodeport()
nodedata['node']['maxmemory'] = getmaxmemory()
nodedata['node']['maxdisk'] = getmaxdisk()
nodedata['node']['maxvps'] = getmaxvps()
nodedata['node']['licensetype'] = getlicensetype()
nodedata['node']['osversion'] = getosversion()
nodedata['node']['friendlyname'] = getfriendlyname()
nodedata['node']['ploop'] = getploopstatus()
nodedata['node']['vswap'] = getvswapstatus()
nodedata['node']['interface'] = getpublicinterface()
nodedata['node']['interfacespeed'] = getinterfacespeed()
nodedata['node']['countinbw'] = "true"
nodedata['node']['countoutbw'] = "true"
# Assertions
assert nodedata['node']['type'] , "Node type unable to be determined. Please reboot and try again."
# Fire event
print "Attepting to add this node to SolusVM"
caller = salt.client.Caller('/etc/salt/minion')
caller.sminion.functions['event.fire_master'](nodedata, 'solusvm/addnode')
# Pause to allow time for remote execution
time.sleep(5)
print "Completed"
addnode-required-packages:
pkg.installed:
- names:
- python-psutil
add-solusvm-slave:
cmd.script:
- source: salt://solusvm/addnode.py
- user: root
- group: root
- shell: /bin/bash
- require:
- pkg: python-psutil
solusvm_addnode:
cmd.state.sls:
- tgt: solusvm.bhsrv.net
- arg:
- solusvm.addnode-master
- "pillar={ {% for key, value in data['data'].items() %} {{ key }}: {{ value }}, {% endfor %} }"
reactor:
- 'salt/auth':
- /srv/reactor/auth-pending.sls
- 'solusvm/addnode':
- /srv/reactor/solusvm/addnode.sls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment