mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-15 12:59:06 +00:00
Update gns3dms to support cloud.conf
This commit is contained in:
parent
36e539382c
commit
ef492d4690
@ -24,7 +24,7 @@
|
||||
# number has been incremented)
|
||||
|
||||
"""
|
||||
Monitors communication with the GNS3 client via tmp file. Will terminate the instance if
|
||||
Monitors communication with the GNS3 client via tmp file. Will terminate the instance if
|
||||
communication is lost.
|
||||
"""
|
||||
|
||||
@ -62,7 +62,7 @@ sys.path.append(EXTRA_LIB)
|
||||
|
||||
import daemon
|
||||
|
||||
my_daemon = None
|
||||
my_daemon = None
|
||||
|
||||
usage = """
|
||||
USAGE: %s
|
||||
@ -73,14 +73,14 @@ Options:
|
||||
-v, --verbose Enable verbose logging
|
||||
-h, --help Display this menu :)
|
||||
|
||||
--cloud_api_key <api_key> Rackspace API key
|
||||
--cloud_api_key <api_key> Rackspace API key
|
||||
--cloud_user_name
|
||||
|
||||
--instance_id ID of the Rackspace instance to terminate
|
||||
|
||||
--deadtime How long in seconds can the communication lose exist before we
|
||||
shutdown this instance.
|
||||
Default:
|
||||
|
||||
--deadtime How long in seconds can the communication lose exist before we
|
||||
shutdown this instance.
|
||||
Default:
|
||||
Example --deadtime=3600 (60 minutes)
|
||||
|
||||
--check-interval Defaults to --deadtime, used for debugging
|
||||
@ -146,7 +146,7 @@ def parse_cmd_line(argv):
|
||||
cmd_line_option_list['syslog'] = ('localhost',514)
|
||||
|
||||
|
||||
get_gns3secrets(cmd_line_option_list)
|
||||
get_gns3config(cmd_line_option_list)
|
||||
|
||||
for opt, val in opts:
|
||||
if (opt in ("-h", "--help")):
|
||||
@ -202,7 +202,7 @@ def parse_cmd_line(argv):
|
||||
|
||||
return cmd_line_option_list
|
||||
|
||||
def get_gns3secrets(cmd_line_option_list):
|
||||
def get_gns3config(cmd_line_option_list):
|
||||
"""
|
||||
Load cloud credentials from .gns3secrets
|
||||
"""
|
||||
@ -225,6 +225,15 @@ def get_gns3secrets(cmd_line_option_list):
|
||||
except configparser.NoSectionError:
|
||||
pass
|
||||
|
||||
cloud_config_file = "%s/.config/GNS3/cloud.conf"
|
||||
if os.path.isfile(cloud_config_file)
|
||||
config.read(cloud_config_file)
|
||||
|
||||
try:
|
||||
for key, value in config.items("CLOUD_SERVER"):
|
||||
cmd_line_option_list[key] = value.strip()
|
||||
except configparser.NoSectionError:
|
||||
pass
|
||||
|
||||
def set_logging(cmd_options):
|
||||
"""
|
||||
@ -256,7 +265,7 @@ def set_logging(cmd_options):
|
||||
)
|
||||
|
||||
syslog_hndlr.setFormatter(sys_formatter)
|
||||
|
||||
|
||||
log.setLevel(log_level)
|
||||
log.addHandler(console_log)
|
||||
log.addHandler(syslog_hndlr)
|
||||
@ -308,7 +317,7 @@ def monitor_loop(options):
|
||||
|
||||
if delta.seconds > options["deadtime"]:
|
||||
log.warning("Deadtime exceeded, terminating instance ...")
|
||||
#Terminate involes many layers of HTTP / API calls, lots of
|
||||
#Terminate involes many layers of HTTP / API calls, lots of
|
||||
#different errors types could occur here.
|
||||
try:
|
||||
rksp = Rackspace(options)
|
||||
@ -341,7 +350,8 @@ def main():
|
||||
|
||||
log.info("Received shutdown signal")
|
||||
options["shutdown"] = True
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
pid_file = "%s/.gns3ias.pid" % (expanduser("~"))
|
||||
|
||||
if options["shutdown"]:
|
||||
|
@ -68,7 +68,7 @@ emailAddress=gns3cert@gns3.com
|
||||
"
|
||||
|
||||
# Generate the server private key
|
||||
openssl genrsa -aes256 -out $DST_DIR/$DOMAIN.key -passout env:PASSPHRASE 2048
|
||||
openssl genrsa -aes256 -out $DOMAIN.key -passout env:PASSPHRASE 2048
|
||||
fail_if_error $?
|
||||
|
||||
#openssl rsa -outform der -in $DOMAIN.pem -out $DOMAIN.key -passin env:PASSPHRASE
|
||||
@ -93,4 +93,7 @@ fail_if_error $?
|
||||
openssl x509 -req -days 3650 -in $DOMAIN.csr -signkey $DOMAIN.key -out $DOMAIN.crt
|
||||
fail_if_error $?
|
||||
|
||||
echo "${DST_DIR}${DOMAIN}.key"
|
||||
echo "${DST_DIR}${DOMAIN}.crt"
|
||||
|
||||
cd $OLD_DIR
|
@ -62,16 +62,21 @@ class Config(object):
|
||||
# 5: server.conf in the current working directory
|
||||
|
||||
home = os.path.expanduser("~")
|
||||
self._cloud_config = os.path.join(home, ".config", appname, "cloud.conf")
|
||||
filename = "server.conf"
|
||||
self._files = [os.path.join(home, ".config", appname, filename),
|
||||
os.path.join(home, ".config", appname + ".conf"),
|
||||
os.path.join("/etc/xdg", appname, filename),
|
||||
os.path.join("/etc/xdg", appname + ".conf"),
|
||||
filename]
|
||||
filename,
|
||||
self._cloud_config]
|
||||
|
||||
self._config = configparser.ConfigParser()
|
||||
self.read_config()
|
||||
|
||||
def list_cloud_config_file(self):
|
||||
return self._cloud_config
|
||||
|
||||
def read_config(self):
|
||||
"""
|
||||
Read the configuration files.
|
||||
|
@ -20,8 +20,9 @@ from .base import IModule
|
||||
from .dynamips import Dynamips
|
||||
from .vpcs import VPCS
|
||||
from .virtualbox import VirtualBox
|
||||
from .deadman import DeadMan
|
||||
|
||||
MODULES = [Dynamips, VPCS, VirtualBox]
|
||||
MODULES = [Dynamips, VPCS, VirtualBox, DeadMan]
|
||||
|
||||
if sys.platform.startswith("linux"):
|
||||
# IOU runs only on Linux
|
||||
|
@ -30,7 +30,7 @@ from gns3server.config import Config
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class DeadMan():
|
||||
class DeadMan(IModule):
|
||||
"""
|
||||
DeadMan module.
|
||||
|
||||
@ -51,10 +51,12 @@ class DeadMan():
|
||||
self._heartbeat_file = "%s/heartbeat_file_for_gnsdms" % (
|
||||
self._tempdir)
|
||||
|
||||
self.cloud_config = Config.instance().get_section_config("CLOUD_SERVER")
|
||||
self._heartbeat_file = self.cloud_config["heartbeat_file"]
|
||||
|
||||
if 'heartbeat_file' in kwargs:
|
||||
self._heartbeat_file = kwargs['heartbeat_file']
|
||||
|
||||
|
||||
self._deadman_process = None
|
||||
self.start()
|
||||
|
||||
@ -63,8 +65,12 @@ class DeadMan():
|
||||
Start a subprocess and return the object
|
||||
"""
|
||||
|
||||
cmd = []
|
||||
#gnsserver gets configuration options from cloud.conf. This is where
|
||||
#the client adds specific cloud information.
|
||||
#gns3dms also reads in cloud.conf. That is why we don't need to specific
|
||||
#all the command line arguments here.
|
||||
|
||||
cmd = []
|
||||
cmd.append("gns3dms")
|
||||
cmd.append("--file %s" % (self._heartbeat_file))
|
||||
cmd.append("--background")
|
||||
|
@ -141,35 +141,20 @@ class Server(object):
|
||||
instance.start() # starts the new process
|
||||
|
||||
|
||||
def _get_cert_info(self):
|
||||
"""
|
||||
Finds the cert and key file needed for SSL
|
||||
"""
|
||||
|
||||
home = expanduser("~")
|
||||
ssl_dir = "%s/.conf/GNS3Certs/" % (home)
|
||||
log.debug("Looking for SSL certs in: %s" % (ssl_dir))
|
||||
|
||||
keyfile = "%s/gns3server.localdomain.com.key" % (ssl_dir)
|
||||
certfile = "%s/gns3server.localdomain.com.crt" % (ssl_dir)
|
||||
|
||||
if os.path.isfile(keyfile) and os.path.isfile(certfile):
|
||||
return { "certfile" : certfile,
|
||||
"keyfile" : keyfile,
|
||||
}
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Starts the Tornado web server and ZeroMQ server.
|
||||
"""
|
||||
|
||||
# FIXME: debug mode!
|
||||
cloud_config = Config.instance().get_section_config("CLOUD_SERVER")
|
||||
|
||||
settings = {
|
||||
"debug":True,
|
||||
"cookie_secret": base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes),
|
||||
"login_url": "/login",
|
||||
"required_user" : "test123",
|
||||
"required_pass" : "test456",
|
||||
"required_user" : cloud_config['WEB_USERNAME'],
|
||||
"required_pass" : cloud_config['WEB_PASSWORD'],
|
||||
}
|
||||
|
||||
router = self._create_zmq_router()
|
||||
@ -191,11 +176,14 @@ class Server(object):
|
||||
zmq.zmq_version()))
|
||||
kwargs = {"address": self._host}
|
||||
|
||||
ssl_options = self._get_cert_info()
|
||||
if cloud_config["SSL_ENABLED"] == "yes":
|
||||
ssl_options = {
|
||||
"certfile" : cloud_config["SSL_CRT"],
|
||||
"keyfile" : cloud_config["SSL_KEY"],
|
||||
}
|
||||
|
||||
if ssl_options:
|
||||
log.info("Certs found - starting in SSL mode")
|
||||
kwargs['ssl_options'] = ssl_options
|
||||
kwargs["ssl_options"] = ssl_options
|
||||
|
||||
if parse_version(tornado.version) >= parse_version("3.1"):
|
||||
kwargs["max_buffer_size"] = 524288000 # 500 MB file upload limit
|
||||
|
@ -5,4 +5,5 @@ jsonschema
|
||||
pycurl
|
||||
python-dateutil
|
||||
apache-libcloud
|
||||
requests
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user