mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-18 07:23:47 +02:00
IOS devices can be deployed on cloud instances.
This commit is contained in:
parent
91894935bf
commit
c4afc33ea8
@ -290,7 +290,7 @@ def get_provider(cloud_settings):
|
||||
username = cloud_settings['cloud_user_name']
|
||||
apikey = cloud_settings['cloud_api_key']
|
||||
region = cloud_settings['cloud_region']
|
||||
ias_url = cloud_settings['gns3_ias_url']
|
||||
ias_url = cloud_settings.get('gns3_ias_url', '')
|
||||
except KeyError as e:
|
||||
log.error("Unable to create cloud provider: {}".format(e))
|
||||
return
|
||||
|
@ -77,7 +77,7 @@ Options:
|
||||
--cloud_user_name
|
||||
|
||||
--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
|
||||
shutdown this instance.
|
||||
@ -205,8 +205,8 @@ def parse_cmd_line(argv):
|
||||
print(usage)
|
||||
sys.exit(2)
|
||||
|
||||
if cmd_line_option_list["region"] is None:
|
||||
print("You need to specify a region")
|
||||
if cmd_line_option_list["cloud_region"] is None:
|
||||
print("You need to specify a cloud_region")
|
||||
print(usage)
|
||||
sys.exit(2)
|
||||
|
||||
|
@ -62,20 +62,28 @@ 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")
|
||||
self._cloud_file = 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,
|
||||
self._cloud_config]
|
||||
self._cloud_file]
|
||||
|
||||
self._config = configparser.ConfigParser()
|
||||
self.read_config()
|
||||
self._cloud_config = configparser.ConfigParser()
|
||||
self.read_cloud_config()
|
||||
|
||||
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):
|
||||
"""
|
||||
|
@ -78,11 +78,15 @@ class LoginHandler(tornado.web.RequestHandler):
|
||||
self.set_secure_cookie("user", "None")
|
||||
auth_status = "failure"
|
||||
|
||||
log.info("Authentication attempt %s: %s" %(auth_status, user))
|
||||
log.info("Authentication attempt {}: {}, {}".format(auth_status, user, password))
|
||||
|
||||
try:
|
||||
redirect_to = self.get_secure_cookie("login_success_redirect_to")
|
||||
except tornado.web.MissingArgumentError:
|
||||
redirect_to = "/"
|
||||
|
||||
if redirect_to is None:
|
||||
self.write({'result': auth_status})
|
||||
else:
|
||||
log.info('Redirecting to {}'.format(redirect_to))
|
||||
self.redirect(redirect_to)
|
@ -61,6 +61,7 @@ class IModule(multiprocessing.Process):
|
||||
self._current_destination = None
|
||||
self._current_call_id = None
|
||||
self._stopping = False
|
||||
self._cloud_settings = config.cloud_settings()
|
||||
|
||||
def _setup(self):
|
||||
"""
|
||||
@ -173,11 +174,13 @@ class IModule(multiprocessing.Process):
|
||||
:param results: JSON results to the ZeroMQ server
|
||||
"""
|
||||
|
||||
log.error('got here 4')
|
||||
jsonrpc_response = jsonrpc.JSONRPCResponse(results, self._current_call_id)()
|
||||
|
||||
# add session to the 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)
|
||||
|
||||
def send_param_error(self):
|
||||
|
@ -146,16 +146,17 @@ class VM(object):
|
||||
if os.path.isfile(updated_image_path):
|
||||
image = updated_image_path
|
||||
else:
|
||||
if not os.path.exists(self.images_directory):
|
||||
os.mkdir(self.images_directory)
|
||||
if request.get("cloud_path", None):
|
||||
# Download the image from cloud files
|
||||
cloud_path = request.get("cloud_path")
|
||||
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)
|
||||
|
||||
try:
|
||||
|
||||
if platform not in PLATFORMS:
|
||||
raise DynamipsError("Unknown router platform: {}".format(platform))
|
||||
|
||||
@ -200,6 +201,7 @@ class VM(object):
|
||||
if self._hypervisor_manager.ghost_ios_support:
|
||||
self.set_ghost_ios(router)
|
||||
|
||||
log.error('got here 1')
|
||||
except DynamipsError as e:
|
||||
dynamips_stdout = ""
|
||||
if hypervisor:
|
||||
@ -209,6 +211,7 @@ class VM(object):
|
||||
self._hypervisor_manager.hypervisors.remove(hypervisor)
|
||||
dynamips_stdout = hypervisor.read_stdout()
|
||||
self.send_custom_error(str(e) + dynamips_stdout)
|
||||
log.error('got here 2')
|
||||
return
|
||||
|
||||
response = {"name": router.name,
|
||||
@ -216,6 +219,7 @@ class VM(object):
|
||||
defaults = router.defaults()
|
||||
response.update(defaults)
|
||||
self._routers[router.id] = router
|
||||
log.error('got here 3 {}'.format(response))
|
||||
self.send_response(response)
|
||||
|
||||
@IModule.route("dynamips.vm.delete")
|
||||
|
@ -61,6 +61,7 @@ USAGE: %s
|
||||
Options:
|
||||
|
||||
-d, --debug Enable debugging
|
||||
-i --ip The ip address of the server, for cert generation
|
||||
-v, --verbose Enable verbose logging
|
||||
-h, --help Display this menu :)
|
||||
|
||||
@ -79,6 +80,7 @@ def parse_cmd_line(argv):
|
||||
|
||||
short_args = "dvh"
|
||||
long_args = ("debug",
|
||||
"ip=",
|
||||
"verbose",
|
||||
"help",
|
||||
"data=",
|
||||
@ -105,6 +107,8 @@ def parse_cmd_line(argv):
|
||||
sys.exit(0)
|
||||
elif opt in ("-d", "--debug"):
|
||||
cmd_line_option_list["debug"] = True
|
||||
elif opt in ("--ip",):
|
||||
cmd_line_option_list["ip"] = val
|
||||
elif opt in ("-v", "--verbose"):
|
||||
cmd_line_option_list["verbose"] = True
|
||||
elif opt in ("--data",):
|
||||
@ -151,7 +155,7 @@ def set_logging(cmd_options):
|
||||
return log
|
||||
|
||||
|
||||
def _generate_certs():
|
||||
def _generate_certs(options):
|
||||
"""
|
||||
Generate a self-signed certificate for SSL-enabling the WebSocket
|
||||
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)
|
||||
"""
|
||||
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)))
|
||||
output_raw = subprocess.check_output(cmd, shell=False,
|
||||
stderr=subprocess.STDOUT)
|
||||
@ -176,9 +180,11 @@ def _start_gns3server():
|
||||
|
||||
:return: None
|
||||
"""
|
||||
cmd = ['gns3server', '--quiet']
|
||||
# cmd = ['gns3server', '--quiet']
|
||||
cmd = 'gns3server --quiet > /tmp/gns3.log 2>&1 &'
|
||||
log.info("Starting gns3server with cmd {}".format(cmd))
|
||||
subprocess.Popen(cmd, shell=False)
|
||||
# subprocess.Popen(cmd, shell=False)
|
||||
os.system(cmd)
|
||||
|
||||
|
||||
def main():
|
||||
@ -211,7 +217,7 @@ def main():
|
||||
except FileExistsError:
|
||||
pass
|
||||
|
||||
(server_key, server_crt) = _generate_certs()
|
||||
(server_key, server_crt) = _generate_certs(options)
|
||||
|
||||
cloud_config = configparser.ConfigParser()
|
||||
cloud_config['CLOUD_SERVER'] = {}
|
||||
@ -221,14 +227,15 @@ def main():
|
||||
|
||||
cloud_config['CLOUD_SERVER']['SSL_KEY'] = server_key
|
||||
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_PASSWORD'] = str(uuid.uuid4()).upper()[0:8]
|
||||
|
||||
with open(cfg, 'w') as 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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user