def create_in_cluster(env, ip, allow_absent_resource_agent=False): """ Create group with ip resource and booth resource LibraryEnvironment env provides all for communication with externals string ip determines float ip for the operation of the booth bool allow_absent_resource_agent is flag allowing create booth resource even if its agent is not installed """ resources_section = get_resources(env.get_cib()) id_provider = IdProvider(resources_section) name = env.booth.name booth_config_file_path = get_config_file_name(name) if resource.find_for_config(resources_section, booth_config_file_path): raise LibraryError(booth_reports.booth_already_in_cib(name)) create_id = partial( resource.create_resource_id, resources_section, name ) get_agent = partial( find_valid_resource_agent_by_name, env.report_processor, env.cmd_runner(), allowed_absent=allow_absent_resource_agent ) create_primitive = partial( primitive.create, env.report_processor, resources_section, id_provider ) into_booth_group = partial( group.place_resource, group.provide_group(resources_section, create_id("group")), ) into_booth_group(create_primitive( create_id("ip"), get_agent("ocf:heartbeat:IPaddr2"), instance_attributes={"ip": ip}, )) into_booth_group(create_primitive( create_id("service"), get_agent("ocf:pacemaker:booth-site"), instance_attributes={"config": booth_config_file_path}, )) env.push_cib()
def create_in_cluster(env, name, ip, resource_create, resource_remove): #TODO resource_create is provisional hack until resources are not moved to #lib resources_section = get_resources(env.get_cib()) booth_config_file_path = get_config_file_name(name) if resource.find_for_config(resources_section, booth_config_file_path): raise LibraryError(booth_reports.booth_already_in_cib(name)) resource.get_creator(resource_create, resource_remove)( ip, booth_config_file_path, create_id=partial(resource.create_resource_id, resources_section, name))
def create_in_cluster(env, name, ip, resource_create): #TODO resource_create is provisional hack until resources are not moved to #lib resources_section = get_resources(env.get_cib()) booth_config_file_path = get_config_file_name(name) if resource.find_for_config(resources_section, booth_config_file_path): raise LibraryError(booth_reports.booth_already_in_cib(name)) resource.get_creator(resource_create)( ip, booth_config_file_path, create_id = partial( resource.create_resource_id, resources_section, name ) )
def create_in_cluster(env, ip, instance_name=None, allow_absent_resource_agent=False): """ Create group with ip resource and booth resource LibraryEnvironment env -- provides all for communication with externals string ip -- float ip address for the operation of the booth string instance_name -- booth instance name bool allow_absent_resource_agent -- allowing creating booth resource even if its agent is not installed """ report_processor = SimpleReportProcessor(env.report_processor) booth_env = env.get_booth_env(instance_name) # Booth config path goes to CIB. Working with a mocked booth configs would # not work coorectly as the path would point to a mock file (the path to a # mock file is unknown to us in the lib anyway) # It makes sense to work with a mocked CIB, though. Users can do other # changes to the CIB and push them to the cluster at once. _ensure_live_booth_env(booth_env) resources_section = get_resources(env.get_cib()) id_provider = IdProvider(resources_section) instance_name = booth_env.instance_name # validate if resource.find_for_config(resources_section, booth_env.config_path): report_processor.report( booth_reports.booth_already_in_cib(instance_name)) # verify the config exists and is readable try: booth_env.config.raw_file.read() except RawFileError as e: report_processor.report(raw_file_error_report(e)) if report_processor.has_errors: raise LibraryError() # validation done create_id = partial(resource.create_resource_id, resources_section, instance_name) get_agent = partial(find_valid_resource_agent_by_name, env.report_processor, env.cmd_runner(), allowed_absent=allow_absent_resource_agent) create_primitive = partial(primitive.create, env.report_processor, resources_section, id_provider) into_booth_group = partial( group.place_resource, group.provide_group(resources_section, create_id("group")), ) into_booth_group( create_primitive( create_id("ip"), get_agent("ocf:heartbeat:IPaddr2"), instance_attributes={"ip": ip}, )) into_booth_group( create_primitive( create_id("service"), get_agent("ocf:pacemaker:booth-site"), instance_attributes={"config": booth_env.config_path}, )) env.push_cib()
def test_success(self): self.assert_message_from_report( "booth instance 'name' is already created as cluster resource", reports.booth_already_in_cib("name"))