1
0
mirror of https://github.com/GNS3/gns3-server synced 2025-01-27 00:11:07 +00:00

IOS devices can be deployed on cloud instances.

This commit is contained in:
Jerry Seutter 2014-10-27 18:12:56 -06:00
parent 91894935bf
commit c4afc33ea8
7 changed files with 45 additions and 19 deletions

View File

@ -290,7 +290,7 @@ def get_provider(cloud_settings):
username = cloud_settings['cloud_user_name'] username = cloud_settings['cloud_user_name']
apikey = cloud_settings['cloud_api_key'] apikey = cloud_settings['cloud_api_key']
region = cloud_settings['cloud_region'] region = cloud_settings['cloud_region']
ias_url = cloud_settings['gns3_ias_url'] ias_url = cloud_settings.get('gns3_ias_url', '')
except KeyError as e: except KeyError as e:
log.error("Unable to create cloud provider: {}".format(e)) log.error("Unable to create cloud provider: {}".format(e))
return return

View File

@ -77,7 +77,7 @@ Options:
--cloud_user_name --cloud_user_name
--instance_id ID of the Rackspace instance to terminate --instance_id ID of the Rackspace instance to terminate
--region Region of instance --cloud_region Region of instance
--deadtime How long in seconds can the communication lose exist before we --deadtime How long in seconds can the communication lose exist before we
shutdown this instance. shutdown this instance.
@ -205,8 +205,8 @@ def parse_cmd_line(argv):
print(usage) print(usage)
sys.exit(2) sys.exit(2)
if cmd_line_option_list["region"] is None: if cmd_line_option_list["cloud_region"] is None:
print("You need to specify a region") print("You need to specify a cloud_region")
print(usage) print(usage)
sys.exit(2) sys.exit(2)

View File

@ -62,20 +62,28 @@ class Config(object):
# 5: server.conf in the current working directory # 5: server.conf in the current working directory
home = os.path.expanduser("~") home = os.path.expanduser("~")
self._cloud_config = os.path.join(home, ".config", appname, "cloud.conf") self._cloud_file = os.path.join(home, ".config", appname, "cloud.conf")
filename = "server.conf" filename = "server.conf"
self._files = [os.path.join(home, ".config", appname, filename), self._files = [os.path.join(home, ".config", appname, filename),
os.path.join(home, ".config", appname + ".conf"), os.path.join(home, ".config", appname + ".conf"),
os.path.join("/etc/xdg", appname, filename), os.path.join("/etc/xdg", appname, filename),
os.path.join("/etc/xdg", appname + ".conf"), os.path.join("/etc/xdg", appname + ".conf"),
filename, filename,
self._cloud_config] self._cloud_file]
self._config = configparser.ConfigParser() self._config = configparser.ConfigParser()
self.read_config() self.read_config()
self._cloud_config = configparser.ConfigParser()
self.read_cloud_config()
def list_cloud_config_file(self): def list_cloud_config_file(self):
return self._cloud_config return self._cloud_file
def read_cloud_config(self):
parsed_file = self._cloud_config.read(self._cloud_file)
def cloud_settings(self):
return self._cloud_config['CLOUD_SERVER']
def read_config(self): def read_config(self):
""" """

View File

@ -78,11 +78,15 @@ class LoginHandler(tornado.web.RequestHandler):
self.set_secure_cookie("user", "None") self.set_secure_cookie("user", "None")
auth_status = "failure" auth_status = "failure"
log.info("Authentication attempt %s: %s" %(auth_status, user)) log.info("Authentication attempt {}: {}, {}".format(auth_status, user, password))
try: try:
redirect_to = self.get_secure_cookie("login_success_redirect_to") redirect_to = self.get_secure_cookie("login_success_redirect_to")
except tornado.web.MissingArgumentError: except tornado.web.MissingArgumentError:
redirect_to = "/" redirect_to = "/"
self.redirect(redirect_to) if redirect_to is None:
self.write({'result': auth_status})
else:
log.info('Redirecting to {}'.format(redirect_to))
self.redirect(redirect_to)

