mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-13 01:20:58 +00:00
Importing changeset from gns3dms repo
This commit is contained in:
parent
6ff2c654d9
commit
6421367259
@ -77,6 +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
|
||||||
|
|
||||||
--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.
|
||||||
@ -111,6 +112,7 @@ def parse_cmd_line(argv):
|
|||||||
"cloud_user_name=",
|
"cloud_user_name=",
|
||||||
"cloud_api_key=",
|
"cloud_api_key=",
|
||||||
"instance_id=",
|
"instance_id=",
|
||||||
|
"region=",
|
||||||
"deadtime=",
|
"deadtime=",
|
||||||
"init-wait=",
|
"init-wait=",
|
||||||
"check-interval=",
|
"check-interval=",
|
||||||
@ -130,6 +132,7 @@ def parse_cmd_line(argv):
|
|||||||
cmd_line_option_list["cloud_user_name"] = None
|
cmd_line_option_list["cloud_user_name"] = None
|
||||||
cmd_line_option_list["cloud_api_key"] = None
|
cmd_line_option_list["cloud_api_key"] = None
|
||||||
cmd_line_option_list["instance_id"] = None
|
cmd_line_option_list["instance_id"] = None
|
||||||
|
cmd_line_option_list["region"] = None
|
||||||
cmd_line_option_list["deadtime"] = 60 * 60 #minutes
|
cmd_line_option_list["deadtime"] = 60 * 60 #minutes
|
||||||
cmd_line_option_list["check-interval"] = None
|
cmd_line_option_list["check-interval"] = None
|
||||||
cmd_line_option_list["init-wait"] = 5 * 60
|
cmd_line_option_list["init-wait"] = 5 * 60
|
||||||
@ -145,7 +148,8 @@ def parse_cmd_line(argv):
|
|||||||
else:
|
else:
|
||||||
cmd_line_option_list['syslog'] = ('localhost',514)
|
cmd_line_option_list['syslog'] = ('localhost',514)
|
||||||
|
|
||||||
get_gns3config(cmd_line_option_list)
|
|
||||||
|
get_gns3secrets(cmd_line_option_list)
|
||||||
|
|
||||||
for opt, val in opts:
|
for opt, val in opts:
|
||||||
if (opt in ("-h", "--help")):
|
if (opt in ("-h", "--help")):
|
||||||
@ -161,6 +165,8 @@ def parse_cmd_line(argv):
|
|||||||
cmd_line_option_list["cloud_api_key"] = val
|
cmd_line_option_list["cloud_api_key"] = val
|
||||||
elif (opt in ("--instance_id")):
|
elif (opt in ("--instance_id")):
|
||||||
cmd_line_option_list["instance_id"] = val
|
cmd_line_option_list["instance_id"] = val
|
||||||
|
elif (opt in ("--region")):
|
||||||
|
cmd_line_option_list["region"] = val
|
||||||
elif (opt in ("--deadtime")):
|
elif (opt in ("--deadtime")):
|
||||||
cmd_line_option_list["deadtime"] = int(val)
|
cmd_line_option_list["deadtime"] = int(val)
|
||||||
elif (opt in ("--check-interval")):
|
elif (opt in ("--check-interval")):
|
||||||
@ -199,9 +205,15 @@ def parse_cmd_line(argv):
|
|||||||
print(usage)
|
print(usage)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
if cmd_line_option_list["region"] is None:
|
||||||
|
print("You need to specify a region")
|
||||||
|
print(usage)
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
return cmd_line_option_list
|
return cmd_line_option_list
|
||||||
|
|
||||||
def get_gns3config(cmd_line_option_list):
|
def get_gns3secrets(cmd_line_option_list):
|
||||||
"""
|
"""
|
||||||
Load cloud credentials from .gns3secrets
|
Load cloud credentials from .gns3secrets
|
||||||
"""
|
"""
|
||||||
@ -224,17 +236,6 @@ def get_gns3config(cmd_line_option_list):
|
|||||||
except configparser.NoSectionError:
|
except configparser.NoSectionError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
cloud_config_file = "%s/.config/GNS3/cloud.conf" % (
|
|
||||||
os.path.expanduser("~/"))
|
|
||||||
|
|
||||||
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):
|
def set_logging(cmd_options):
|
||||||
"""
|
"""
|
||||||
@ -351,9 +352,8 @@ def main():
|
|||||||
|
|
||||||
log.info("Received shutdown signal")
|
log.info("Received shutdown signal")
|
||||||
options["shutdown"] = True
|
options["shutdown"] = True
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
pid_file = "%s/.gns3ias.pid" % (expanduser("~"))
|
pid_file = "%s/.gns3dms.pid" % (expanduser("~"))
|
||||||
|
|
||||||
if options["shutdown"]:
|
if options["shutdown"]:
|
||||||
send_shutdown(pid_file)
|
send_shutdown(pid_file)
|
||||||
|
@ -60,6 +60,15 @@ class daemon:
|
|||||||
def delpid(self):
|
def delpid(self):
|
||||||
os.remove(self.pidfile)
|
os.remove(self.pidfile)
|
||||||
|
|
||||||
|
def check_pid(self, pid):
|
||||||
|
""" Check For the existence of a unix pid. """
|
||||||
|
try:
|
||||||
|
os.kill(pid, 0)
|
||||||
|
except OSError:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start the daemon."""
|
"""Start the daemon."""
|
||||||
|
|
||||||
@ -72,10 +81,16 @@ class daemon:
|
|||||||
pid = None
|
pid = None
|
||||||
|
|
||||||
if pid:
|
if pid:
|
||||||
message = "pidfile {0} already exist. " + \
|
pid_exist = self.check_pid(pid)
|
||||||
"Daemon already running?\n"
|
|
||||||
|
if pid_exist:
|
||||||
|
message = "Already running: %s\n" % (pid)
|
||||||
|
sys.stderr.write(message)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
message = "pidfile {0} already exist. " + \
|
||||||
|
"but process is dead\n"
|
||||||
sys.stderr.write(message.format(self.pidfile))
|
sys.stderr.write(message.format(self.pidfile))
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Start the daemon
|
# Start the daemon
|
||||||
self.daemonize()
|
self.daemonize()
|
||||||
|
@ -41,6 +41,7 @@ class Rackspace(object):
|
|||||||
self.authenticated = False
|
self.authenticated = False
|
||||||
self.hostname = socket.gethostname()
|
self.hostname = socket.gethostname()
|
||||||
self.instance_id = options["instance_id"]
|
self.instance_id = options["instance_id"]
|
||||||
|
self.region = options["region"]
|
||||||
|
|
||||||
log.debug("Authenticating with Rackspace")
|
log.debug("Authenticating with Rackspace")
|
||||||
log.debug("My hostname: %s" % (self.hostname))
|
log.debug("My hostname: %s" % (self.hostname))
|
||||||
@ -51,16 +52,17 @@ class Rackspace(object):
|
|||||||
if self.authenticated == False:
|
if self.authenticated == False:
|
||||||
log.critical("Not authenticated against rackspace!!!!")
|
log.critical("Not authenticated against rackspace!!!!")
|
||||||
|
|
||||||
for region_dict in self.rksp.list_regions():
|
for region in self.rksp.list_regions():
|
||||||
region_k, region_v = region_dict.popitem()
|
log.debug("Rackspace regions: %s" % (region))
|
||||||
log.debug("Checking region: %s" % (region_k))
|
|
||||||
self.rksp.set_region(region_v)
|
log.debug("Checking region: %s" % (self.region))
|
||||||
for server in self.rksp.list_instances():
|
self.rksp.set_region(self.region)
|
||||||
log.debug("Checking server: %s" % (server.name))
|
for server in self.rksp.list_instances():
|
||||||
if server.name.lower() == self.hostname.lower() and server.id == self.instance_id:
|
log.debug("Checking server: %s" % (server.name))
|
||||||
log.info("Found matching instance: %s" % (server.id))
|
if server.name.lower() == self.hostname.lower() and server.id == self.instance_id:
|
||||||
log.info("Startup id: %s" % (self.instance_id))
|
log.info("Found matching instance: %s" % (server.id))
|
||||||
return server
|
log.info("Startup id: %s" % (self.instance_id))
|
||||||
|
return server
|
||||||
|
|
||||||
def terminate(self):
|
def terminate(self):
|
||||||
server = self._find_my_instance()
|
server = self._find_my_instance()
|
||||||
|
Loading…
Reference in New Issue
Block a user