Guest User

Untitled

a guest
Apr 16th, 2015
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.64 KB | None | 0 0
  1. diff docker/__init__.py /Users/cyberax/work/blako/libutils/docker/__init__.py
  2. 20c20
  3. < from .client import Client, AutoVersionClient # flake8: noqa
  4. ---
  5. > from .client import Client # flake8: noqa
  6. Only in /Users/cyberax/work/blako/libutils/docker/: __init__.pyc
  7. Common subdirectories: docker/auth and /Users/cyberax/work/blako/libutils/docker/auth
  8. diff docker/client.py /Users/cyberax/work/blako/libutils/docker/client.py
  9. 20c20
  10. < from datetime import datetime
  11. ---
  12. > import warnings
  13. 23a24
  14. > from requests.exceptions import Timeout
  15. 33d33
  16. <
  17. 37c37
  18. < DEFAULT_DOCKER_API_VERSION = '1.18'
  19. ---
  20. > DEFAULT_DOCKER_API_VERSION = '1.12'
  21. 43c43
  22. < def __init__(self, base_url=None, version=None,
  23. ---
  24. > def __init__(self, base_url=None, version=DEFAULT_DOCKER_API_VERSION,
  25. 54c54,55
  26. < self.timeout = timeout
  27. ---
  28. > self._version = version
  29. > self._timeout = timeout
  30. 65,92d65
  31. < # version detection needs to be after unix adapter mounting
  32. < if version is None:
  33. < self._version = DEFAULT_DOCKER_API_VERSION
  34. < elif isinstance(version, six.string_types):
  35. < if version.lower() == 'auto':
  36. < self._version = self._retrieve_server_version()
  37. < else:
  38. < self._version = version
  39. < else:
  40. < raise errors.DockerException(
  41. < 'Version parameter must be a string or None. Found {0}'.format(
  42. < type(version).__name__
  43. < )
  44. < )
  45. <
  46. < def _retrieve_server_version(self):
  47. < try:
  48. < return self.version(api_version=False)["ApiVersion"]
  49. < except KeyError:
  50. < raise errors.DockerException(
  51. < 'Invalid response from docker daemon: key "ApiVersion"'
  52. < ' is missing.'
  53. < )
  54. < except Exception as e:
  55. < raise errors.DockerException(
  56. < 'Error while fetching server API version: {0}'.format(e)
  57. < )
  58. <
  59. 96c69
  60. < kwargs.setdefault('timeout', self.timeout)
  61. ---
  62. > kwargs.setdefault('timeout', self._timeout)
  63. 108,112c81,82
  64. < def _url(self, path, versioned_api=True):
  65. < if versioned_api:
  66. < return '{0}/v{1}{2}'.format(self.base_url, self._version, path)
  67. < else:
  68. < return '{0}{1}'.format(self.base_url, path)
  69. ---
  70. > def _url(self, path):
  71. > return '{0}/v{1}{2}'.format(self.base_url, self._version, path)
  72. 130a101,223
  73. > def _container_config(self, image, command, hostname=None, user=None,
  74. > detach=False, stdin_open=False, tty=False,
  75. > mem_limit=0, ports=None, environment=None, dns=None,
  76. > volumes=None, volumes_from=None,
  77. > network_disabled=False, entrypoint=None,
  78. > cpu_shares=None, working_dir=None, domainname=None,
  79. > memswap_limit=0):
  80. > if isinstance(command, six.string_types):
  81. > command = shlex.split(str(command))
  82. > if isinstance(environment, dict):
  83. > environment = [
  84. > '{0}={1}'.format(k, v) for k, v in environment.items()
  85. > ]
  86. >
  87. > if isinstance(mem_limit, six.string_types):
  88. > if len(mem_limit) == 0:
  89. > mem_limit = 0
  90. > else:
  91. > units = {'b': 1,
  92. > 'k': 1024,
  93. > 'm': 1024 * 1024,
  94. > 'g': 1024 * 1024 * 1024}
  95. > suffix = mem_limit[-1].lower()
  96. >
  97. > # Check if the variable is a string representation of an int
  98. > # without a units part. Assuming that the units are bytes.
  99. > if suffix.isdigit():
  100. > digits_part = mem_limit
  101. > suffix = 'b'
  102. > else:
  103. > digits_part = mem_limit[:-1]
  104. >
  105. > if suffix in units.keys() or suffix.isdigit():
  106. > try:
  107. > digits = int(digits_part)
  108. > except ValueError:
  109. > message = ('Failed converting the string value for'
  110. > ' mem_limit ({0}) to a number.')
  111. > formatted_message = message.format(digits_part)
  112. > raise errors.DockerException(formatted_message)
  113. >
  114. > mem_limit = digits * units[suffix]
  115. > else:
  116. > message = ('The specified value for mem_limit parameter'
  117. > ' ({0}) should specify the units. The postfix'
  118. > ' should be one of the `b` `k` `m` `g`'
  119. > ' characters')
  120. > raise errors.DockerException(message.format(mem_limit))
  121. >
  122. > if isinstance(ports, list):
  123. > exposed_ports = {}
  124. > for port_definition in ports:
  125. > port = port_definition
  126. > proto = 'tcp'
  127. > if isinstance(port_definition, tuple):
  128. > if len(port_definition) == 2:
  129. > proto = port_definition[1]
  130. > port = port_definition[0]
  131. > exposed_ports['{0}/{1}'.format(port, proto)] = {}
  132. > ports = exposed_ports
  133. >
  134. > if isinstance(volumes, six.string_types):
  135. > volumes = [volumes, ]
  136. >
  137. > if isinstance(volumes, list):
  138. > volumes_dict = {}
  139. > for vol in volumes:
  140. > volumes_dict[vol] = {}
  141. > volumes = volumes_dict
  142. >
  143. > if volumes_from:
  144. > if not isinstance(volumes_from, six.string_types):
  145. > volumes_from = ','.join(volumes_from)
  146. > else:
  147. > # Force None, an empty list or dict causes client.start to fail
  148. > volumes_from = None
  149. >
  150. > attach_stdin = False
  151. > attach_stdout = False
  152. > attach_stderr = False
  153. > stdin_once = False
  154. >
  155. > if not detach:
  156. > attach_stdout = True
  157. > attach_stderr = True
  158. >
  159. > if stdin_open:
  160. > attach_stdin = True
  161. > stdin_once = True
  162. >
  163. > if utils.compare_version('1.10', self._version) >= 0:
  164. > message = ('{0!r} parameter has no effect on create_container().'
  165. > ' It has been moved to start()')
  166. > if dns is not None:
  167. > raise errors.DockerException(message.format('dns'))
  168. > if volumes_from is not None:
  169. > raise errors.DockerException(message.format('volumes_from'))
  170. >
  171. > return {
  172. > 'Hostname': hostname,
  173. > 'Domainname': domainname,
  174. > 'ExposedPorts': ports,
  175. > 'User': user,
  176. > 'Tty': tty,
  177. > 'OpenStdin': stdin_open,
  178. > 'StdinOnce': stdin_once,
  179. > 'Memory': mem_limit,
  180. > 'AttachStdin': attach_stdin,
  181. > 'AttachStdout': attach_stdout,
  182. > 'AttachStderr': attach_stderr,
  183. > 'Env': environment,
  184. > 'Cmd': command,
  185. > 'Dns': dns,
  186. > 'Image': image,
  187. > 'Volumes': volumes,
  188. > 'VolumesFrom': volumes_from,
  189. > 'NetworkDisabled': network_disabled,
  190. > 'Entrypoint': entrypoint,
  191. > 'CpuShares': cpu_shares,
  192. > 'WorkingDir': working_dir,
  193. > 'MemorySwap': memswap_limit
  194. > }
  195. >
  196. 169c262
  197. < sock = response.raw._fp.fp.raw
  198. ---
  199. > return response.raw._fp.fp.raw._sock
  200. 171,180c264
  201. < sock = response.raw._fp.fp._sock
  202. < try:
  203. < # Keep a reference to the response to stop it being garbage
  204. < # collected. If the response is garbage collected, it will
  205. < # close TLS sockets.
  206. < sock._response = response
  207. < except AttributeError:
  208. < # UNIX sockets can't have attributes set on them, but that's
  209. < # fine because we won't be doing TLS over them
  210. < pass
  211. ---
  212. > return response.raw._fp.fp._sock
  213. 182,184c266
  214. < return sock
  215. <
  216. < def _stream_helper(self, response, decode=False):
  217. ---
  218. > def _stream_helper(self, response):
  219. 186,203c268,284
  220. < if response.raw._fp.chunked:
  221. < reader = response.raw
  222. < while not reader.closed:
  223. < # this read call will block until we get a chunk
  224. < data = reader.read(1)
  225. < if not data:
  226. < break
  227. < if reader._fp.chunk_left:
  228. < data += reader.read(reader._fp.chunk_left)
  229. < if decode:
  230. < if six.PY3:
  231. < data = data.decode('utf-8')
  232. < data = json.loads(data)
  233. < yield data
  234. < else:
  235. < # Response isn't chunked, meaning we probably
  236. < # encountered an error immediately
  237. < yield self._result(response)
  238. ---
  239. > socket_fp = self._get_raw_response_socket(response)
  240. > socket_fp.setblocking(1)
  241. > socket = socket_fp.makefile()
  242. > while True:
  243. > # Because Docker introduced newlines at the end of chunks in v0.9,
  244. > # and only on some API endpoints, we have to cater for both cases.
  245. > size_line = socket.readline()
  246. > if size_line == '\r\n' or size_line == '\n':
  247. > size_line = socket.readline()
  248. >
  249. > size = int(size_line, 16)
  250. > if size <= 0:
  251. > break
  252. > data = socket.readline()
  253. > if not data:
  254. > break
  255. > yield data
  256. 219c300
  257. < def _multiplexed_response_stream_helper(self, response):
  258. ---
  259. > def _multiplexed_socket_stream_helper(self, response):
  260. 221,224c302
  261. < stream."""
  262. <
  263. < # Disable timeout on the underlying socket to prevent
  264. < # Read timed out(s) for long running processes
  265. ---
  266. > socket."""
  267. 226,229c304,317
  268. < if six.PY3:
  269. < socket._sock.settimeout(None)
  270. < else:
  271. < socket.settimeout(None)
  272. ---
  273. >
  274. > def recvall(socket, size):
  275. > blocks = []
  276. > while size > 0:
  277. > block = socket.recv(size)
  278. > if not block:
  279. > return None
  280. >
  281. > blocks.append(block)
  282. > size -= len(block)
  283. >
  284. > sep = bytes() if six.PY3 else str()
  285. > data = sep.join(blocks)
  286. > return data
  287. 232c320,321
  288. < header = response.raw.read(STREAM_HEADER_SIZE_BYTES)
  289. ---
  290. > socket.settimeout(None)
  291. > header = recvall(socket, STREAM_HEADER_SIZE_BYTES)
  292. 238c327
  293. < data = response.raw.read(length)
  294. ---
  295. > data = recvall(socket, length)
  296. 243,246d331
  297. < @property
  298. < def api_version(self):
  299. < return self._version
  300. <
  301. 276,281c361,362
  302. < if stream:
  303. < return self._multiplexed_response_stream_helper(response)
  304. < else:
  305. < return sep.join(
  306. < [x for x in self._multiplexed_buffer_helper(response)]
  307. < )
  308. ---
  309. > return stream and self._multiplexed_socket_stream_helper(response) or \
  310. > sep.join([x for x in self._multiplexed_buffer_helper(response)])
  311. 303,304c384
  312. < custom_context=False, encoding=None, pull=True,
  313. < forcerm=False, dockerfile=None):
  314. ---
  315. > custom_context=False, encoding=None):
  316. 318,319d397
  317. < elif not os.path.isdir(path):
  318. < raise TypeError("You must specify a directory to build in path")
  319. 325,331c403
  320. < exclude = list(filter(bool, f.read().splitlines()))
  321. < # These are handled by the docker daemon and should not be
  322. < # excluded on the client
  323. < if 'Dockerfile' in exclude:
  324. < exclude.remove('Dockerfile')
  325. < if '.dockerignore' in exclude:
  326. < exclude.remove(".dockerignore")
  327. ---
  328. > exclude = list(filter(bool, f.read().split('\n')))
  329. 337,341d408
  330. < if dockerfile and utils.compare_version('1.17', self._version) < 0:
  331. < raise errors.InvalidVersion(
  332. < 'dockerfile was only introduced in API version 1.17'
  333. < )
  334. <
  335. 348,351c415
  336. < 'rm': rm,
  337. < 'forcerm': forcerm,
  338. < 'pull': pull,
  339. < 'dockerfile': dockerfile
  340. ---
  341. > 'rm': rm
  342. 368,369d431
  343. < if headers is None:
  344. < headers = {}
  345. 383c445
  346. < if context is not None and not custom_context:
  347. ---
  348. > if context is not None:
  349. 410,411c472
  350. < since=None, before=None, limit=-1, size=False,
  351. < filters=None):
  352. ---
  353. > since=None, before=None, limit=-1, size=False):
  354. 420,421d480
  355. < if filters:
  356. < params['filters'] = utils.convert_filters(filters)
  357. 446,447c505
  358. < memswap_limit=0, cpuset=None, host_config=None,
  359. < mac_address=None, labels=None):
  360. ---
  361. > memswap_limit=0):
  362. 452,461c510,513
  363. < if host_config and utils.compare_version('1.15', self._version) < 0:
  364. < raise errors.InvalidVersion(
  365. < 'host_config is not supported in API < 1.15'
  366. < )
  367. <
  368. < config = utils.create_container_config(
  369. < self._version, image, command, hostname, user, detach, stdin_open,
  370. < tty, mem_limit, ports, environment, dns, volumes, volumes_from,
  371. < network_disabled, entrypoint, cpu_shares, working_dir, domainname,
  372. < memswap_limit, cpuset, host_config, mac_address, labels
  373. ---
  374. > config = self._container_config(
  375. > image, command, hostname, user, detach, stdin_open, tty, mem_limit,
  376. > ports, environment, dns, volumes, volumes_from, network_disabled,
  377. > entrypoint, cpu_shares, working_dir, domainname, memswap_limit
  378. 479,539c531,532
  379. < def events(self, since=None, until=None, filters=None, decode=None):
  380. < if isinstance(since, datetime):
  381. < since = utils.datetime_to_timestamp(since)
  382. <
  383. < if isinstance(until, datetime):
  384. < until = utils.datetime_to_timestamp(until)
  385. <
  386. < if filters:
  387. < filters = utils.convert_filters(filters)
  388. <
  389. < params = {
  390. < 'since': since,
  391. < 'until': until,
  392. < 'filters': filters
  393. < }
  394. <
  395. < return self._stream_helper(self.get(self._url('/events'),
  396. < params=params, stream=True),
  397. < decode=decode)
  398. <
  399. < def execute(self, container, cmd, detach=False, stdout=True, stderr=True,
  400. < stream=False, tty=False):
  401. < if utils.compare_version('1.15', self._version) < 0:
  402. < raise errors.InvalidVersion('Exec is not supported in API < 1.15')
  403. < if isinstance(container, dict):
  404. < container = container.get('Id')
  405. < if isinstance(cmd, six.string_types):
  406. < cmd = shlex.split(str(cmd))
  407. <
  408. < data = {
  409. < 'Container': container,
  410. < 'User': '',
  411. < 'Privileged': False,
  412. < 'Tty': tty,
  413. < 'AttachStdin': False,
  414. < 'AttachStdout': stdout,
  415. < 'AttachStderr': stderr,
  416. < 'Detach': detach,
  417. < 'Cmd': cmd
  418. < }
  419. <
  420. < # create the command
  421. < url = self._url('/containers/{0}/exec'.format(container))
  422. < res = self._post_json(url, data=data)
  423. < self._raise_for_status(res)
  424. <
  425. < # start the command
  426. < cmd_id = res.json().get('Id')
  427. < res = self._post_json(self._url('/exec/{0}/start'.format(cmd_id)),
  428. < data=data, stream=stream)
  429. < self._raise_for_status(res)
  430. < if stream:
  431. < return self._multiplexed_response_stream_helper(res)
  432. < elif six.PY3:
  433. < return bytes().join(
  434. < [x for x in self._multiplexed_buffer_helper(res)]
  435. < )
  436. < else:
  437. < return str().join(
  438. < [x for x in self._multiplexed_buffer_helper(res)]
  439. < )
  440. ---
  441. > def events(self):
  442. > return self._stream_helper(self.get(self._url('/events'), stream=True))
  443. 557c550,551
  444. < return self._result(res, True)
  445. ---
  446. > self._raise_for_status(res)
  447. > return self._result(res)
  448. 559,560c553
  449. < def images(self, name=None, quiet=False, all=False, viz=False,
  450. < filters=None):
  451. ---
  452. > def images(self, name=None, quiet=False, all=False, viz=False):
  453. 570,571d562
  454. < if filters:
  455. < params['filters'] = utils.convert_filters(filters)
  456. 652c643
  457. < reauth=False, insecure_registry=False, dockercfg_path=None):
  458. ---
  459. > reauth=False):
  460. 655,659c646
  461. < # If dockercfg_path is passed check to see if the config file exists,
  462. < # if so load that config.
  463. < if dockercfg_path and os.path.exists(dockercfg_path):
  464. < self._auth_configs = auth.load_config(dockercfg_path)
  465. < elif not self._auth_configs:
  466. ---
  467. > if not self._auth_configs:
  468. 684c671
  469. < timestamps=False, tail='all'):
  470. ---
  471. > timestamps=False):
  472. 691,696c678
  473. < 'follow': stream and 1 or 0,
  474. < }
  475. < if utils.compare_version('1.13', self._version) >= 0:
  476. < if tail != 'all' and (not isinstance(tail, int) or tail <= 0):
  477. < tail = 'all'
  478. < params['tail'] = tail
  479. ---
  480. > 'follow': stream and 1 or 0}
  481. 700c682
  482. < return self._multiplexed_response_stream_helper(res)
  483. ---
  484. > return self._multiplexed_socket_stream_helper(res)
  485. 717,723d698
  486. < def pause(self, container):
  487. < if isinstance(container, dict):
  488. < container = container.get('Id')
  489. < url = self._url('/containers/{0}/pause'.format(container))
  490. < res = self._post(url)
  491. < self._raise_for_status(res)
  492. <
  493. 736,742c711
  494. < # Port settings is None when the container is running with
  495. < # network_mode=host.
  496. < port_settings = json_.get('NetworkSettings', {}).get('Ports')
  497. < if port_settings is None:
  498. < return None
  499. <
  500. < h_ports = port_settings.get(s_port + '/udp')
  501. ---
  502. > h_ports = json_['NetworkSettings']['Ports'].get(s_port + '/udp')
  503. 744c713
  504. < h_ports = port_settings.get(s_port + '/tcp')
  505. ---
  506. > h_ports = json_['NetworkSettings']['Ports'].get(s_port + '/tcp')
  507. 828,829d796
  508. < if isinstance(image, dict):
  509. < image = image.get('Id')
  510. 834,854d800
  511. < def rename(self, container, name):
  512. < if utils.compare_version('1.17', self._version) < 0:
  513. < raise errors.InvalidVersion(
  514. < 'rename was only introduced in API version 1.17'
  515. < )
  516. < if isinstance(container, dict):
  517. < container = container.get('Id')
  518. < url = self._url("/containers/{0}/rename".format(container))
  519. < params = {'name': name}
  520. < res = self._post(url, params=params)
  521. < self._raise_for_status(res)
  522. <
  523. < def resize(self, container, height, width):
  524. < if isinstance(container, dict):
  525. < container = container.get('Id')
  526. <
  527. < params = {'h': height, 'w': width}
  528. < url = self._url("/containers/{0}/resize".format(container))
  529. < res = self._post(url, params=params)
  530. < self._raise_for_status(res)
  531. <
  532. 871,873c817,846
  533. < restart_policy=None, cap_add=None, cap_drop=None, devices=None,
  534. < extra_hosts=None, read_only=None, pid_mode=None,
  535. < security_opt=None):
  536. ---
  537. > restart_policy=None, cap_add=None, cap_drop=None):
  538. > if isinstance(container, dict):
  539. > container = container.get('Id')
  540. >
  541. > if isinstance(lxc_conf, dict):
  542. > formatted = []
  543. > for k, v in six.iteritems(lxc_conf):
  544. > formatted.append({'Key': k, 'Value': str(v)})
  545. > lxc_conf = formatted
  546. >
  547. > start_config = {
  548. > 'LxcConf': lxc_conf
  549. > }
  550. > if binds:
  551. > start_config['Binds'] = utils.convert_volume_binds(binds)
  552. >
  553. > if port_bindings:
  554. > start_config['PortBindings'] = utils.convert_port_bindings(
  555. > port_bindings
  556. > )
  557. >
  558. > start_config['PublishAllPorts'] = publish_all_ports
  559. >
  560. > if links:
  561. > if isinstance(links, dict):
  562. > links = six.iteritems(links)
  563. >
  564. > formatted_links = [
  565. > '{0}:{1}'.format(k, v) for k, v in sorted(links)
  566. > ]
  567. 875c848,852
  568. < if utils.compare_version('1.10', self._version) < 0:
  569. ---
  570. > start_config['Links'] = formatted_links
  571. >
  572. > start_config['Privileged'] = privileged
  573. >
  574. > if utils.compare_version('1.10', self._version) >= 0:
  575. 877,879c854
  576. < raise errors.InvalidVersion(
  577. < 'dns is only supported for API version >= 1.10'
  578. < )
  579. ---
  580. > start_config['Dns'] = dns
  581. 881,883c856,862
  582. < raise errors.InvalidVersion(
  583. < 'volumes_from is only supported for API version >= 1.10'
  584. < )
  585. ---
  586. > if isinstance(volumes_from, six.string_types):
  587. > volumes_from = volumes_from.split(',')
  588. > start_config['VolumesFrom'] = volumes_from
  589. > else:
  590. > warning_message = ('{0!r} parameter is discarded. It is only'
  591. > ' available for API version greater or equal'
  592. > ' than 1.10')
  593. 885,889c864,874
  594. < if utils.compare_version('1.15', self._version) < 0:
  595. < if security_opt is not None:
  596. < raise errors.InvalidVersion(
  597. < 'security_opt is only supported for API version >= 1.15'
  598. < )
  599. ---
  600. > if dns is not None:
  601. > warnings.warn(warning_message.format('dns'),
  602. > DeprecationWarning)
  603. > if volumes_from is not None:
  604. > warnings.warn(warning_message.format('volumes_from'),
  605. > DeprecationWarning)
  606. > if dns_search:
  607. > start_config['DnsSearch'] = dns_search
  608. >
  609. > if network_mode:
  610. > start_config['NetworkMode'] = network_mode
  611. 891,899c876,877
  612. < if utils.compare_version('1.17', self._version) < 0:
  613. < if read_only is not None:
  614. < raise errors.InvalidVersion(
  615. < 'read_only is only supported for API version >= 1.17'
  616. < )
  617. < if pid_mode is not None:
  618. < raise errors.InvalidVersion(
  619. < 'pid_mode is only supported for API version >= 1.17'
  620. < )
  621. ---
  622. > if restart_policy:
  623. > start_config['RestartPolicy'] = restart_policy
  624. 901,909c879,880
  625. < start_config = utils.create_host_config(
  626. < binds=binds, port_bindings=port_bindings, lxc_conf=lxc_conf,
  627. < publish_all_ports=publish_all_ports, links=links, dns=dns,
  628. < privileged=privileged, dns_search=dns_search, cap_add=cap_add,
  629. < cap_drop=cap_drop, volumes_from=volumes_from, devices=devices,
  630. < network_mode=network_mode, restart_policy=restart_policy,
  631. < extra_hosts=extra_hosts, read_only=read_only, pid_mode=pid_mode,
  632. < security_opt=security_opt
  633. < )
  634. ---
  635. > if cap_add:
  636. > start_config['CapAdd'] = cap_add
  637. 911,912c882,883
  638. < if isinstance(container, dict):
  639. < container = container.get('Id')
  640. ---
  641. > if cap_drop:
  642. > start_config['CapDrop'] = cap_drop
  643. 915,916d885
  644. < if not start_config:
  645. < start_config = None
  646. 920,924c889
  647. < def stats(self, container, decode=None):
  648. < if utils.compare_version('1.17', self._version) < 0:
  649. < raise errors.InvalidVersion(
  650. < 'Stats retrieval is not supported in API < 1.17!')
  651. <
  652. ---
  653. > def resize(self, container, height, width):
  654. 927,928c892,896
  655. < url = self._url("/containers/{0}/stats".format(container))
  656. < return self._stream_helper(self._get(url, stream=True), decode=decode)
  657. ---
  658. >
  659. > params = {'h': height, 'w': width}
  660. > url = self._url("/containers/{0}/resize".format(container))
  661. > res = self._post(url, params=params)
  662. > self._raise_for_status(res)
  663. 935d902
  664. <
  665. 937c904
  666. < timeout=(timeout + self.timeout))
  667. ---
  668. > timeout=(timeout + self._timeout))
  669. 955,964c922,923
  670. < def version(self, api_version=True):
  671. < url = self._url("/version", versioned_api=api_version)
  672. < return self._result(self._get(url), json=True)
  673. <
  674. < def unpause(self, container):
  675. < if isinstance(container, dict):
  676. < container = container.get('Id')
  677. < url = self._url('/containers/{0}/unpause'.format(container))
  678. < res = self._post(url)
  679. < self._raise_for_status(res)
  680. ---
  681. > def version(self):
  682. > return self._result(self._get(self._url("/version")), True)
  683. 966c925
  684. < def wait(self, container, timeout=None):
  685. ---
  686. > def wait(self, container):
  687. 970c929
  688. < res = self._post(url, timeout=timeout)
  689. ---
  690. > res = self._post(url, timeout=None)
  691. 976a936,945
  692. > def get_json_stats(self, container):
  693. > if isinstance(container, dict):
  694. > container = container.get('Id')
  695. > url = self._url("/containers/{0}/json".format(container))
  696. > res = self._get(url, timeout=None)
  697. > if res.status_code == 404:
  698. > return None
  699. > self._raise_for_status(res)
  700. > json_ = res.json()
  701. > return json_
  702. 978,985c947,972
  703. < class AutoVersionClient(Client):
  704. < def __init__(self, *args, **kwargs):
  705. < if 'version' in kwargs and kwargs['version']:
  706. < raise errors.DockerException(
  707. < 'Can not specify version for AutoVersionClient'
  708. < )
  709. < kwargs['version'] = 'auto'
  710. < super(AutoVersionClient, self).__init__(*args, **kwargs)
  711. ---
  712. > def pid(self, container):
  713. > json_ = self.get_json_stats(container)
  714. > return json_['State']['Pid']
  715. >
  716. > def poll(self, container):
  717. > json_ = self.get_json_stats(container)
  718. > if json_['State']['Running']:
  719. > return None
  720. >
  721. > return self.wait(container)
  722. >
  723. > def stats(self, container):
  724. > if isinstance(container, dict):
  725. > container = container.get('Id')
  726. > url = self._url("/containers/{0}/stats".format(container))
  727. > try:
  728. > res = self._get(url, stream=True, timeout=5)
  729. > except Timeout:
  730. > return None
  731. > if res.status_code == 404:
  732. > return None
  733. > self._raise_for_status(res)
  734. >
  735. > # Yes, it doesn't loop. We just need the first line.
  736. > for ln in res.iter_lines(decode_unicode=False):
  737. > return json.loads(ln)
  738. Only in /Users/cyberax/work/blako/libutils/docker/: client.pyc
  739. diff docker/errors.py /Users/cyberax/work/blako/libutils/docker/errors.py
  740. 33c33
  741. < message = '{0} Client Error: {1}'.format(
  742. ---
  743. > message = '%s Client Error: %s' % (
  744. 37c37
  745. < message = '{0} Server Error: {1}'.format(
  746. ---
  747. > message = '%s Server Error: %s' % (
  748. 41c41
  749. < message = '{0} ("{1}")'.format(message, self.explanation)
  750. ---
  751. > message = '%s ("%s")' % (message, self.explanation)
  752. 56,59d55
  753. < class InvalidVersion(DockerException):
  754. < pass
  755. <
  756. <
  757. Only in /Users/cyberax/work/blako/libutils/docker/: errors.pyc
  758. Common subdirectories: docker/ssladapter and /Users/cyberax/work/blako/libutils/docker/ssladapter
  759. diff docker/tls.py /Users/cyberax/work/blako/libutils/docker/tls.py
  760. 13c13
  761. < ssl_version=None, assert_hostname=None):
  762. ---
  763. > ssl_version=None):
  764. 20,24c20,21
  765. < # urllib3 sets a default ssl_version if ssl_version is None,
  766. < # but that default is the vulnerable PROTOCOL_SSLv23 selection,
  767. < # so we override the default with the maximum supported in the running
  768. < # Python interpeter up to TLS 1.2. (see: http://tinyurl.com/kxga8hb)
  769. < ssl_version = ssl_version or ssladapter.get_max_tls_protocol()
  770. ---
  771. > # urllib3 sets a default ssl_version if ssl_version is None
  772. > # http://tinyurl.com/kxga8hb
  773. 26d22
  774. < self.assert_hostname = assert_hostname
  775. 72,75c68
  776. < client.mount('https://', ssladapter.SSLAdapter(
  777. < ssl_version=self.ssl_version,
  778. < assert_hostname=self.assert_hostname,
  779. < ))
  780. ---
  781. > client.mount('https://', ssladapter.SSLAdapter(self.ssl_version))
  782. Only in /Users/cyberax/work/blako/libutils/docker/: tls.pyc
  783. Common subdirectories: docker/unixconn and /Users/cyberax/work/blako/libutils/docker/unixconn
  784. Common subdirectories: docker/utils and /Users/cyberax/work/blako/libutils/docker/utils
  785. diff docker/version.py /Users/cyberax/work/blako/libutils/docker/version.py
  786. 1c1
  787. < version = "1.1.1-dev"
  788. ---
  789. > version = "0.5.0"
Add Comment
Please, Sign In to add comment