View File

@ -61,6 +61,7 @@ class IModule(multiprocessing.Process):
self._current_destination = None self._current_destination = None
self._current_call_id = None self._current_call_id = None
self._stopping = False self._stopping = False
self._cloud_settings = config.cloud_settings()
def _setup(self): def _setup(self):
""" """
@ -173,11 +174,13 @@ class IModule(multiprocessing.Process):
:param results: JSON results to the ZeroMQ server :param results: JSON results to the ZeroMQ server
""" """
log.error('got here 4')
jsonrpc_response = jsonrpc.JSONRPCResponse(results, self._current_call_id)() jsonrpc_response = jsonrpc.JSONRPCResponse(results, self._current_call_id)()
# add session to the response # add session to the response
response = [self._current_session, jsonrpc_response] response = [self._current_session, jsonrpc_response]
log.debug("ZeroMQ client ({}) sending: {}".format(self.name, response)) log.error("ZeroMQ client ({}) sending: {}".format(self.name, response))
log.error('got here 5')
self._stream.send_json(response) self._stream.send_json(response)
def send_param_error(self): def send_param_error(self):

View File

@ -146,16 +146,17 @@ class VM(object):
if os.path.isfile(updated_image_path): if os.path.isfile(updated_image_path):
image = updated_image_path image = updated_image_path
else: else:
if not os.path.exists(self.images_directory):
os.mkdir(self.images_directory)
if request.get("cloud_path", None): if request.get("cloud_path", None):
# Download the image from cloud files # Download the image from cloud files
cloud_path = request.get("cloud_path") cloud_path = request.get("cloud_path")
full_cloud_path = "/".join((cloud_path, image)) full_cloud_path = "/".join((cloud_path, image))
provider = get_provider(self.cloud_settings) provider = get_provider(self._cloud_settings)
provider.download_file(full_cloud_path, updated_image_path) provider.download_file(full_cloud_path, updated_image_path)
try: try:
if platform not in PLATFORMS: if platform not in PLATFORMS:
raise DynamipsError("Unknown router platform: {}".format(platform)) raise DynamipsError("Unknown router platform: {}".format(platform))
@ -200,6 +201,7 @@ class VM(object):
if self._hypervisor_manager.ghost_ios_support: if self._hypervisor_manager.ghost_ios_support:
self.set_ghost_ios(router) self.set_ghost_ios(router)
log.error('got here 1')
except DynamipsError as e: except DynamipsError as e:
dynamips_stdout = "" dynamips_stdout = ""
if hypervisor: if hypervisor:
@ -209,6 +211,7 @@ class VM(object):
self._hypervisor_manager.hypervisors.remove(hypervisor) self._hypervisor_manager.hypervisors.remove(hypervisor)
dynamips_stdout = hypervisor.read_stdout() dynamips_stdout = hypervisor.read_stdout()
self.send_custom_error(str(e) + dynamips_stdout) self.send_custom_error(str(e) + dynamips_stdout)
log.error('got here 2')
return return
response = {"name": router.name, response = {"name": router.name,
@ -216,6 +219,7 @@ class VM(object):
defaults = router.defaults() defaults = router.defaults()
response.update(defaults) response.update(defaults)
self._routers[router.id] = router self._routers[router.id] = router
log.error('got here 3 {}'.format(response))
self.send_response(response) self.send_response(response)
@IModule.route("dynamips.vm.delete") @IModule.route("dynamips.vm.delete")

View File

@ -61,6 +61,7 @@ USAGE: %s
Options: Options:
-d, --debug Enable debugging -d, --debug Enable debugging
-i --ip The ip address of the server, for cert generation
-v, --verbose Enable verbose logging -v, --verbose Enable verbose logging
-h, --help Display this menu :) -h, --help Display this menu :)
@ -79,6 +80,7 @@ def parse_cmd_line(argv):
short_args = "dvh" short_args = "dvh"
long_args = ("debug", long_args = ("debug",
"ip=",
"verbose", "verbose",
"help", "help",
"data=", "data=",
@ -105,6 +107,8 @@ def parse_cmd_line(argv):
sys.exit(0) sys.exit(0)
elif opt in ("-d", "--debug"): elif opt in ("-d", "--debug"):
cmd_line_option_list["debug"] = True cmd_line_option_list["debug"] = True
elif opt in ("--ip",):
cmd_line_option_list["ip"] = val
elif opt in ("-v", "--verbose"): elif opt in ("-v", "--verbose"):
cmd_line_option_list["verbose"] = True cmd_line_option_list["verbose"] = True
elif opt in ("--data",): elif opt in ("--data",):
@ -151,7 +155,7 @@ def set_logging(cmd_options):
return log return log
def _generate_certs(): def _generate_certs(options):
""" """
Generate a self-signed certificate for SSL-enabling the WebSocket Generate a self-signed certificate for SSL-enabling the WebSocket
connection. The certificate is sent back to the client so it can connection. The certificate is sent back to the client so it can
@ -159,7 +163,7 @@ def _generate_certs():
:return: A 2-tuple of strings containing (server_key, server_cert) :return: A 2-tuple of strings containing (server_key, server_cert)
""" """
cmd = ["{}/cert_utils/create_cert.sh".format(SCRIPT_PATH)] cmd = ["{}/cert_utils/create_cert.sh".format(SCRIPT_PATH), options['ip']]
log.debug("Generating certs with cmd: {}".format(' '.join(cmd))) log.debug("Generating certs with cmd: {}".format(' '.join(cmd)))
output_raw = subprocess.check_output(cmd, shell=False, output_raw = subprocess.check_output(cmd, shell=False,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)
@ -176,9 +180,11 @@ def _start_gns3server():
:return: None :return: None
""" """
cmd = ['gns3server', '--quiet'] # cmd = ['gns3server', '--quiet']
cmd = 'gns3server --quiet > /tmp/gns3.log 2>&1 &'
log.info("Starting gns3server with cmd {}".format(cmd)) log.info("Starting gns3server with cmd {}".format(cmd))
subprocess.Popen(cmd, shell=False) # subprocess.Popen(cmd, shell=False)
os.system(cmd)
def main(): def main():
@ -211,7 +217,7 @@ def main():
except FileExistsError: except FileExistsError:
pass pass
(server_key, server_crt) = _generate_certs() (server_key, server_crt) = _generate_certs(options)
cloud_config = configparser.ConfigParser() cloud_config = configparser.ConfigParser()
cloud_config['CLOUD_SERVER'] = {} cloud_config['CLOUD_SERVER'] = {}
@ -221,14 +227,15 @@ def main():
cloud_config['CLOUD_SERVER']['SSL_KEY'] = server_key cloud_config['CLOUD_SERVER']['SSL_KEY'] = server_key
cloud_config['CLOUD_SERVER']['SSL_CRT'] = server_crt cloud_config['CLOUD_SERVER']['SSL_CRT'] = server_crt
cloud_config['CLOUD_SERVER']['SSL_ENABLED'] = 'yes' cloud_config['CLOUD_SERVER']['SSL_ENABLED'] = 'no'
cloud_config['CLOUD_SERVER']['WEB_USERNAME'] = str(uuid.uuid4()).upper()[0:8] cloud_config['CLOUD_SERVER']['WEB_USERNAME'] = str(uuid.uuid4()).upper()[0:8]
cloud_config['CLOUD_SERVER']['WEB_PASSWORD'] = str(uuid.uuid4()).upper()[0:8] cloud_config['CLOUD_SERVER']['WEB_PASSWORD'] = str(uuid.uuid4()).upper()[0:8]
with open(cfg, 'w') as cloud_config_file: with open(cfg, 'w') as cloud_config_file:
cloud_config.write(cloud_config_file) cloud_config.write(cloud_config_file)
cloud_config_file.close() with open(cfg, 'r') as f:
log.info(f.read())
_start_gns3server() _start_gns3server()