def _delete_floating_ip(self, server, fip): with logging.ExceptionLogger( LOG, _("Unable to delete IP: %s") % fip["ip"]): if self.check_ip_address(fip["ip"])(server): self._dissociate_floating_ip(server, fip["ip"]) network_wrapper.wrap(self.clients).delete_floating_ip(fip["id"], wait=True)
def test_wrap(self): mock_clients = mock.Mock() mock_clients.nova().networks.list.return_value = [] mock_clients.services.return_value = {"foo": consts.Service.NEUTRON} self.assertIsInstance(network.wrap(mock_clients, {}), network.NeutronWrapper) mock_clients.services.return_value = {"foo": "bar"} self.assertIsInstance(network.wrap(mock_clients, {}), network.NovaNetworkWrapper)
def boot_and_associate_floating_ip(self, image, flavor, **kwargs): """Boot a server and associate a floating IP to it. :param image: image to be used to boot an instance :param flavor: flavor to be used to boot an instance :param kwargs: Optional additional arguments for server creation """ server = self._boot_server(image, flavor, **kwargs) address = network_wrapper.wrap(self.clients).create_floating_ip( tenant_id=server.tenant_id) self._associate_floating_ip(server, address["ip"])
def _attach_floating_ip(self, server, floating_network): internal_network = list(server.networks)[0] fixed_ip = server.addresses[internal_network][0]["addr"] fip = network_wrapper.wrap(self.clients).create_floating_ip( ext_network=floating_network, int_network=internal_network, tenant_id=server.tenant_id, fixed_ip=fixed_ip) self._associate_floating_ip(server, fip["ip"], fixed_address=fixed_ip) return fip
def setup(self): admin_or_user = (self.context.get("admin") or self.context.get("users")[0]) net_wrapper = network.wrap( osclients.Clients(admin_or_user["endpoint"]), self.config) use_sg, msg = net_wrapper.supports_security_group() if not use_sg: LOG.info(_("Security group context is disabled: %(message)s") % {"message": msg}) return secgroup_name = "%s_%s" % (SSH_GROUP_NAME, self.context["task"]["uuid"]) for user in self.context["users"]: user["secgroup"] = _prepare_open_secgroup(user["endpoint"], secgroup_name)
def setup(self): admin_or_user = (self.context.get("admin") or self.context.get("users")[0]) net_wrapper = network.wrap( osclients.Clients(admin_or_user["endpoint"]), self.config) use_sg, msg = net_wrapper.supports_security_group() if not use_sg: LOG.info( _("Security group context is disabled: %(message)s") % {"message": msg}) return secgroup_name = "%s_%s" % (SSH_GROUP_NAME, self.context["task"]["uuid"]) for user in self.context["users"]: user["secgroup"] = _prepare_open_secgroup(user["endpoint"], secgroup_name)
def _remove_default_security_group(self): """Delete default security group for tenants.""" clients = osclients.Clients(self.endpoint) net_wrapper = network.wrap(clients) if net_wrapper.SERVICE_IMPL != consts.Service.NEUTRON: return use_sg, msg = net_wrapper.supports_security_group() if not use_sg: LOG.debug("Security group context is disabled: %(message)s" % {"message": msg}) return for user, tenant_id in rutils.iterate_per_tenants( self.context["users"]): with logging.ExceptionLogger( LOG, _("Unable to delete default security group")): uclients = osclients.Clients(user["endpoint"]) sg = uclients.nova().security_groups.find(name="default") clients.neutron().delete_security_group(sg.id)
def _get_netwrap(self): if not hasattr(self, "_netwrap"): self._netwrap = network_wrapper.wrap(self.clients) return self._netwrap
def __init__(self, context): super(Network, self).__init__(context) self.net_wrapper = network_wrapper.wrap( osclients.Clients(context["admin"]["endpoint"]), self.config)
def __init__(self, context): super(Network, self).__init__(context) self.config.setdefault("start_cidr", self.START_CIDR_DFLT) self.config.setdefault("networks_per_tenant", 1) self.net_wrapper = network_wrapper.wrap( osclients.Clients(context["admin"]["endpoint"]), self.config)
def __init__(self, context): super(PrepareEC2ClientContext, self).__init__(context) self.net_wrapper = network_wrapper.wrap( osclients.Clients(context["admin"]["endpoint"]), self.config) self.net_wrapper.start_cidr = '10.0.0.0/16'