No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

slim.py 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. #!/usr/bin/env python3
  2. #-*- coding: utf-8 -*-
  3. import os, os.path
  4. import sys
  5. import shutil
  6. import argparse
  7. import logging
  8. import re
  9. import json
  10. import configparser
  11. import signal
  12. import subprocess
  13. from lodel import buildconf
  14. logging.basicConfig(level=logging.INFO)
  15. INSTANCES_ABSPATH="/tmp/lodel2_instances"
  16. LODEL2_INSTALLDIR="/usr/lib/python3/dist-packages"
  17. CONFFILE='conf.d/lodel2.ini'
  18. try:
  19. STORE_FILE = os.path.join("[@]SLIM_VAR_DIR[@]", 'slim_instances.json')
  20. PID_FILE = os.path.join("[@]SLIM_VAR_DIR[@]", 'slim_instances_pid.json')
  21. CREATION_SCRIPT = os.path.join("[@]LODEL2_PROGSDIR[@]", 'create_instance')
  22. INSTALL_TPL = "[@]INSTALLMODEL_DIR[@]"
  23. EMFILE = os.path.join("[@]SLIM_DATADIR[@]", 'emfile.pickle')
  24. except SyntaxError:
  25. STORE_FILE='./instances.json'
  26. PID_FILE = './slim_instances_pid.json'
  27. CREATION_SCRIPT='../scripts/create_instance.sh'
  28. INSTALL_TPL = './slim_ressources/slim_install_model'
  29. EMFILE = './slim_ressources/emfile.pickle'
  30. CREATION_SCRIPT=os.path.join(os.path.dirname(__file__), CREATION_SCRIPT)
  31. STORE_FILE=os.path.join(os.path.dirname(__file__), STORE_FILE)
  32. INSTALL_TPL=os.path.join(os.path.dirname(__file__), INSTALL_TPL)
  33. EMFILE=os.path.join(os.path.dirname(__file__), EMFILE)
  34. #STORE_FILE syntax :
  35. #
  36. #First level keys are instances names, their values are dict with following
  37. #informations :
  38. # - path
  39. #
  40. ##@brief Run 'make %target%' for each instances given in names
  41. #@param target str : make target
  42. #@param names list : list of instance name
  43. def run_make(target, names):
  44. validate_names(names)
  45. store_datas = get_store_datas()
  46. cwd = os.getcwd()
  47. for name in [n for n in store_datas if n in names]:
  48. datas = store_datas[name]
  49. logging.info("Running 'make %s' for '%s' in %s" % (
  50. target, name, datas['path']))
  51. os.chdir(datas['path'])
  52. os.system('make %s' % target)
  53. os.chdir(cwd)
  54. ##@brief Set configuration given args
  55. #@param args as returned by argparse
  56. def set_conf(name, args):
  57. validate_names([name])
  58. conffile = get_conffile(name)
  59. config = configparser.ConfigParser(interpolation=None)
  60. config.read(conffile)
  61. if args.interface is not None:
  62. iarg = args.interface
  63. if iarg not in ('web', 'python'):
  64. raise TypeError("Interface can only be on of : 'web', 'python'")
  65. if iarg.lower() == 'web':
  66. iarg = 'webui'
  67. else:
  68. iarg = ''
  69. config['lodel2']['interface'] = iarg
  70. interface = config['lodel2']['interface']
  71. if interface == 'webui':
  72. if 'lodel2.webui' not in config:
  73. config['lodel2.webui'] = dict()
  74. config['lodel2.webui']['standalone'] = 'uwsgi'
  75. if args.listen_port is not None:
  76. config['lodel2.webui']['listen_port'] = str(args.listen_port)
  77. if args.listen_address is not None:
  78. config['lodel2.webui']['listen_address'] = str(args.listen_address)
  79. if args.static_url is not None:
  80. config['lodel2.webui']['static_url'] = str(args.static_url)
  81. if args.uwsgi_workers is not None:
  82. config['lodel2.webui']['uwsgi_workers'] = str(args.uwsgi_workers)
  83. else: #interface is python
  84. if args.listen_port is not None or args.listen_address is not None:
  85. logging.error("Listen port and listen address will not being set. \
  86. Selected interface is not the web iterface")
  87. if 'lodel.webui' in config:
  88. del(config['lodel2.webui'])
  89. if args.datasource_connectors is not None:
  90. darg = args.datasource_connectors
  91. if darg not in ('dummy', 'mongodb'):
  92. raise ValueError("Allowed connectors are : 'dummy' and 'mongodb'")
  93. if darg not in ('mongodb',):
  94. raise TypeError("Datasource_connectors can only be of : 'mongodb'")
  95. if darg.lower() == 'mongodb':
  96. dconf = 'mongodb_datasource'
  97. toadd = 'mongodb_datasource'
  98. todel = 'dummy_datasource'
  99. else:
  100. dconf = 'dummy_datasource'
  101. todel = 'mongodb_datasource'
  102. toadd = 'dummy_datasource'
  103. config['lodel2']['datasource_connectors'] = dconf
  104. #Delete old default & dummy2 conn
  105. kdel = 'lodel2.datasource.%s.%s' % (todel, 'default')
  106. if kdel in config:
  107. del(config[kdel])
  108. #Add the new default & dummy2 conn
  109. kadd = 'lodel2.datasource.%s.%s' % (toadd, 'default')
  110. if kadd not in config:
  111. config[kadd] = dict()
  112. #Bind to current conn
  113. for dsn in ('default', 'dummy2'):
  114. config['lodel2.datasources.%s' %dsn ]= {
  115. 'identifier':'%s.default' % toadd}
  116. #Set the conf for mongodb
  117. if darg == 'mongodb':
  118. dbconfname = 'lodel2.datasource.mongodb_datasource.default'
  119. if args.host is not None:
  120. config[dbconfname]['host'] = str(args.host)
  121. if args.user is not None:
  122. config[dbconfname]['username'] = str(args.user)
  123. if args.password is not None:
  124. config[dbconfname]['password'] = str(args.password)
  125. if args.db_name is not None:
  126. config[dbconfname]['db_name'] = str(args.db_name)
  127. else:
  128. config['lodel2.datasource.dummy_datasource.default'] = {'dummy':''}
  129. #Now config should be OK to be written again in conffile
  130. with open(conffile, 'w+') as cfp:
  131. config.write(cfp)
  132. ##@brief If the name is not valid raise
  133. def name_is_valid(name):
  134. allowed_chars = [chr(i) for i in range(ord('a'), ord('z')+1)]
  135. allowed_chars += [chr(i) for i in range(ord('A'), ord('Z')+1)]
  136. allowed_chars += [chr(i) for i in range(ord('0'), ord('9')+1)]
  137. allowed_chars += ['_']
  138. for c in name:
  139. if c not in allowed_chars:
  140. raise RuntimeError("Allowed characters for instance name are \
  141. lower&upper alphanum and '_'. Name '%s' is invalid" % name)
  142. ##@brief Create a new instance
  143. #@param name str : the instance name
  144. def new_instance(name):
  145. name_is_valid(name)
  146. store_datas = get_store_datas()
  147. if name in store_datas:
  148. logging.error("An instance named '%s' already exists" % name)
  149. exit(1)
  150. if not os.path.isdir(INSTANCES_ABSPATH):
  151. logging.info("Instances directory '%s' don't exists, creating it")
  152. os.mkdir(INSTANCES_ABSPATH)
  153. instance_path = os.path.join(INSTANCES_ABSPATH, name)
  154. creation_cmd = '{script} "{name}" "{path}" "{install_tpl}" \
  155. "{emfile}"'.format(
  156. script = CREATION_SCRIPT,
  157. name = name,
  158. path = instance_path,
  159. install_tpl = INSTALL_TPL,
  160. emfile = EMFILE)
  161. res = os.system(creation_cmd)
  162. if res != 0:
  163. logging.error("Creation script fails")
  164. exit(res)
  165. #storing new instance
  166. store_datas[name] = {'path': instance_path}
  167. save_datas(store_datas)
  168. ##@brief Delete an instance
  169. #@param name str : the instance name
  170. def delete_instance(name):
  171. pids = get_pids()
  172. if name in pids:
  173. logging.error("The instance '%s' is started. Stop it before deleting \
  174. it" % name)
  175. return
  176. store_datas = get_store_datas()
  177. logging.warning("Deleting instance %s" % name)
  178. logging.info("Deleting instance folder %s" % store_datas[name]['path'])
  179. shutil.rmtree(store_datas[name]['path'])
  180. logging.debug("Deleting instance from json store file")
  181. del(store_datas[name])
  182. save_datas(store_datas)
  183. ##@brief returns stored datas
  184. def get_store_datas():
  185. if not os.path.isfile(STORE_FILE) or os.stat(STORE_FILE).st_size == 0:
  186. return dict()
  187. else:
  188. with open(STORE_FILE, 'r') as sfp:
  189. datas = json.load(sfp)
  190. return datas
  191. ##@brief Checks names validity and exit if fails
  192. def validate_names(names):
  193. store_datas = get_store_datas()
  194. invalid = [ n for n in names if n not in store_datas]
  195. if len(invalid) > 0:
  196. print("Following names are not existing instance :", file=sys.stderr)
  197. for name in invalid:
  198. print("\t%s" % name, file=sys.stderr)
  199. exit(1)
  200. ##@brief Returns the PID dict
  201. #@return a dict with instance name as key an PID as value
  202. def get_pids():
  203. if not os.path.isfile(PID_FILE) or os.stat(PID_FILE).st_size == 0:
  204. return dict()
  205. with open(PID_FILE, 'r') as pfd:
  206. return json.load(pfd)
  207. ##@brief Save a dict of pid
  208. #@param pid_dict dict : key is instance name values are pid
  209. def save_pids(pid_dict):
  210. with open(PID_FILE, 'w+') as pfd:
  211. json.dump(pid_dict, pfd)
  212. ##@brief Given an instance name returns its PID
  213. #@return False or an int
  214. def get_pid(name):
  215. pid_datas = get_pids()
  216. if name not in pid_datas:
  217. return False
  218. else:
  219. pid = pid_datas[name]
  220. if not is_running(name, pid):
  221. return False
  222. return pid
  223. ##@brief Start an instance
  224. #@param names list : instance name list
  225. def start_instances(names, foreground):
  226. pids = get_pids()
  227. store_datas = get_store_datas()
  228. for name in names:
  229. if name in pids:
  230. logging.warning("The instance %s is allready running" % name)
  231. continue
  232. os.chdir(store_datas[name]['path'])
  233. args = [sys.executable, 'loader.py']
  234. if foreground:
  235. logging.info("Calling execl with : %s" % args)
  236. os.execl(args[0], *args)
  237. return #only usefull if execl call fails (not usefull)
  238. else:
  239. curexec = subprocess.Popen(args,
  240. stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
  241. stderr=subprocess.DEVNULL, preexec_fn=os.setsid,
  242. cwd = store_datas[name]['path'])
  243. pids[name] = curexec.pid
  244. logging.info("Instance '%s' started. PID %d" % (name, curexec.pid))
  245. save_pids(pids)
  246. ##@brief Stop an instance given its name
  247. #@param names list : names list
  248. def stop_instances(names):
  249. pids = get_pids()
  250. store_datas = get_store_datas()
  251. for name in names:
  252. if name not in pids:
  253. logging.warning("The instance %s is not running" % name)
  254. continue
  255. pid = pids[name]
  256. try:
  257. os.kill(pid, signal.SIGTERM)
  258. except ProcessLookupError:
  259. logging.warning("The instance %s seems to be in error, no process \
  260. with pid %d found" % (name, pids[name]))
  261. del(pids[name])
  262. save_pids(pids)
  263. ##@brief Checks that a process is running
  264. #
  265. #If not running clean the pid list
  266. #@return bool
  267. def is_running(name, pid):
  268. try:
  269. os.kill(pid, 0)
  270. return True
  271. except (OSError,ProcessLookupError):
  272. pid_datas = get_pids()
  273. logging.warning("Instance '%s' was marked as running, but not \
  274. process with pid %d found. Cleaning pid list" % (name, pid))
  275. del(pid_datas[name])
  276. save_pids(pid_datas)
  277. return False
  278. ##@brief Check if instance are specified
  279. def get_specified(args):
  280. if args.all:
  281. names = list(get_store_datas().keys())
  282. elif args.name is not None:
  283. names = args.name
  284. else:
  285. names = None
  286. return sorted(names)
  287. ##@brief Saves store datas
  288. def save_datas(datas):
  289. with open(STORE_FILE, 'w+') as sfp:
  290. json.dump(datas, sfp)
  291. ##@return conffile path
  292. def get_conffile(name):
  293. validate_names([name])
  294. store_datas = get_store_datas()
  295. return os.path.join(store_datas[name]['path'], CONFFILE)
  296. ##@brief Print the list of instances and exit
  297. #@param verbosity int
  298. #@param batch bool : if true make simple output
  299. def list_instances(verbosity, batch):
  300. verbosity = 0 if verbosity is None else verbosity
  301. if not os.path.isfile(STORE_FILE):
  302. print("No store file, no instances are existing. Exiting...",
  303. file=sys.stderr)
  304. exit(0)
  305. store_datas = get_store_datas()
  306. if not batch:
  307. print('Instances list :')
  308. for name in store_datas:
  309. details_instance(name, verbosity, batch)
  310. exit(0)
  311. ##@brief Print instance informations and return (None)
  312. #@param name str : instance name
  313. #@param verbosity int
  314. #@param batch bool : if true make simple output
  315. def details_instance(name, verbosity, batch):
  316. validate_names([name])
  317. store_datas = get_store_datas()
  318. pids = get_pids()
  319. if not batch:
  320. msg = "\t- '%s'" % name
  321. if name in pids and is_running(name, pids[name]):
  322. msg += ' [Run PID %d] ' % pids[name]
  323. if verbosity > 0:
  324. msg += ' path = "%s"' % store_datas[name]['path']
  325. if verbosity > 1:
  326. ruler = (''.join(['=' for _ in range(20)])) + "\n"
  327. msg += "\n\t\t====conf.d/lodel2.ini====\n"
  328. with open(get_conffile(name)) as cfp:
  329. for line in cfp:
  330. msg += "\t\t"+line
  331. msg += "\t\t=========================\n"
  332. print(msg)
  333. else:
  334. msg = name
  335. if name in pids and is_running(name, pids[name]):
  336. msg += ' %d ' % pids[name]
  337. else:
  338. msg += ' stopped '
  339. if verbosity > 0:
  340. msg += "\t"+'"%s"' % store_datas[name]['path']
  341. if verbosity > 1:
  342. conffile = get_conffile(name)
  343. msg += "\n\t#####"+conffile+"#####\n"
  344. with open(conffile, 'r') as cfp:
  345. for line in cfp:
  346. msg += "\t"+line
  347. msg += "\n\t###########"
  348. print(msg)
  349. ##@brief Given instance names generate nginx confs
  350. #@param names list : list of instance names
  351. def nginx_conf(names):
  352. ret = """
  353. server {
  354. listen 80;
  355. server_name _;
  356. include uwsgi_params;
  357. location /static/ {
  358. alias """ + LODEL2_INSTALLDIR + """/lodel/plugins/webui/templates/;
  359. }
  360. """
  361. for name in names:
  362. name = name.replace('/', '_')
  363. sockfile = os.path.join(buildconf.LODEL2VARDIR, 'uwsgi_sockets/')
  364. sockfile = os.path.join(sockfile, name + '.sock')
  365. ret += """
  366. location /{instance_name}/ {{
  367. uwsgi_pass unix://{sockfile};
  368. }}""".format(instance_name = name, sockfile = sockfile)
  369. ret += """
  370. }
  371. """
  372. print(ret)
  373. ##@brief Returns instanciated parser
  374. def get_parser():
  375. parser = argparse.ArgumentParser(
  376. description='SLIM (Simple Lodel Instance Manager.)')
  377. selector = parser.add_argument_group('Instances selectors')
  378. actions = parser.add_argument_group('Instances actions')
  379. confs = parser.add_argument_group('Options (use with -c or -s)')
  380. startstop = parser.add_argument_group('Start/stop options')
  381. parser.add_argument('-l', '--list',
  382. help='list existing instances and exit', action='store_const',
  383. const=True, default=False)
  384. parser.add_argument('-v', '--verbose', action='count')
  385. parser.add_argument('-b', '--batch', action='store_const',
  386. default=False, const=True,
  387. help="Format output (when possible) making it usable by POSIX scripts \
  388. (only implemented for -l for the moment)")
  389. selector.add_argument('-a', '--all', action='store_const',
  390. default=False, const=True,
  391. help='Select all instances')
  392. selector.add_argument('-n', '--name', metavar='NAME', type=str, nargs='*',
  393. help="Specify an instance name")
  394. actions.add_argument('-c', '--create', action='store_const',
  395. default=False, const=True,
  396. help="Create a new instance with given name (see -n --name)")
  397. actions.add_argument('-d', '--delete', action='store_const',
  398. default=False, const=True,
  399. help="Delete an instance with given name (see -n --name)")
  400. actions.add_argument('-p', '--purge', action='store_const',
  401. default=False, const=True,
  402. help="Delete ALL instances")
  403. actions.add_argument('-s', '--set-option', action='store_const',
  404. default=False, const=True,
  405. help="Use this flag to set options on instance")
  406. actions.add_argument('-e', '--edit-config', action='store_const',
  407. default=False, const=True,
  408. help='Edit configuration of specified instance')
  409. actions.add_argument('-i', '--interactive', action='store_const',
  410. default=False, const=True,
  411. help='Run a loader.py from ONE instance in foreground')
  412. actions.add_argument('-m', '--make', metavar='TARGET', type=str,
  413. nargs="?", default='not',
  414. help='Run make for selected instances')
  415. actions.add_argument('--nginx-conf', action='store_const',
  416. default = False, const=True,
  417. help="Output a conf for nginx given selected instances")
  418. startstop.add_argument('--stop', action='store_const',
  419. default=False, const=True, help="Stop instances")
  420. startstop.add_argument('--start', action='store_const',
  421. default=False, const=True, help="Start instances")
  422. startstop.add_argument('-f', '--foreground', action='store_const',
  423. default=False, const=True, help="Start in foreground (limited \
  424. to 1 instance")
  425. confs.add_argument('--interface', type=str,
  426. help="Select wich interface to run. Possible values are \
  427. 'python' and 'web'")
  428. confs.add_argument('-t', '--static-url', type=str, nargs="?",
  429. default='http://127.0.0.1/static/', metavar='URL',
  430. help='Set an url for static documents')
  431. confs.add_argument('--listen-port', type=int,
  432. help="Select the port on wich the web interface will listen to")
  433. confs.add_argument('--listen-address', type=str,
  434. help="Select the address on wich the web interface will bind to")
  435. confs.add_argument('--datasource_connectors', type=str,
  436. help="Select wich datasource to connect. Possible values are \
  437. 'mongodb' and 'mysql'")
  438. confs.add_argument('--host', type=str,
  439. help="Select the host on which the server DB listen to")
  440. confs.add_argument('--user', type=str,
  441. help="Select the user name to connect to the database")
  442. confs.add_argument('--password', type=str,
  443. help="Select the password name to connect the datasource")
  444. confs.add_argument('--db_name', type=str,
  445. help="Select the database name on which datasource will be connect")
  446. confs.add_argument('--uwsgi-workers', type=int, default='2',
  447. metavar = 'N', help="Number of workers to spawn at the start of uwsgi")
  448. return parser
  449. if __name__ == '__main__':
  450. parser = get_parser()
  451. args = parser.parse_args()
  452. if args.verbose is None:
  453. args.verbose = 0
  454. if args.list:
  455. # Instances list
  456. if args.name is not None:
  457. validate_names(args.name)
  458. for name in args.name:
  459. details_instance(name, args.verbose, args.batch)
  460. else:
  461. list_instances(args.verbose, args.batch)
  462. elif args.create:
  463. #Instance creation
  464. if args.name is None:
  465. parser.print_help()
  466. print("\nAn instance name expected when creating an instance !",
  467. file=sys.stderr)
  468. exit(1)
  469. for name in args.name:
  470. new_instance(name)
  471. elif args.purge:
  472. # SLIM Purge (stop & delete all)
  473. print("Do you really want to delete all the instances ? Yes/no ",)
  474. rep = sys.stdin.readline()
  475. if rep == "Yes\n":
  476. store = get_store_datas()
  477. stop_instances(store.keys())
  478. for name in store:
  479. delete_instance(name)
  480. elif rep.lower() != 'no':
  481. print("Expect exactly 'Yes' to confirm...")
  482. exit()
  483. elif args.delete:
  484. #Instance deletion
  485. if args.all:
  486. parser.print_help()
  487. print("\n use -p --purge instead of --delete --all",
  488. file=sys.stderr)
  489. exit(1)
  490. if args.name is None:
  491. parser.print_help()
  492. print("\nAn instance name expected when creating an instance !",
  493. file=sys.stderr)
  494. exit(1)
  495. validate_names(args.name)
  496. for name in args.name:
  497. delete_instance(name)
  498. elif args.make != 'not':
  499. #Running make in instances
  500. if args.make is None:
  501. target = 'all'
  502. else:
  503. target = args.make
  504. names = get_specified(args)
  505. if names is None:
  506. parser.print_help()
  507. print("\nWhen using -m --make options you have to select \
  508. instances, either by name using -n or all using -a")
  509. exit(1)
  510. run_make(target, names)
  511. elif args.edit_config:
  512. #Edit configuration
  513. names = get_specified(args)
  514. if len(names) > 1:
  515. print("\n-e --edit-config option works only when 1 instance is \
  516. specified")
  517. validate_names(names)
  518. name = names[0]
  519. store_datas = get_store_datas()
  520. conffile = get_conffile(name)
  521. os.system('editor "%s"' % conffile)
  522. exit(0)
  523. elif args.nginx_conf:
  524. names = get_specified(args)
  525. if len(names) == 0:
  526. parser.print_help()
  527. print("\nSpecify at least 1 instance or use --all")
  528. exit(1)
  529. nginx_conf(names)
  530. elif args.interactive:
  531. #Run loader.py in foreground
  532. if args.name is None or len(args.name) != 1:
  533. print("\n-i option only allowed with ONE instance name")
  534. parser.print_help()
  535. exit(1)
  536. validate_names(args.name)
  537. name = args.name[0]
  538. store_datas = get_store_datas()
  539. os.chdir(store_datas[name]['path'])
  540. os.execl('/usr/bin/env', '/usr/bin/env', 'python3', 'loader.py')
  541. elif args.set_option:
  542. names = None
  543. if args.all:
  544. names = list(get_store_datas().values())
  545. elif args.name is not None:
  546. names = args.name
  547. if names is None:
  548. parser.print_help()
  549. print("\n-s option only allowed with instance specified (by name \
  550. or with -a)")
  551. exit(1)
  552. for name in names:
  553. set_conf(name, args)
  554. elif args.start:
  555. names = get_specified(args)
  556. if names is None:
  557. parser.print_help()
  558. print("\nPlease specify at least 1 instance with the --start \
  559. option", file=sys.stderr)
  560. elif args.foreground and len(names) > 1:
  561. parser.prin_help()
  562. print("\nOnly 1 instance allowed with the use of the --forground \
  563. argument")
  564. start_instances(names, args.foreground)
  565. elif args.stop:
  566. names = get_specified(args)
  567. stop_instances(names)