project.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. from __future__ import absolute_import
  2. from __future__ import unicode_literals
  3. import datetime
  4. import logging
  5. import operator
  6. import re
  7. from functools import reduce
  8. import enum
  9. import six
  10. from docker.errors import APIError
  11. from . import parallel
  12. from .config import ConfigurationError
  13. from .config.config import V1
  14. from .config.sort_services import get_container_name_from_network_mode
  15. from .config.sort_services import get_service_name_from_network_mode
  16. from .const import IMAGE_EVENTS
  17. from .const import LABEL_ONE_OFF
  18. from .const import LABEL_PROJECT
  19. from .const import LABEL_SERVICE
  20. from .container import Container
  21. from .network import build_networks
  22. from .network import get_networks
  23. from .network import ProjectNetworks
  24. from .service import BuildAction
  25. from .service import ContainerNetworkMode
  26. from .service import ContainerPidMode
  27. from .service import ConvergenceStrategy
  28. from .service import NetworkMode
  29. from .service import parse_repository_tag
  30. from .service import PidMode
  31. from .service import Service
  32. from .service import ServiceNetworkMode
  33. from .service import ServicePidMode
  34. from .utils import microseconds_from_time_nano
  35. from .utils import truncate_string
  36. from .volume import ProjectVolumes
  37. log = logging.getLogger(__name__)
  38. @enum.unique
  39. class OneOffFilter(enum.Enum):
  40. include = 0
  41. exclude = 1
  42. only = 2
  43. @classmethod
  44. def update_labels(cls, value, labels):
  45. if value == cls.only:
  46. labels.append('{0}={1}'.format(LABEL_ONE_OFF, "True"))
  47. elif value == cls.exclude:
  48. labels.append('{0}={1}'.format(LABEL_ONE_OFF, "False"))
  49. elif value == cls.include:
  50. pass
  51. else:
  52. raise ValueError("Invalid value for one_off: {}".format(repr(value)))
  53. class Project(object):
  54. """
  55. A collection of services.
  56. """
  57. def __init__(self, name, services, client, networks=None, volumes=None, config_version=None):
  58. self.name = name
  59. self.services = services
  60. self.client = client
  61. self.volumes = volumes or ProjectVolumes({})
  62. self.networks = networks or ProjectNetworks({}, False)
  63. self.config_version = config_version
  64. def labels(self, one_off=OneOffFilter.exclude, legacy=False):
  65. name = self.name
  66. if legacy:
  67. name = re.sub(r'[_-]', '', name)
  68. labels = ['{0}={1}'.format(LABEL_PROJECT, name)]
  69. OneOffFilter.update_labels(one_off, labels)
  70. return labels
  71. @classmethod
  72. def from_config(cls, name, config_data, client, default_platform=None):
  73. """
  74. Construct a Project from a config.Config object.
  75. """
  76. use_networking = (config_data.version and config_data.version != V1)
  77. networks = build_networks(name, config_data, client)
  78. project_networks = ProjectNetworks.from_services(
  79. config_data.services,
  80. networks,
  81. use_networking)
  82. volumes = ProjectVolumes.from_config(name, config_data, client)
  83. project = cls(name, [], client, project_networks, volumes, config_data.version)
  84. for service_dict in config_data.services:
  85. service_dict = dict(service_dict)
  86. if use_networking:
  87. service_networks = get_networks(service_dict, networks)
  88. else:
  89. service_networks = {}
  90. service_dict.pop('networks', None)
  91. links = project.get_links(service_dict)
  92. network_mode = project.get_network_mode(
  93. service_dict, list(service_networks.keys())
  94. )
  95. pid_mode = project.get_pid_mode(service_dict)
  96. volumes_from = get_volumes_from(project, service_dict)
  97. if config_data.version != V1:
  98. service_dict['volumes'] = [
  99. volumes.namespace_spec(volume_spec)
  100. for volume_spec in service_dict.get('volumes', [])
  101. ]
  102. secrets = get_secrets(
  103. service_dict['name'],
  104. service_dict.pop('secrets', None) or [],
  105. config_data.secrets)
  106. project.services.append(
  107. Service(
  108. service_dict.pop('name'),
  109. client=client,
  110. project=name,
  111. use_networking=use_networking,
  112. networks=service_networks,
  113. links=links,
  114. network_mode=network_mode,
  115. volumes_from=volumes_from,
  116. secrets=secrets,
  117. pid_mode=pid_mode,
  118. platform=service_dict.pop('platform', None),
  119. default_platform=default_platform,
  120. **service_dict)
  121. )
  122. return project
  123. @property
  124. def service_names(self):
  125. return [service.name for service in self.services]
  126. def get_service(self, name):
  127. """
  128. Retrieve a service by name. Raises NoSuchService
  129. if the named service does not exist.
  130. """
  131. for service in self.services:
  132. if service.name == name:
  133. return service
  134. raise NoSuchService(name)
  135. def validate_service_names(self, service_names):
  136. """
  137. Validate that the given list of service names only contains valid
  138. services. Raises NoSuchService if one of the names is invalid.
  139. """
  140. valid_names = self.service_names
  141. for name in service_names:
  142. if name not in valid_names:
  143. raise NoSuchService(name)
  144. def get_services(self, service_names=None, include_deps=False):
  145. """
  146. Returns a list of this project's services filtered
  147. by the provided list of names, or all services if service_names is None
  148. or [].
  149. If include_deps is specified, returns a list including the dependencies for
  150. service_names, in order of dependency.
  151. Preserves the original order of self.services where possible,
  152. reordering as needed to resolve dependencies.
  153. Raises NoSuchService if any of the named services do not exist.
  154. """
  155. if service_names is None or len(service_names) == 0:
  156. service_names = self.service_names
  157. unsorted = [self.get_service(name) for name in service_names]
  158. services = [s for s in self.services if s in unsorted]
  159. if include_deps:
  160. services = reduce(self._inject_deps, services, [])
  161. uniques = []
  162. [uniques.append(s) for s in services if s not in uniques]
  163. return uniques
  164. def get_services_without_duplicate(self, service_names=None, include_deps=False):
  165. services = self.get_services(service_names, include_deps)
  166. for service in services:
  167. service.remove_duplicate_containers()
  168. return services
  169. def get_links(self, service_dict):
  170. links = []
  171. if 'links' in service_dict:
  172. for link in service_dict.get('links', []):
  173. if ':' in link:
  174. service_name, link_name = link.split(':', 1)
  175. else:
  176. service_name, link_name = link, None
  177. try:
  178. links.append((self.get_service(service_name), link_name))
  179. except NoSuchService:
  180. raise ConfigurationError(
  181. 'Service "%s" has a link to service "%s" which does not '
  182. 'exist.' % (service_dict['name'], service_name))
  183. del service_dict['links']
  184. return links
  185. def get_network_mode(self, service_dict, networks):
  186. network_mode = service_dict.pop('network_mode', None)
  187. if not network_mode:
  188. if self.networks.use_networking:
  189. return NetworkMode(networks[0]) if networks else NetworkMode('none')
  190. return NetworkMode(None)
  191. service_name = get_service_name_from_network_mode(network_mode)
  192. if service_name:
  193. return ServiceNetworkMode(self.get_service(service_name))
  194. container_name = get_container_name_from_network_mode(network_mode)
  195. if container_name:
  196. try:
  197. return ContainerNetworkMode(Container.from_id(self.client, container_name))
  198. except APIError:
  199. raise ConfigurationError(
  200. "Service '{name}' uses the network stack of container '{dep}' which "
  201. "does not exist.".format(name=service_dict['name'], dep=container_name))
  202. return NetworkMode(network_mode)
  203. def get_pid_mode(self, service_dict):
  204. pid_mode = service_dict.pop('pid', None)
  205. if not pid_mode:
  206. return PidMode(None)
  207. service_name = get_service_name_from_network_mode(pid_mode)
  208. if service_name:
  209. return ServicePidMode(self.get_service(service_name))
  210. container_name = get_container_name_from_network_mode(pid_mode)
  211. if container_name:
  212. try:
  213. return ContainerPidMode(Container.from_id(self.client, container_name))
  214. except APIError:
  215. raise ConfigurationError(
  216. "Service '{name}' uses the PID namespace of container '{dep}' which "
  217. "does not exist.".format(name=service_dict['name'], dep=container_name)
  218. )
  219. return PidMode(pid_mode)
  220. def start(self, service_names=None, **options):
  221. containers = []
  222. def start_service(service):
  223. service_containers = service.start(quiet=True, **options)
  224. containers.extend(service_containers)
  225. services = self.get_services(service_names)
  226. def get_deps(service):
  227. return {
  228. (self.get_service(dep), config)
  229. for dep, config in service.get_dependency_configs().items()
  230. }
  231. parallel.parallel_execute(
  232. services,
  233. start_service,
  234. operator.attrgetter('name'),
  235. 'Starting',
  236. get_deps,
  237. )
  238. return containers
  239. def stop(self, service_names=None, one_off=OneOffFilter.exclude, **options):
  240. containers = self.containers(service_names, one_off=one_off)
  241. def get_deps(container):
  242. # actually returning inversed dependencies
  243. return {(other, None) for other in containers
  244. if container.service in
  245. self.get_service(other.service).get_dependency_names()}
  246. parallel.parallel_execute(
  247. containers,
  248. self.build_container_operation_with_timeout_func('stop', options),
  249. operator.attrgetter('name'),
  250. 'Stopping',
  251. get_deps,
  252. )
  253. def pause(self, service_names=None, **options):
  254. containers = self.containers(service_names)
  255. parallel.parallel_pause(reversed(containers), options)
  256. return containers
  257. def unpause(self, service_names=None, **options):
  258. containers = self.containers(service_names)
  259. parallel.parallel_unpause(containers, options)
  260. return containers
  261. def kill(self, service_names=None, **options):
  262. parallel.parallel_kill(self.containers(service_names), options)
  263. def remove_stopped(self, service_names=None, one_off=OneOffFilter.exclude, **options):
  264. parallel.parallel_remove(self.containers(
  265. service_names, stopped=True, one_off=one_off
  266. ), options)
  267. def down(
  268. self,
  269. remove_image_type,
  270. include_volumes,
  271. remove_orphans=False,
  272. timeout=None,
  273. ignore_orphans=False):
  274. self.stop(one_off=OneOffFilter.include, timeout=timeout)
  275. if not ignore_orphans:
  276. self.find_orphan_containers(remove_orphans)
  277. self.remove_stopped(v=include_volumes, one_off=OneOffFilter.include)
  278. self.networks.remove()
  279. if include_volumes:
  280. self.volumes.remove()
  281. self.remove_images(remove_image_type)
  282. def remove_images(self, remove_image_type):
  283. for service in self.get_services():
  284. service.remove_image(remove_image_type)
  285. def restart(self, service_names=None, **options):
  286. containers = self.containers(service_names, stopped=True)
  287. parallel.parallel_execute(
  288. containers,
  289. self.build_container_operation_with_timeout_func('restart', options),
  290. operator.attrgetter('name'),
  291. 'Restarting',
  292. )
  293. return containers
  294. def build(self, service_names=None, no_cache=False, pull=False, force_rm=False, memory=None,
  295. build_args=None, gzip=False, parallel_build=False):
  296. services = []
  297. for service in self.get_services(service_names):
  298. if service.can_be_built():
  299. services.append(service)
  300. else:
  301. log.info('%s uses an image, skipping' % service.name)
  302. def build_service(service):
  303. service.build(no_cache, pull, force_rm, memory, build_args, gzip)
  304. if parallel_build:
  305. _, errors = parallel.parallel_execute(
  306. services,
  307. build_service,
  308. operator.attrgetter('name'),
  309. 'Building',
  310. limit=5,
  311. )
  312. if len(errors):
  313. combined_errors = '\n'.join([
  314. e.decode('utf-8') if isinstance(e, six.binary_type) else e for e in errors.values()
  315. ])
  316. raise ProjectError(combined_errors)
  317. else:
  318. for service in services:
  319. build_service(service)
  320. def create(
  321. self,
  322. service_names=None,
  323. strategy=ConvergenceStrategy.changed,
  324. do_build=BuildAction.none,
  325. ):
  326. services = self.get_services_without_duplicate(service_names, include_deps=True)
  327. for svc in services:
  328. svc.ensure_image_exists(do_build=do_build)
  329. plans = self._get_convergence_plans(services, strategy)
  330. for service in services:
  331. service.execute_convergence_plan(
  332. plans[service.name],
  333. detached=True,
  334. start=False)
  335. def events(self, service_names=None):
  336. def build_container_event(event, container):
  337. time = datetime.datetime.fromtimestamp(event['time'])
  338. time = time.replace(
  339. microsecond=microseconds_from_time_nano(event['timeNano']))
  340. return {
  341. 'time': time,
  342. 'type': 'container',
  343. 'action': event['status'],
  344. 'id': container.id,
  345. 'service': container.service,
  346. 'attributes': {
  347. 'name': container.name,
  348. 'image': event['from'],
  349. },
  350. 'container': container,
  351. }
  352. service_names = set(service_names or self.service_names)
  353. for event in self.client.events(
  354. filters={'label': self.labels()},
  355. decode=True
  356. ):
  357. # The first part of this condition is a guard against some events
  358. # broadcasted by swarm that don't have a status field.
  359. # See https://github.com/docker/compose/issues/3316
  360. if 'status' not in event or event['status'] in IMAGE_EVENTS:
  361. # We don't receive any image events because labels aren't applied
  362. # to images
  363. continue
  364. # TODO: get labels from the API v1.22 , see github issue 2618
  365. try:
  366. # this can fail if the container has been removed
  367. container = Container.from_id(self.client, event['id'])
  368. except APIError:
  369. continue
  370. if container.service not in service_names:
  371. continue
  372. yield build_container_event(event, container)
  373. def up(self,
  374. service_names=None,
  375. start_deps=True,
  376. strategy=ConvergenceStrategy.changed,
  377. do_build=BuildAction.none,
  378. timeout=None,
  379. detached=False,
  380. remove_orphans=False,
  381. ignore_orphans=False,
  382. scale_override=None,
  383. rescale=True,
  384. start=True,
  385. always_recreate_deps=False,
  386. reset_container_image=False,
  387. renew_anonymous_volumes=False,
  388. silent=False,
  389. ):
  390. self.initialize()
  391. if not ignore_orphans:
  392. self.find_orphan_containers(remove_orphans)
  393. if scale_override is None:
  394. scale_override = {}
  395. services = self.get_services_without_duplicate(
  396. service_names,
  397. include_deps=start_deps)
  398. for svc in services:
  399. svc.ensure_image_exists(do_build=do_build, silent=silent)
  400. plans = self._get_convergence_plans(
  401. services, strategy, always_recreate_deps=always_recreate_deps)
  402. def do(service):
  403. return service.execute_convergence_plan(
  404. plans[service.name],
  405. timeout=timeout,
  406. detached=detached,
  407. scale_override=scale_override.get(service.name),
  408. rescale=rescale,
  409. start=start,
  410. reset_container_image=reset_container_image,
  411. renew_anonymous_volumes=renew_anonymous_volumes,
  412. )
  413. def get_deps(service):
  414. return {
  415. (self.get_service(dep), config)
  416. for dep, config in service.get_dependency_configs().items()
  417. }
  418. results, errors = parallel.parallel_execute(
  419. services,
  420. do,
  421. operator.attrgetter('name'),
  422. None,
  423. get_deps,
  424. )
  425. if errors:
  426. raise ProjectError(
  427. 'Encountered errors while bringing up the project.'
  428. )
  429. return [
  430. container
  431. for svc_containers in results
  432. if svc_containers is not None
  433. for container in svc_containers
  434. ]
  435. def initialize(self):
  436. self.networks.initialize()
  437. self.volumes.initialize()
  438. def _get_convergence_plans(self, services, strategy, always_recreate_deps=False):
  439. plans = {}
  440. for service in services:
  441. updated_dependencies = [
  442. name
  443. for name in service.get_dependency_names()
  444. if name in plans and
  445. plans[name].action in ('recreate', 'create')
  446. ]
  447. if updated_dependencies and strategy.allows_recreate:
  448. log.debug('%s has upstream changes (%s)',
  449. service.name,
  450. ", ".join(updated_dependencies))
  451. containers_stopped = any(
  452. service.containers(stopped=True, filters={'status': ['created', 'exited']}))
  453. has_links = any(c.get('HostConfig.Links') for c in service.containers())
  454. if always_recreate_deps or containers_stopped or not has_links:
  455. plan = service.convergence_plan(ConvergenceStrategy.always)
  456. else:
  457. plan = service.convergence_plan(strategy)
  458. else:
  459. plan = service.convergence_plan(strategy)
  460. plans[service.name] = plan
  461. return plans
  462. def pull(self, service_names=None, ignore_pull_failures=False, parallel_pull=False, silent=False,
  463. include_deps=False):
  464. services = self.get_services(service_names, include_deps)
  465. msg = not silent and 'Pulling' or None
  466. if parallel_pull:
  467. def pull_service(service):
  468. strm = service.pull(ignore_pull_failures, True, stream=True)
  469. if strm is None: # Attempting to pull service with no `image` key is a no-op
  470. return
  471. writer = parallel.get_stream_writer()
  472. for event in strm:
  473. if 'status' not in event:
  474. continue
  475. status = event['status'].lower()
  476. if 'progressDetail' in event:
  477. detail = event['progressDetail']
  478. if 'current' in detail and 'total' in detail:
  479. percentage = float(detail['current']) / float(detail['total'])
  480. status = '{} ({:.1%})'.format(status, percentage)
  481. writer.write(
  482. msg, service.name, truncate_string(status), lambda s: s
  483. )
  484. _, errors = parallel.parallel_execute(
  485. services,
  486. pull_service,
  487. operator.attrgetter('name'),
  488. msg,
  489. limit=5,
  490. )
  491. if len(errors):
  492. combined_errors = '\n'.join([
  493. e.decode('utf-8') if isinstance(e, six.binary_type) else e for e in errors.values()
  494. ])
  495. raise ProjectError(combined_errors)
  496. else:
  497. for service in services:
  498. service.pull(ignore_pull_failures, silent=silent)
  499. def push(self, service_names=None, ignore_push_failures=False):
  500. unique_images = set()
  501. for service in self.get_services(service_names, include_deps=False):
  502. # Considering <image> and <image:latest> as the same
  503. repo, tag, sep = parse_repository_tag(service.image_name)
  504. service_image_name = sep.join((repo, tag)) if tag else sep.join((repo, 'latest'))
  505. if service_image_name not in unique_images:
  506. service.push(ignore_push_failures)
  507. unique_images.add(service_image_name)
  508. def _labeled_containers(self, stopped=False, one_off=OneOffFilter.exclude):
  509. ctnrs = list(filter(None, [
  510. Container.from_ps(self.client, container)
  511. for container in self.client.containers(
  512. all=stopped,
  513. filters={'label': self.labels(one_off=one_off)})])
  514. )
  515. if ctnrs:
  516. return ctnrs
  517. return list(filter(lambda c: c.has_legacy_proj_name(self.name), filter(None, [
  518. Container.from_ps(self.client, container)
  519. for container in self.client.containers(
  520. all=stopped,
  521. filters={'label': self.labels(one_off=one_off, legacy=True)})])
  522. ))
  523. def containers(self, service_names=None, stopped=False, one_off=OneOffFilter.exclude):
  524. if service_names:
  525. self.validate_service_names(service_names)
  526. else:
  527. service_names = self.service_names
  528. containers = self._labeled_containers(stopped, one_off)
  529. def matches_service_names(container):
  530. return container.labels.get(LABEL_SERVICE) in service_names
  531. return [c for c in containers if matches_service_names(c)]
  532. def find_orphan_containers(self, remove_orphans):
  533. def _find():
  534. containers = self._labeled_containers()
  535. for ctnr in containers:
  536. service_name = ctnr.labels.get(LABEL_SERVICE)
  537. if service_name not in self.service_names:
  538. yield ctnr
  539. orphans = list(_find())
  540. if not orphans:
  541. return
  542. if remove_orphans:
  543. for ctnr in orphans:
  544. log.info('Removing orphan container "{0}"'.format(ctnr.name))
  545. ctnr.kill()
  546. ctnr.remove(force=True)
  547. else:
  548. log.warning(
  549. 'Found orphan containers ({0}) for this project. If '
  550. 'you removed or renamed this service in your compose '
  551. 'file, you can run this command with the '
  552. '--remove-orphans flag to clean it up.'.format(
  553. ', '.join(["{}".format(ctnr.name) for ctnr in orphans])
  554. )
  555. )
  556. def _inject_deps(self, acc, service):
  557. dep_names = service.get_dependency_names()
  558. if len(dep_names) > 0:
  559. dep_services = self.get_services(
  560. service_names=list(set(dep_names)),
  561. include_deps=True
  562. )
  563. else:
  564. dep_services = []
  565. dep_services.append(service)
  566. return acc + dep_services
  567. def build_container_operation_with_timeout_func(self, operation, options):
  568. def container_operation_with_timeout(container):
  569. if options.get('timeout') is None:
  570. service = self.get_service(container.service)
  571. options['timeout'] = service.stop_timeout(None)
  572. return getattr(container, operation)(**options)
  573. return container_operation_with_timeout
  574. def get_volumes_from(project, service_dict):
  575. volumes_from = service_dict.pop('volumes_from', None)
  576. if not volumes_from:
  577. return []
  578. def build_volume_from(spec):
  579. if spec.type == 'service':
  580. try:
  581. return spec._replace(source=project.get_service(spec.source))
  582. except NoSuchService:
  583. pass
  584. if spec.type == 'container':
  585. try:
  586. container = Container.from_id(project.client, spec.source)
  587. return spec._replace(source=container)
  588. except APIError:
  589. pass
  590. raise ConfigurationError(
  591. "Service \"{}\" mounts volumes from \"{}\", which is not the name "
  592. "of a service or container.".format(
  593. service_dict['name'],
  594. spec.source))
  595. return [build_volume_from(vf) for vf in volumes_from]
  596. def get_secrets(service, service_secrets, secret_defs):
  597. secrets = []
  598. for secret in service_secrets:
  599. secret_def = secret_defs.get(secret.source)
  600. if not secret_def:
  601. raise ConfigurationError(
  602. "Service \"{service}\" uses an undefined secret \"{secret}\" "
  603. .format(service=service, secret=secret.source))
  604. if secret_def.get('external'):
  605. log.warn("Service \"{service}\" uses secret \"{secret}\" which is external. "
  606. "External secrets are not available to containers created by "
  607. "docker-compose.".format(service=service, secret=secret.source))
  608. continue
  609. if secret.uid or secret.gid or secret.mode:
  610. log.warn(
  611. "Service \"{service}\" uses secret \"{secret}\" with uid, "
  612. "gid, or mode. These fields are not supported by this "
  613. "implementation of the Compose file".format(
  614. service=service, secret=secret.source
  615. )
  616. )
  617. secrets.append({'secret': secret, 'file': secret_def.get('file')})
  618. return secrets
  619. class NoSuchService(Exception):
  620. def __init__(self, name):
  621. if isinstance(name, six.binary_type):
  622. name = name.decode('utf-8')
  623. self.name = name
  624. self.msg = "No such service: %s" % self.name
  625. def __str__(self):
  626. return self.msg
  627. class ProjectError(Exception):
  628. def __init__(self, msg):
  629. self.msg = msg