Created
March 12, 2014 21:22
-
-
Save kelchm/9516676 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import salt | |
import socket | |
import os | |
import platform | |
import math | |
from salt.modules.network import ip_addrs | |
from psutil import virtual_memory | |
# 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 | |
if os.path.isdir('/proc/vz'): | |
if os.path.isfile('/proc/vz/version'): | |
node_type = 'openvz' | |
return node_type | |
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/1024)*1024) | |
return mem_rnd | |
def getmaxdisk(): | |
st = os.statvfs("/vz") | |
disk_mb = st.f_blocks * st.f_frsize/1024/1024 | |
# Floor to nearest 100GB | |
disk_rnd = int(math.floor(disk_mb/100000)*100000) | |
return disk_rnd | |
def getmaxvps(): | |
if getshorthostname().upper().startswith("DVS"): | |
max_vps = 1 | |
else: | |
max_vps = 50 | |
return max_vps | |
def getosversion(): | |
os_version = 6 | |
return os_version | |
def getploopstatus(): | |
ploop_status = "true" | |
return ploop_status | |
def getfriendlyname(): | |
friendly_name = "" | |
max_memory = getmaxmemory()/1024 | |
if getshorthostname().upper().startswith("DVS"): | |
friendly_name += `max_memory` + "G" | |
return friendly_name | |
(solus_id, solus_key) = getsolusdata(solusvm_config_path) | |
print solus_id | |
print solus_key | |
print getprivateip() | |
print getshorthostname().upper() | |
print getnodetype() | |
print getmaxmemory() | |
print getmaxdisk() | |
print getmaxvps() | |
print getosversion() | |
print getfriendlyname() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment