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 _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 _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"]) with atomic.ActionTimer(self, "neutron.delete_floating_ip"): network_wrapper.wrap(self.clients, self).delete_floating_ip( fip["id"], wait=True)
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"]) with atomic.ActionTimer(self, "neutron.delete_floating_ip"): network_wrapper.wrap(self.clients, self).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 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 __init__(self, ctx): super(PrepareEC2ClientContext, self).__init__(ctx) self.net_wrapper = network_wrapper.wrap(osclients.Clients( self.context["admin"]["credential"]), self, config=self.config) self.net_wrapper.start_cidr = '10.0.0.0/16'
def setup(self): # NOTE(rkiran): Some clients are not thread-safe. Thus during # multithreading/multiprocessing, it is likely the # sockets are left open. This problem is eliminated by # creating a connection in setup and cleanup separately. net_wrapper = network_wrapper.wrap(osclients.Clients( self.context["admin"]["credential"]), self, config=self.config) kwargs = {} if self.config["dns_nameservers"] is not None: kwargs["dns_nameservers"] = self.config["dns_nameservers"] for user, tenant_id in (utils.iterate_per_tenants( self.context.get("users", []))): self.context["tenants"][tenant_id]["networks"] = [] for i in range(self.config["networks_per_tenant"]): # NOTE(amaretskiy): router_create_args and subnets_num take # effect for Neutron only. network_create_args = self.config["network_create_args"].copy() network = net_wrapper.create_network( tenant_id, dualstack=self.config["dualstack"], subnets_num=self.config["subnets_per_network"], network_create_args=network_create_args, router_create_args=self.config["router"], **kwargs) self.context["tenants"][tenant_id]["networks"].append(network)
def _remove_default_security_group(self): """Delete default security group for tenants.""" clients = osclients.Clients(self.credential) if consts.Service.NEUTRON not in clients.services().values(): return use_sg, msg = network.wrap(clients, self).supports_extension("security-group") if not use_sg: LOG.debug("Security group context is disabled: %s" % 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["credential"]) security_groups = uclients.neutron().list_security_groups() default = [ sg for sg in security_groups["security_groups"] if sg["name"] == "default" ] if default: clients.neutron().delete_security_group(default[0]["id"])
def setup(self): # NOTE(rkiran): Some clients are not thread-safe. Thus during # multithreading/multiprocessing, it is likely the # sockets are left open. This problem is eliminated by # creating a connection in setup and cleanup separately. net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["credential"]), self, config=self.config) kwargs = {} if self.config["dns_nameservers"] is not None: kwargs["dns_nameservers"] = self.config["dns_nameservers"] for user, tenant_id in (utils.iterate_per_tenants( self.context.get("users", []))): self.context["tenants"][tenant_id]["networks"] = [] for i in range(self.config["networks_per_tenant"]): # NOTE(amaretskiy): add_router and subnets_num take effect # for Neutron only. network_create_args = self.config["network_create_args"].copy() network = net_wrapper.create_network( tenant_id, add_router=True, subnets_num=self.config["subnets_per_network"], network_create_args=network_create_args, **kwargs) self.context["tenants"][tenant_id]["networks"].append(network)
def setup(self): for user, tenant_id in utils.iterate_per_tenants( self.context.get("users", [])): net_wrapper = network_wrapper.wrap( osclients.Clients(user["endpoint"]), self, config=self.config) self.context["tenants"][tenant_id]["networks"] = ( net_wrapper.list_networks())
def setup(self): net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["endpoint"]), self.context["task"], config=self.config) use_lb, msg = net_wrapper.supports_extension("lbaas") if not use_lb: LOG.info(msg) return # Creates a lb-pool for every subnet created in network context. for user, tenant_id in (utils.iterate_per_tenants( self.context.get("users", []))): for network in self.context["tenants"][tenant_id]["networks"]: for subnet in network.get("subnets", []): if self.config["lbaas_version"] == 1: network.setdefault("lb_pools", []).append( net_wrapper.create_v1_pool( tenant_id, subnet, **self.config["pool"])) else: raise NotImplementedError( "Context for LBaaS version %s not implemented." % self.config["lbaas_version"])
def setup(self): net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["endpoint"]), self.task, config=self.config) use_lb, msg = net_wrapper.supports_extension("lbaas") if not use_lb: LOG.info(msg) return # Creates a lb-pool for every subnet created in network context. for user, tenant_id in (utils.iterate_per_tenants( self.context.get("users", []))): for network in self.context["tenants"][tenant_id]["networks"]: for subnet in network.get("subnets", []): if self.config["lbaas_version"] == 1: network.setdefault("lb_pools", []).append( net_wrapper.create_v1_pool( tenant_id, subnet, **self.config["pool"])) else: raise NotImplementedError( "Context for LBaaS version %s not implemented." % self.config["lbaas_version"])
def test_wrap(self): mock_clients = mock.Mock() mock_clients.nova().networks.list.return_value = [] config = {"fakearg": "fake"} owner = Owner() mock_clients.services.return_value = {"foo": consts.Service.NEUTRON} wrapper = network.wrap(mock_clients, owner, config) self.assertIsInstance(wrapper, network.NeutronWrapper) self.assertEqual(wrapper.owner, owner) self.assertEqual(wrapper.config, config) mock_clients.services.return_value = {"foo": "bar"} wrapper = network.wrap(mock_clients, owner, config) self.assertIsInstance(wrapper, network.NovaNetworkWrapper) self.assertEqual(wrapper.owner, owner) self.assertEqual(wrapper.config, config)
def test_wrap(self): mock_clients = mock.Mock() mock_clients.nova().networks.list.return_value = [] config = {"fakearg": "fake"} owner = Owner() mock_clients.services.return_value = {"foo": consts.Service.NEUTRON} wrapper = network.wrap(mock_clients, owner, config) self.assertIsInstance(wrapper, network.NeutronWrapper) self.assertEqual(wrapper.owner, owner) self.assertEqual(wrapper.config, config) mock_clients.services.return_value = {"foo": "bar"} wrapper = network.wrap(mock_clients, owner, config) self.assertIsInstance(wrapper, network.NovaNetworkWrapper) self.assertEqual(wrapper.owner, owner) self.assertEqual(wrapper.config, config)
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, self).create_floating_ip(tenant_id=server.tenant_id) self._associate_floating_ip(server, address["ip"])
def cleanup(self): net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["credential"]), self, config=self.config) for tenant_id, tenant_ctx in self.context["tenants"].items(): for network in tenant_ctx.get("networks", []): with logging.ExceptionLogger( LOG, "Failed to delete network for tenant %s" % tenant_id): net_wrapper.delete_network(network)
def cleanup(self): net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["credential"]), self, config=self.config) for tenant_id, tenant_ctx in self.context["tenants"].items(): for network in tenant_ctx.get("networks", []): with logging.ExceptionLogger( LOG, "Failed to delete network for tenant %s" % tenant_id): net_wrapper.delete_network(network)
def cleanup(self): net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["endpoint"]), self.config) for tenant_id, tenant_ctx in six.iteritems(self.context["tenants"]): for network in tenant_ctx.get("networks", []): with logging.ExceptionLogger( LOG, _("Failed to delete network for tenant %s") % tenant_id): net_wrapper.delete_network(network)
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 _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, self).create_floating_ip( ext_network=floating_network, tenant_id=server.tenant_id, fixed_ip=fixed_ip) self._associate_floating_ip(server, fip["ip"], fixed_address=fixed_ip) return fip
def cleanup(self): net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["endpoint"]), self.config) for tenant_id, tenant_ctx in six.iteritems(self.context["tenants"]): for network in tenant_ctx.get("networks", []): with logging.ExceptionLogger( LOG, _("Failed to delete network for tenant %s") % tenant_id): net_wrapper.delete_network(network)
def run(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, self).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"] with atomic.ActionTimer(self, "neutron.create_floating_ip"): fip = network_wrapper.wrap(self.clients, self).create_floating_ip( ext_network=floating_network, tenant_id=server.tenant_id, fixed_ip=fixed_ip) self._associate_floating_ip(server, fip["ip"], fixed_address=fixed_ip) return fip
def _attach_floating_ip(self, server, floating_network): internal_network = list(server.networks)[0] fixed_ip = server.addresses[internal_network][0]["addr"] with atomic.ActionTimer(self, "neutron.create_floating_ip"): fip = network_wrapper.wrap(self.clients, self).create_floating_ip( ext_network=floating_network, tenant_id=server.tenant_id, fixed_ip=fixed_ip) self._associate_floating_ip(server, fip, 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: %s") % 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 cleanup(self): net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["endpoint"]), self.config) for tenant_id, tenant_ctx in six.iteritems(self.context["tenants"]): for network in tenant_ctx.get("networks", []): for pool in network.get("lb_pools", []): with logging.ExceptionLogger( LOG, _("Failed to delete pool %(pool)s for tenant " "%(tenant)s") % {"pool": pool["pool"]["id"], "tenant": tenant_id}): if self.config["lbaas_version"] == 1: net_wrapper.delete_v1_pool(pool["pool"]["id"])
def cleanup(self): net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["endpoint"]), self.task, config=self.config) for tenant_id, tenant_ctx in six.iteritems(self.context["tenants"]): for network in tenant_ctx.get("networks", []): for pool in network.get("lb_pools", []): with logging.ExceptionLogger( LOG, _("Failed to delete pool %(pool)s for tenant " "%(tenant)s") % {"pool": pool["pool"]["id"], "tenant": tenant_id}): if self.config["lbaas_version"] == 1: net_wrapper.delete_v1_pool(pool["pool"]["id"])
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["credential"]), self, config=self.config) use_sg, msg = net_wrapper.supports_extension("security-group") if not use_sg: LOG.info("Security group context is disabled: %s" % msg) return secgroup_name = self.generate_random_name() for user in self.context["users"]: user["secgroup"] = _prepare_open_secgroup(user["credential"], 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=self.config) use_sg, msg = net_wrapper.supports_extension("security-group") if not use_sg: LOG.info(_("Security group context is disabled: %s") % msg) return secgroup_name = self.generate_random_name() for user in self.context["users"]: user["secgroup"] = _prepare_open_secgroup(user["endpoint"], secgroup_name)
def run(self, image, flavor, **kwargs): """Boot a server associate and dissociate a floating IP from it. The scenario first boot a server and create a floating IP. then associate the floating IP to the server.Finally dissociate the floating IP. :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, self).create_floating_ip( tenant_id=server.tenant_id) self._associate_floating_ip(server, address["ip"]) self._dissociate_floating_ip(server, address["ip"])
def run(self, image, flavor, **kwargs): """Boot a server associate and dissociate a floating IP from it. The scenario first boot a server and create a floating IP. then associate the floating IP to the server.Finally dissociate the floating IP. :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, self).create_floating_ip( tenant_id=server.tenant_id) self._associate_floating_ip(server, address["ip"]) self._dissociate_floating_ip(server, address["ip"])
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_extension("security-group") if not use_sg: LOG.info(_("Security group context is disabled: %s") % 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 cleanup(self): net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["credential"]), self, config=self.config) for tenant_id, tenant_ctx in six.iteritems(self.context["tenants"]): for network in tenant_ctx.get("networks", []): with logging.ExceptionLogger( LOG, _("Failed to delete network for tenant %s") % tenant_id): net_wrapper.delete_network(network) for fip in tenant_ctx.get("fips", []): with logging.ExceptionLogger( LOG, _("Failed to delete floating ip for tenant %s") % tenant_id): net_wrapper.delete_floating_ip(fip["id"])
def setup(self): # NOTE(rkiran): Some clients are not thread-safe. Thus during # multithreading/multiprocessing, it is likely the # sockets are left open. This problem is eliminated by # creating a connection in setup and cleanup seperately. net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["endpoint"]), self.config) for user, tenant_id in (utils.iterate_per_tenants( self.context.get("users", []))): self.context["tenants"][tenant_id]["networks"] = [] for i in range(self.config["networks_per_tenant"]): # NOTE(amaretskiy): add_router and subnets_num take effect # for Neutron only. # NOTE(amaretskiy): Do we need neutron subnets_num > 1 ? network = net_wrapper.create_network(tenant_id, add_router=True, subnets_num=1) self.context["tenants"][tenant_id]["networks"].append(network)
def _remove_default_security_group(self): """Delete default security group for tenants.""" clients = osclients.Clients(self.endpoint) if consts.Service.NEUTRON not in clients.services().values(): return use_sg, msg = network.wrap(clients).supports_security_group() if not use_sg: LOG.debug("Security group context is disabled: %s" % 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 setup(self): # NOTE(rkiran): Some clients are not thread-safe. Thus during # multithreading/multiprocessing, it is likely the # sockets are left open. This problem is eliminated by # creating a connection in setup and cleanup separately. net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["endpoint"]), self.config) for user, tenant_id in (utils.iterate_per_tenants( self.context.get("users", []))): self.context["tenants"][tenant_id]["networks"] = [] for i in range(self.config["networks_per_tenant"]): # NOTE(amaretskiy): add_router and subnets_num take effect # for Neutron only. # NOTE(amaretskiy): Do we need neutron subnets_num > 1 ? network = net_wrapper.create_network(tenant_id, add_router=True, subnets_num=1) self.context["tenants"][tenant_id]["networks"].append(network)
def _remove_default_security_group(self): """Delete default security group for tenants.""" clients = osclients.Clients(self.endpoint) if consts.Service.NEUTRON not in clients.services().values(): return use_sg, msg = network.wrap(clients).supports_security_group() if not use_sg: LOG.debug("Security group context is disabled: %s" % 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 _remove_default_security_group(self): """Delete default security group for tenants.""" clients = osclients.Clients(self.credential) if consts.Service.NEUTRON not in clients.services().values(): return use_sg, msg = network.wrap(clients, self).supports_extension( "security-group") if not use_sg: LOG.debug("Security group context is disabled: %s" % 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["credential"]) security_groups = uclients.neutron().list_security_groups() default = [sg for sg in security_groups["security_groups"] if sg["name"] == "default"] if default: clients.neutron().delete_security_group(default[0]["id"])
def run(self, image, flavor, force_delete=False, **kwargs): """Boot a server with sec_group, ip, keypair and delete it. :param image: image to be used to boot an instance :param flavor: flavor to be used to boot an instance :param force_delete: True if force_delete should be used :param kwargs: Optional additional arguments for server creation """ keypair = self._create_keypair() self.sleep_between(5, 5) security_group = self._create_security_group() self.sleep_between(5, 5) server = self._boot_server(image, flavor, key_name=keypair, secgroups=security_group, **kwargs) self.sleep_between(5, 5) address = network_wrapper.wrap( self.clients, self).create_floating_ip(tenant_id=server.tenant_id) self.sleep_between(5, 5) self._associate_floating_ip(server, address["ip"]) self.sleep_between(5, 5) self._delete_server(server, force=force_delete)
def boot_server_from_volume_snapshot2_edit(self, snapshot, flavor, volume_size, netwrk, auto_assign_nic=False, **kwargs): """Boot a server from a snapshot. The scenario first creates a volume and creates a snapshot from this volume, then boots a server from the created snapshot. Assumes that cleanup is done elsewhere. :param image: image to be used to boot an instance :param flavor: flavor to be used to boot an instance :param volume_size: volume size (in GB) :param auto_assign_nic: True if NICs should be assigned :param kwargs: Optional additional arguments for server creation """ #volume = self._create_volume(volume_size, imageRef=image) #snapshot = self._create_snapshot(volume.id, False) #block_device_mapping = {"vda": "%s:snap::1" % snapshot.id} block_device_mapping_v2 = [{"boot_index": "0","uuid": snapshot,"source_type": "snapshot","volume_size": volume_size,"destination_type": "volume","delete_on_termination": True }] nic=[{'net-id': netwrk}] # sec1= self._create_security_groups(1) # print(sec1[0].name) # self._create_rules_for_security_group_edit([sec1[0]],ip_protocol="tcp",cidr="0.0.0.0/0",from_port=22,to_port=22) # self._create_rules_for_security_group_edit([sec1[0]],ip_protocol="icmp",cidr="0.0.0.0/0",from_port=-1,to_port=-1) # self._create_rules_for_security_group_edit([sec1[0]],ip_protocol="tcp",cidr="0.0.0.0/0",from_port=1,to_port=65535) # self._create_rules_for_security_group_edit([sec1[0]],ip_protocol="udp",cidr="0.0.0.0/0",from_port=1,to_port=65535) server = self._boot_server(None, flavor, nics=nic, block_device_mapping_v2=block_device_mapping_v2, **kwargs) address = network_wrapper.wrap(self.clients, self).create_floating_ip( tenant_id=server.tenant_id) self._associate_floating_ip(server, address["ip"]) # file=open("/home/grafana/custom-rally/vm-ip-address.txt",'a') # file.write(address["ip"]+'\n') print(address["ip"])
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, ctx): super(PrepareEC2ClientContext, self).__init__(ctx) self.net_wrapper = network_wrapper.wrap( osclients.Clients(self.context["admin"]["credential"]), self, config=self.config) self.net_wrapper.start_cidr = '10.0.0.0/16'
def __init__(self, ctx): super(Network, self).__init__(ctx) self.net_wrapper = network_wrapper.wrap( osclients.Clients(ctx["admin"]["endpoint"]), self.config)