def cutover(self, dmd): try: ctx = sm.ServiceContext() except sm.ServiceMigrationError: log.info("Couldn't generate service context, skipping.") return # Create the endpoint we're importing. memcached = sm.Endpoint( name="memcached", purpose="import", application="memcached", portnumber=11211, protocol="tcp", addressConfig=sm.AddressConfig(0, ""), ) commit = False zauths = filter(lambda s: s.name in ["zauth", "Zauth"], ctx.services) log.info("Found %i services named 'zauth' or 'Zauth'." % len(zauths)) for zauth in zauths: mc_imports = filter( lambda ep: ep.name == "memcached" and ep.purpose == "import", zauth.endpoints) if len(mc_imports) > 0: log.info("Service %s already has a memcached endpoint." % zauth.name) continue log.info("Adding a memcached import endpoint to service '%s'." % zauth.name) zauth.endpoints.append(memcached) commit = True if commit: ctx.commit()
def test_endpoints_add(self): """ Tests adding endpoints to an existing list. """ ctx = sm.ServiceContext(INFILENAME) svc = filter(lambda x: x.description == "Zope server", ctx.services)[0] self.assertEqual(len(svc.endpoints), 9) svc.endpoints.append(sm.Endpoint("foo", "bar")) svc.endpoints.append(sm.Endpoint("bar", "baz")) ctx.commit(OUTFILENAME) ctx = sm.ServiceContext(OUTFILENAME) svc = filter(lambda x: x.description == "Zope server", ctx.services)[0] if not "foo" in [ep.name for ep in svc.endpoints]: raise ValueError("Failed to alter endpoints.") if not "bar" in [ep.name for ep in svc.endpoints]: raise ValueError("Failed to alter endpoints.") for ep in svc.endpoints: if ep.name == "foo": self.assertEqual(ep.purpose, "bar") if ep.name == "bar": self.assertEqual(ep.purpose, "baz") self.assertEqual(len(svc.endpoints), 11)
def test_endpoints_replace(self): """ Tests completely replacing the endpoints list. """ ctx = sm.ServiceContext(INFILENAME) svc = filter(lambda x: x.description == "Zope server", ctx.services)[0] svc.endpoints = [ sm.Endpoint("foo", "bar"), sm.Endpoint("bar", "baz"), ] ctx.commit(OUTFILENAME) ctx = sm.ServiceContext(OUTFILENAME) svc = filter(lambda x: x.description == "Zope server", ctx.services)[0] if not "foo" in [ep.name for ep in svc.endpoints]: raise ValueError("Failed to alter endpoints.") if not "bar" in [ep.name for ep in svc.endpoints]: raise ValueError("Failed to alter endpoints.") for ep in svc.endpoints: if ep.name == "foo": self.assertEqual(ep.purpose, "bar") if ep.name == "bar": self.assertEqual(ep.purpose, "baz") self.assertEqual(len(svc.endpoints), 2)
def cutover(self, dmd): try: ctx = sm.ServiceContext() except sm.ServiceMigrationError: log.info("Couldn't generate service context, skipping.") return # Get all services tagged "collector" and "daemon". collectorDaemons = filter( lambda s: all(x in s.tags for x in ["collector", "daemon"]), ctx.services) log.info("Found %i services tagged 'collector' or 'daemon'." % len(collectorDaemons)) # Create the endpoint we're importing. endpoint = sm.Endpoint(name="zproxy", purpose="import", application="zproxy", portnumber=8080, protocol="tcp", addressConfig=sm.AddressConfig(0, "")) # Add the endpoint to each daemon. for daemon in collectorDaemons: # Make sure we're not already importing zproxy. zpImports = filter( lambda ep: ep.name == "zproxy" and ep.purpose == "import", daemon.endpoints) if len(zpImports) > 0: log.info("Service %s already has a zproxy import endpoint." % daemon.name) continue log.info("Adding a zproxy import endpoint to service '%s'." % daemon.name) daemon.endpoints.append(endpoint) # Commit our changes. ctx.commit()
def install_migrate_zenpython(): if not VERSION5: return try: ctx = sm.ServiceContext() except sm.ServiceMigrationError: log.info("Couldn't generate service context, skipping.") return # Create the endpoints we're importing. mgmt_endpoint = { "ApplicationTemplate": "openstack_rabbitmq_{{(parent .).Name}}_admin", "Name": "rabbitmqadmins_ceil", "PortNumber": 45672, "PortTemplate": "{{plus .InstanceID 45672}}", "Protocol": "tcp", "Purpose": "import_all" } mgmt_endpoint_lc = { key.lower(): value for (key, value) in mgmt_endpoint.iteritems() } try: rabbit_mgmt = sm.Endpoint(**mgmt_endpoint_lc) except TypeError: mgmt_endpoint_lc = { key.lower(): value for (key, value) in mgmt_endpoint.iteritems() if key != "PortTemplate" } amqp_endpoint = { "ApplicationTemplate": "openstack_rabbitmq_{{(parent .).Name}}", "Name": "rabbitmqs_ceil", "PortNumber": 55672, "PortTemplate": "{{plus .InstanceID 55672}}", "Protocol": "tcp", "Purpose": "import_all" } amqp_endpoint_lc = { key.lower(): value for (key, value) in amqp_endpoint.iteritems() } try: rabbit_amqp = sm.Endpoint(**amqp_endpoint_lc) except TypeError: amqp_endpoint_lc = { key.lower(): value for (key, value) in amqp_endpoint.iteritems() if key != "PortTemplate" } commit = False zpythons = filter(lambda s: s.name == "zenpython", ctx.services) log.info("Found %i services named 'zenpython'" % len(zpythons)) for zpython in zpythons: collector = ctx.getServiceParent(zpython).name rbtamqp_imports = filter( lambda ep: ep.name == "rabbitmqs_ceil" and ep.purpose == "import_all", zpython.endpoints) if len(rbtamqp_imports) > 0: log.info("Service %s already has a rabbitmqs_ceil endpoint." % ctx.getServicePath(zpython)) else: log.info( "Adding a rabbitmqs_ceil import endpoint to service '%s'." % ctx.getServicePath(zpython)) rabbit_amqp = sm.Endpoint(**amqp_endpoint_lc) rabbit_amqp.__data = copy.deepcopy(amqp_endpoint) rabbit_amqp.application = "openstack_rabbitmq_{}".format(collector) zpython.endpoints.append(rabbit_amqp) commit = True rbtmgmt_imports = filter( lambda ep: ep.name == "rabbitmqadmins_ceil" and ep.purpose == "import_all", zpython.endpoints) if len(rbtmgmt_imports) > 0: log.info("Service %s already has a rabbitmqadmins_ceil endpoint." % ctx.getServicePath(zpython)) else: log.info( "Adding a rabbitmqadmins_ceil import endpoint to service '%s'." % ctx.getServicePath(zpython)) rabbit_mgmt = sm.Endpoint(**mgmt_endpoint_lc) rabbit_mgmt.__data = copy.deepcopy(mgmt_endpoint) rabbit_mgmt.application = "openstack_rabbitmq_{}_admin".format( collector) zpython.endpoints.append(rabbit_mgmt) commit = True # Fix application names for existing rabbitmq-ceilometer and zenpython endpoints # naming convention. services = filter( lambda s: s.name == "zenpython" or s.name == "RabbitMQ-Ceilometer", ctx.services) change_count = 0 for service in services: collector = ctx.getServiceParent(service).name for endpoint in service.endpoints: if endpoint.application.startswith("rabbitmq_"): new_application_name = endpoint.application.replace( "rabbitmq_", "openstack_rabbitmq_") log.debug("%s/%s: Changing endpoint from %s to %s", collector, service.name, endpoint.application, new_application_name) endpoint.application = new_application_name commit = True change_count += 1 if endpoint.applicationtemplate.startswith("rabbitmq_"): new_application_template = endpoint.applicationtemplate.replace( "rabbitmq_", "openstack_rabbitmq_") log.debug("%s/%s: Changing endpoint template from %s to %s", collector, service.name, endpoint.applicationtemplate, new_application_template) endpoint.applicationtemplate = new_application_template commit = True change_count += 1 if change_count: log.info( "Upgraded %d endpoint names and templates to new naming convention.", change_count) if commit: ctx.commit()
def cutover(self, dmd): try: ctx = sm.ServiceContext() except sm.ServiceMigrationError: log.info("Couldn't generate service context, skipping.") return svcs = filter( lambda s: all(x in s.tags for x in ["collector", "daemon"]), ctx.services) daemons = ([ svc for svc in svcs if not svc.name == 'collectorredis' and not svc.name == 'zminion' ]) collectorRedises = [ svc for svc in svcs if svc.name == 'collectorredis' ] ignoreDaemonList = [ 'RabbitMQ-Ceilometer', ] changed = False for daemon in daemons: if daemon.name in ignoreDaemonList: continue try: collectorRedisEndpoint = ([ endpoint for endpoint in daemon.endpoints if endpoint.name == 'CollectorRedis' ][0]) collectorRedisEndpoint.purpose = 'import_all' changed = True except IndexError: log.error("Collector redis endpoint does not exist in {} " "service definition.".format(daemon.name)) return for collectorRedis in collectorRedises: parent = ctx.getServiceParent(collectorRedis) parentName = parent.name if parent else "" collectorRedis.startup = "{{ if ne .InstanceID 0 }} /bin/sed -i 's/# slaveof <masterip> <masterport>/slaveof rd1 6379/' /etc/redis.conf & {{ end }} /usr/bin/redis-server /etc/redis.conf" collectorRedis.changeOptions = ['restartAllOnInstanceZeroDown'] collectorRedis.hostPolicy = 'REQUIRE_SEPARATE' collectorRedis.privileged = True collectorRedis.instanceLimits.maximum = 0 endpoints = [] endpoints.append( sm.Endpoint(name='zproxy', purpose='import', application='zproxy', portnumber=8080, protocol='tcp', applicationtemplate='zproxy')) endpoints.append( sm.Endpoint(name='CollectorRedis', purpose='export', application=parentName + '_redis', portnumber=6379, protocol='tcp', applicationtemplate='{{(parent .).Name}}_redis')) endpoints.append( sm.Endpoint(name='CollectorRedises', purpose='import_all', application=parentName + '_redis', portnumber=16379, protocol='tcp', applicationtemplate='{{(parent .).Name}}_redis', virtualaddress='rd{{ plus 1 .InstanceID }}:6379')) collectorRedis.endpoints = endpoints changed = True if changed: ctx.commit()
svc.endpoints = filter(lambda x: x.name != "zenhub", svc.endpoints) # Alter the mariadb endpoint. maria = filter(lambda x: x.name == "mariadb", svc.endpoints)[0] maria.name = "altered mariadb" maria.purpose = "export" maria.application = "application" maria.portnumber = 1234 maria.protocol = "TCP" maria.addressConfig = sm.AddressConfig(5678, "UDP") # Add a new endpoint svc.endpoints.append( sm.Endpoint(name="endpoint name", purpose="import", application="application", portnumber=9012, protocol="TCP", addressConfig=sm.AddressConfig(3456, "UDP"))) # Remove the "help" command. svc.commands = filter(lambda x: x.name != "help", svc.commands) # Alter the "upgrade" command. upgrade = filter(lambda x: x.name == "upgrade", svc.commands)[0] upgrade.name = "upgrade renamed" upgrade.command = "upgrade command" upgrade.commitOnSuccess = False # Add a new command. svc.commands.append(sm.Command("new command", "new command", False))