Docker remote driver for OpenStack Neutron
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.
 
 
 
 
 

96 lines
3.6 KiB

  1. # Copyright 2016: IBM Inc.
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. from rally.common import logging
  16. from rally.task import atomic
  17. from rally_openstack import scenario
  18. LOG = logging.getLogger(__name__)
  19. class KuryrScenario(scenario.OpenStackScenario):
  20. """Base class for Kuryr scenarios with basic atomic actions."""
  21. @atomic.action_timer("kuryr.list_networks")
  22. def _list_networks(self, network_list_args):
  23. """Return user networks list.
  24. :param network_list_args: network list options
  25. """
  26. LOG.debug("Running the list_networks scenario")
  27. names = network_list_args.get('names')
  28. ids = network_list_args.get('ids')
  29. return self.docker_client.networks(names, ids)
  30. @atomic.action_timer("kuryr.create_network")
  31. def _create_network(self, is_kuryr=True, network_create_args=None):
  32. """Create network with kuryr or without kuryr.
  33. :param network_create_args: dict: name, driver and others
  34. :returns: dict of the created network reference object
  35. """
  36. name = self.generate_random_name()
  37. if is_kuryr:
  38. ipam = {
  39. "Driver": "kuryr",
  40. "Options": {},
  41. "Config": [
  42. {
  43. "Subnet": "20.0.0.0/24",
  44. "IPRange": "20.0.0.0/24",
  45. "Gateway": "20.0.0.1"
  46. }
  47. ]
  48. }
  49. return self.docker_client.create_network(name=name,
  50. driver='kuryr',
  51. ipam=ipam,
  52. options=network_create_args)
  53. else:
  54. return self.docker_client.create_network(name=name,
  55. options=network_create_args)
  56. @atomic.action_timer("kuryr.delete_network")
  57. def _delete_network(self, network):
  58. """Delete Kuryr network.
  59. :param network: Network object
  60. """
  61. self.docker_client.remove_network(network['Id'])
  62. @atomic.action_timer("kuryr.start_container")
  63. def _start_container(self, container_create_args=None):
  64. """Start Container on docker network."""
  65. network_config = self.docker_client.create_networking_config(
  66. {self.context.get("netname"):
  67. self.docker_client.create_endpoint_config()})
  68. container = self.docker_client.create_container(
  69. image='kuryr/busybox',
  70. command='/bin/sleep 600',
  71. networking_config=network_config)
  72. container_id = container.get('Id')
  73. self.docker_client.start(container=container_id)
  74. return container_id
  75. @atomic.action_timer("kuryr.stop_container")
  76. def _stop_container(self, container_id):
  77. """Stop Container."""
  78. self.docker_client.stop(container=container_id)
  79. @atomic.action_timer("kuryr.remove_container")
  80. def _remove_container(self, container_id):
  81. self.docker_client.remove_container(container=container_id,
  82. force=True)