Class: BrpmRestClient
- Inherits:
-
Object
- Object
- BrpmRestClient
- Defined in:
- lib/brpm_rest_client.rb
Instance Method Summary collapse
- #archive_list(list_id) ⇒ Object
- #archive_list_item(list_item_id) ⇒ Object
- #cancel_plan(plan_id) ⇒ Object
- #copy_version_tags_of_app_and_comp_from_env_to_env(app_name, component_name, source_env, target_env) ⇒ Object
-
#create(model_name, data, options = {}) ⇒ Object
Performs a post on the passed model use this to create a new record ==== Attributes.
- #create_environment(environment_name) ⇒ Object
- #create_installed_component(component_name, component_version, environment_name, app_name, server_name) ⇒ Object
- #create_list_from_hash(list) ⇒ Object
- #create_list_item_from_hash(list_item) ⇒ Object
- #create_or_update_list_item(list_name, list_item_name) ⇒ Object
- #create_or_update_script(script) ⇒ Object
- #create_or_update_ticket(ticket) ⇒ Object
- #create_plan(template_name, plan_name, date = nil, description = nil) ⇒ Object
- #create_request(template_name, name, environment, execute_now, data = {}) ⇒ Object
- #create_request_for_plan(plan_id, stage_name, name, requestor_id, app_name, env_name, execute_now, data = nil) ⇒ Object
- #create_request_for_plan_from_template(plan_id, stage_name, template_name, name, env_name, execute_now, data = {}) ⇒ Object
- #create_request_from_hash(request) ⇒ Object
- #create_script_from_hash(script) ⇒ Object
- #create_server(server_name, dns = nil, environment_ids = nil, ip_address = nil, os_platform = nil, property_ids = nil) ⇒ Object
- #create_step(request_id, name, owner_type, owner_id) ⇒ Object
- #create_step_from_hash(step) ⇒ Object
- #create_ticket_from_hash(ticket) ⇒ Object
- #create_version_tag(app_name, component_name, environment, version_tag_name) ⇒ Object
- #delete_environment(environment_name) ⇒ Object
- #delete_list(list_id) ⇒ Object
- #delete_list_item(list_item_id) ⇒ Object
- #delete_plan(plan_id) ⇒ Object
- #delete_request(request_id) ⇒ Object
- #delete_script(script_id) ⇒ Object
- #delete_version_tag(version_tag_id) ⇒ Object
-
#get(model_name, model_id = nil, options = {}) ⇒ Object
Performs a get on the passed model.
- #get_app_by_id(app_id) ⇒ Object
- #get_app_by_name(app_name) ⇒ Object
- #get_apps ⇒ Object
- #get_attribute_value(name, attributes) ⇒ Object
- #get_component_by_id(component_id) ⇒ Object
- #get_constraints ⇒ Object
- #get_environment_by_id(environment_id) ⇒ Object
- #get_environment_by_name(environment_name) ⇒ Object
- #get_environments_of_application(app_name) ⇒ Object
- #get_first_environment_of_route_for_plan_and_app(plan_id, app_id) ⇒ Object
- #get_group_by_name(name) ⇒ Object
- #get_id_for_project_server_type(integration_server_type) ⇒ Object
- #get_installed_component(component_name, environment_name) ⇒ Object
- #get_installed_component_by_id(component_id) ⇒ Object
- #get_installed_components_by(filter) ⇒ Object
- #get_list_by_id(list_id) ⇒ Object
- #get_list_by_name(name) ⇒ Object
- #get_list_item_by_id(list_item_id) ⇒ Object
- #get_list_item_by_name(list_name, list_item_name) ⇒ Object
- #get_list_items_by(filter) ⇒ Object
- #get_plan_by_id(plan_id) ⇒ Object
- #get_plan_by_name(plan_name) ⇒ Object
- #get_plan_route_by_plan_and_app(plan_id, app_id) ⇒ Object
- #get_plan_stage_by_id(plan_stage_id) ⇒ Object
- #get_plan_stage_id(plan_id, stage_name) ⇒ Object
- #get_plan_template_by_name(plan_template_name) ⇒ Object
- #get_plans_by(filter) ⇒ Object
- #get_project_servers ⇒ Object
- #get_property_by_name(property_name) ⇒ Object
- #get_request_by_id(request_id) ⇒ Object
- #get_request_templates_by_app(app_name) ⇒ Object
- #get_requests_by(filter) ⇒ Object
- #get_requests_by_name(request_name) ⇒ Object
- #get_requests_by_name_and_plan_and_stage(request_name, plan_name, stage_name) ⇒ Object
- #get_requests_by_plan_id_and_stage_name(plan_id, stage_name) ⇒ Object
- #get_requests_by_plan_id_and_stage_name_and_app_name(plan_id, stage_name, app_name) ⇒ Object
- #get_route_by_id(route_id) ⇒ Object
- #get_route_gate_by_id(route_gate_id) ⇒ Object
- #get_run_by_id(run_id) ⇒ Object
- #get_script_by_name(name) ⇒ Object
- #get_scripts_by(filter) ⇒ Object
- #get_server_by_name(server_name) ⇒ Object
- #get_server_group_from_step_id(step_id) ⇒ Object
- #get_step_by_id(step_id) ⇒ Object
- #get_steps_by(filter) ⇒ Object
- #get_ticket_by_foreign_id(ticket_foreign_id) ⇒ Object
- #get_tickets_by(filter) ⇒ Object
- #get_tickets_by_request_id(request_id) ⇒ Object
- #get_tickets_by_run_id_and_request_state(run_id, state) ⇒ Object
- #get_user_by_id(user_id) ⇒ Object
- #get_user_by_name(first_name, last_name) ⇒ Object
- #get_version_tag(app_name, component_name, environment_name, version_tag_name) ⇒ Object
- #get_version_tags_by(filter) ⇒ Object
- #get_version_tags_by_app_and_comp_and_env(app_name, component_name, environment_name) ⇒ Object
- #get_work_task_by_name(name) ⇒ Object
-
#initialize(brpm_url = BrpmAuto.params.brpm_url, brpm_api_token = BrpmAuto.params.brpm_api_token) ⇒ BrpmRestClient
constructor
A new instance of BrpmRestClient.
- #link_environment_to_app(environment_id, app_name) ⇒ Object
- #link_environment_to_server(environment_id, server_name) ⇒ Object
- #monitor_request(request_id, options = {}) ⇒ Object
- #move_request_to_plan_and_stage(request_id, plan_id, stage_name) ⇒ Object
-
#notify(body, subject = "Mail from automation", recipients = nil, step_id = BrpmAuto.params.step_id) ⇒ Object
Sends an email based on step recipients.
- #plan_plan(plan_id) ⇒ Object
- #plan_request(request_id) ⇒ Object
- #rename_environment(environment_id, environment_name) ⇒ Object
- #set_property_of_installed_component(installed_component_id, property, value) ⇒ Object
- #set_property_of_server(server_id, property_id, value) ⇒ Object
- #set_servers_of_installed_component(installed_component_id, server_names) ⇒ Object
- #set_version_of_steps_for_component(request, component_name, version) ⇒ Object
- #set_version_tag_of_steps_for_component(request, component_name, version_tag_name) ⇒ Object
- #start_plan(plan_id) ⇒ Object
- #start_request(request_id) ⇒ Object
- #sync_attribute(name, value, attributes) ⇒ Object
- #sync_attributes(existing_attributes, updated_attributes) ⇒ Object
- #unlink_environment_from_app(environment_name, app_name) ⇒ Object
- #unlink_environment_from_server(environment_name, server_name) ⇒ Object
-
#update(model_name, model_id, data, options = {}) ⇒ Object
Performs a put on the passed model use this to update a single record ==== Attributes.
- #update_list_from_hash(list) ⇒ Object
- #update_list_item_from_hash(list_item) ⇒ Object
- #update_request_from_hash(request) ⇒ Object
- #update_script_from_hash(script) ⇒ Object
- #update_step_from_hash(step) ⇒ Object
- #update_ticket_from_hash(ticket) ⇒ Object
Constructor Details
#initialize(brpm_url = BrpmAuto.params.brpm_url, brpm_api_token = BrpmAuto.params.brpm_api_token) ⇒ BrpmRestClient
Returns a new instance of BrpmRestClient.
2 3 4 5 |
# File 'lib/brpm_rest_client.rb', line 2 def initialize(brpm_url = BrpmAuto.params.brpm_url, brpm_api_token= BrpmAuto.params.brpm_api_token) @brpm_url = brpm_url @brpm_api_token = brpm_api_token end |
Instance Method Details
#archive_list(list_id) ⇒ Object
1488 1489 1490 1491 1492 1493 1494 1495 1496 |
# File 'lib/brpm_rest_client.rb', line 1488 def archive_list(list_id) result = brpm_put "v1/lists/#{list_id}", { :toggle_archive => true } unless result["status"] == "success" raise "Could not archive the list: #{result["error_message"]}" end result["response"] end |
#archive_list_item(list_item_id) ⇒ Object
1618 1619 1620 1621 1622 1623 1624 1625 1626 |
# File 'lib/brpm_rest_client.rb', line 1618 def archive_list_item(list_item_id) result = brpm_put "v1/list_items/#{list_item_id}", { :toggle_archive => true } unless result["status"] == "success" raise "Could not archive the list item: #{result["error_message"]}" end result["response"] end |
#cancel_plan(plan_id) ⇒ Object
732 733 734 735 736 737 738 739 740 741 |
# File 'lib/brpm_rest_client.rb', line 732 def cancel_plan(plan_id) plan = {} plan["aasm_event"] = "cancel" result = brpm_put "v1/plans/#{plan_id}", { :plan => plan} unless result["status"] == "success" raise "Could not cancel plan: #{result["error_message"]}" end end |
#copy_version_tags_of_app_and_comp_from_env_to_env(app_name, component_name, source_env, target_env) ⇒ Object
655 656 657 658 659 660 661 |
# File 'lib/brpm_rest_client.rb', line 655 def (app_name, component_name, source_env, target_env) = (app_name, component_name, source_env) .each do |source_version_tag| create_version_tag(app_name, component_name, target_env, source_version_tag["name"]) end end |
#create(model_name, data, options = {}) ⇒ Object
Performs a post on the passed model
use this to create a new record
Attributes
-
model_name
- rpm model [requests, plans, steps, version_tags, etc] -
data
- hash of the put data -
options
- hash of options includesincludes all the Rest.rest_call
Returns
-
hash of http response
60 61 62 63 64 65 |
# File 'lib/brpm_rest_client.rb', line 60 def create(model_name, data, = {}) ["data"] = data url = get_brpm_url(model_name) result = Rest.post(url, ) result end |
#create_environment(environment_name) ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/brpm_rest_client.rb', line 281 def create_environment(environment_name) environment={} environment["name"]=environment_name result = brpm_post "v1/environments", { :environment => environment } if result["status"] == "success" result_hash = result["response"] else if Rest.already_exists_error(result) BrpmAuto.log "This environment already exists. Continuing ..." result_hash = get_environment_by_name(environment_name) else raise "Could not create environment: #{result["error_message"]}" end end result_hash end |
#create_installed_component(component_name, component_version, environment_name, app_name, server_name) ⇒ Object
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'lib/brpm_rest_client.rb', line 483 def create_installed_component(component_name, component_version, environment_name, app_name, server_name) installed_comp = {} installed_comp["app_name"] = app_name installed_comp["component_name"] = component_name installed_comp["environment_name"] = environment_name installed_comp["version"]= component_version installed_comp["server_names"] = [ server_name ] result = brpm_post "v1/installed_components", { :installed_component => installed_comp } if result["status"] == "success" result_hash = result["response"] else if Rest.already_exists_error(result) BrpmAuto.log "This installed component already exists." result_hash = get_installed_component(component_name, environment_name) result_hash = get_installed_component_by_id(result_hash["id"]) servers = result_hash["servers"].map { |server| server["name"] } BrpmAuto.log "Verifying if the existing installed component is already linked to the server ..." if servers.include?(server_name) BrpmAuto.log "The existing installed component is already linked to the server. Continuing ..." else BrpmAuto.log "The existing installed component is not yet linked to the server, doing it now ..." servers.push server_name set_servers_of_installed_component(result_hash["id"], servers) end else raise "Could not create installed component: #{result["error_message"]}" end end BrpmAuto.log "Copying the version tags from environment [default] to environment #{environment_name} ..." (app_name, component_name, "[default]", environment_name) result_hash end |
#create_list_from_hash(list) ⇒ Object
1468 1469 1470 1471 1472 1473 1474 1475 1476 |
# File 'lib/brpm_rest_client.rb', line 1468 def create_list_from_hash(list) result = brpm_post "v1/lists", { :list => list } unless result["status"] == "success" raise "Could not create the list: #{result["error_message"]}" end result["response"] end |
#create_list_item_from_hash(list_item) ⇒ Object
1558 1559 1560 1561 1562 1563 1564 1565 1566 |
# File 'lib/brpm_rest_client.rb', line 1558 def create_list_item_from_hash(list_item) result = brpm_post "v1/list_items", { :list_item => list_item } unless result["status"] == "success" raise "Could not create the list item: #{result["error_message"]}" end result["response"] end |
#create_or_update_list_item(list_name, list_item_name) ⇒ Object
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 |
# File 'lib/brpm_rest_client.rb', line 1578 def create_or_update_list_item(list_name, list_item_name) BrpmAuto.log "Checking if the corresponding list item already exists ..." existing_list_item = get_list_item_by_name(list_name, list_item_name) list_item = {} list_item["value_text"] = list_item_name if existing_list_item.nil? BrpmAuto.log "List item doesn't exist yet." list_item_already_exists=false list = get_list_by_name(list_name) if list list_item["list_id"] = list["id"] else raise "A list with the name #{list_name} doesn't exist." end else BrpmAuto.log "List item already exists." list_item_already_exists=true list_item["id"] = existing_list_item["id"].to_s end data = {} data["list_item"] = list_item if list_item_already_exists BrpmAuto.log "Updating the list item..." list_item = update_list_item_from_hash(list_item) BrpmAuto.log "list_item is updated." else BrpmAuto.log "Creating the list item..." list_item = create_list_item_from_hash(list_item) BrpmAuto.log "List item is created." end list_item end |
#create_or_update_script(script) ⇒ Object
1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 |
# File 'lib/brpm_rest_client.rb', line 1700 def create_or_update_script(script) BrpmAuto.log "Checking if the corresponding script already exists ..." existing_script = get_script_by_name(script["name"]) if existing_script.nil? BrpmAuto.log "Script doesn't exist yet." script_already_exists=false else BrpmAuto.log "Script already exists." script_already_exists=true script["id"] = existing_script["id"].to_s end data = {} data["script"] = script if script_already_exists BrpmAuto.log "Updating the script..." script = update_script_from_hash(script) BrpmAuto.log "Script is updated." else BrpmAuto.log "Creating the script..." script = create_script_from_hash(script) BrpmAuto.log "Script is created." end script end |
#create_or_update_ticket(ticket) ⇒ Object
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 |
# File 'lib/brpm_rest_client.rb', line 1372 def create_or_update_ticket(ticket) BrpmAuto.log "Checking if the corresponding ticket already exists ..." existing_ticket = get_ticket_by_foreign_id ticket["foreign_id"] if existing_ticket.nil? BrpmAuto.log "Ticket doesn't exist yet." ticket_already_exists=false else BrpmAuto.log "Ticket already exists." ticket_already_exists=true ticket["id"] = existing_ticket["id"].to_s ticket["extended_attributes_attributes"] = sync_attributes(existing_ticket["extended_attributes"], ticket["extended_attributes_attributes"]) end now = Time.now.to_s sync_attribute "first received", now, ticket["extended_attributes_attributes"] unless ticket_already_exists sync_attribute "last updated", now, ticket["extended_attributes_attributes"] data = {} data["ticket"] = ticket if ticket_already_exists BrpmAuto.log "Updating the ticket ..." update_ticket_from_hash(ticket) BrpmAuto.log "Ticket is updated." else BrpmAuto.log "Creating the ticket ..." create_ticket_from_hash(ticket) BrpmAuto.log "Ticket is created." end end |
#create_plan(template_name, plan_name, date = nil, description = nil) ⇒ Object
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
# File 'lib/brpm_rest_client.rb', line 679 def create_plan(template_name, plan_name, date = nil, description = nil) plan = {} plan["plan_template_name"] = template_name plan["name"] = plan_name plan["release_date"] = date.utc if date plan["description"] = description result = brpm_post "v1/plans", { :plan => plan } if result["status"] == "success" result_hash = result["response"] else if Rest.already_exists_error(result) BrpmAuto.log "This plan already exists. Continuing ..." result_hash = get_plan_by_name(plan_name) else raise "Could not create plan: #{result["error_message"]}" end end result_hash end |
#create_request(template_name, name, environment, execute_now, data = {}) ⇒ Object
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 |
# File 'lib/brpm_rest_client.rb', line 888 def create_request(template_name, name, environment, execute_now, data = {}) request = {} request["template_name"] = template_name request["name"] = name request["environment"] = environment request["execute_now"] = execute_now request["data"] = data result = brpm_post "v1/requests", { :request => request } unless result["status"] == "success" raise "Could not create the request: #{result["error_message"]}" end result["response"] end |
#create_request_for_plan(plan_id, stage_name, name, requestor_id, app_name, env_name, execute_now, data = nil) ⇒ Object
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 |
# File 'lib/brpm_rest_client.rb', line 915 def create_request_for_plan(plan_id, stage_name, name, requestor_id, app_name, env_name, execute_now, data = nil) plan_stage_id = get_plan_stage_id(plan_id, stage_name) request = {} request["plan_member_attributes"] = { "plan_id" => plan_id, "plan_stage_id" => plan_stage_id } request["name"] = name request["requestor_id"] = requestor_id request["deployment_coordinator_id"] = requestor_id request["app_ids"] = [ get_app_by_name(app_name)["id"] ] request["environment"] = env_name request["execute_now"] = execute_now request["data"] = data result = brpm_post "v1/requests", { :request => request } unless result["status"] == "success" raise "Could not create the request: #{result["error_message"]}" end result["response"] end |
#create_request_for_plan_from_template(plan_id, stage_name, template_name, name, env_name, execute_now, data = {}) ⇒ Object
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 |
# File 'lib/brpm_rest_client.rb', line 937 def create_request_for_plan_from_template(plan_id, stage_name, template_name, name, env_name, execute_now, data = {}) plan_stage_id = get_plan_stage_id(plan_id, stage_name) request = {} request["plan_member_attributes"] = { "plan_id" => plan_id, "plan_stage_id" => plan_stage_id } request["template_name"] = template_name request["name"] = name request["environment"] = env_name request["execute_now"] = execute_now request["data"] = data result = brpm_post "v1/requests", { :request => request } unless result["status"] == "success" raise "Could not create the request: #{result["error_message"]}" end result["response"] end |
#create_request_from_hash(request) ⇒ Object
905 906 907 908 909 910 911 912 913 |
# File 'lib/brpm_rest_client.rb', line 905 def create_request_from_hash(request) result = brpm_post "v1/requests", { :request => request } unless result["status"] == "success" raise "Could not create the request: #{result["error_message"]}" end result["response"] end |
#create_script_from_hash(script) ⇒ Object
1680 1681 1682 1683 1684 1685 1686 1687 1688 |
# File 'lib/brpm_rest_client.rb', line 1680 def create_script_from_hash(script) result = brpm_post "v1/scripts", { :script => script } unless result["status"] == "success" raise "Could not create the script: #{result["error_message"]}" end result["response"] end |
#create_server(server_name, dns = nil, environment_ids = nil, ip_address = nil, os_platform = nil, property_ids = nil) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/brpm_rest_client.rb', line 127 def create_server(server_name, dns = nil, environment_ids = nil, ip_address = nil, os_platform = nil, property_ids = nil) server={} server["name"] = server_name server["environment_ids"] = environment_ids unless environment_ids.nil? server["ip_address"] = ip_address unless ip_address.nil? server["os_platform"] = os_platform unless os_platform.nil? server["property_ids"] = property_ids unless property_ids.nil? result = brpm_post "v1/servers", { :server => server } if result["status"] == "success" result_hash = result["response"] else if Rest.already_exists_error(result) BrpmAuto.log "This server already exists." result_hash = get_server_by_name(server_name) existing_environment_ids = result_hash["environments"].map { |env| env["id"] } environment_ids ||= [] (environment_ids - existing_environment_ids).each do |environment_id| link_environment_to_server(environment_id, server_name) end else raise "Could not create server: #{result["error_message"]}" end end result_hash end |
#create_step(request_id, name, owner_type, owner_id) ⇒ Object
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 |
# File 'lib/brpm_rest_client.rb', line 1171 def create_step(request_id, name, owner_type, owner_id) step = {} step["request_id"] = request_id step["name"] = name step["owner_type"] = owner_type step["owner_id"] = owner_id result = brpm_post "v1/steps", { :step => step } unless result["status"] == "success" raise "Could not create the step: #{result["error_message"]}" end result["response"] end |
#create_step_from_hash(step) ⇒ Object
1161 1162 1163 1164 1165 1166 1167 1168 1169 |
# File 'lib/brpm_rest_client.rb', line 1161 def create_step_from_hash(step) result = brpm_post "v1/steps", { :step => step } unless result["status"] == "success" raise "Could not create the step: #{result["error_message"]}" end result["response"] end |
#create_ticket_from_hash(ticket) ⇒ Object
1352 1353 1354 1355 1356 1357 1358 1359 1360 |
# File 'lib/brpm_rest_client.rb', line 1352 def create_ticket_from_hash(ticket) result = brpm_post "v1/tickets", { :ticket => ticket } unless result["status"] == "success" raise "Could not create the ticket: #{result["error_message"]}" end result["response"] end |
#create_version_tag(app_name, component_name, environment, version_tag_name) ⇒ Object
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/brpm_rest_client.rb', line 569 def create_version_tag(app_name, component_name, environment, version_tag_name) version_tag={} version_tag["name"] = version_tag_name version_tag["find_application"] = app_name version_tag["find_component"] = component_name version_tag["find_environment"] = environment version_tag["active"] = true result = brpm_post "v1/version_tags", { :version_tag => version_tag } if result["status"] == "success" result_hash = result["response"] else if Rest.already_exists_error(result) BrpmAuto.log "This version tag already exists. Continuing ..." result_hash = get_version_tag(app_name, component_name, environment, version_tag_name) else raise "Could not create version tag: #{result["error_message"]}" end end result_hash end |
#delete_environment(environment_name) ⇒ Object
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/brpm_rest_client.rb', line 312 def delete_environment(environment_name) environment = get_environment_by_name(environment_name) if environment.nil? BrpmAuto.log "This environment doesn't exist. Continuing ..." return end rename_environment(environment["id"], environment_name) result = brpm_delete "v1/environments/#{environment["id"]}" unless result["status"] == "success" raise "Could not delete environment: #{result["error_message"]}" end end |
#delete_list(list_id) ⇒ Object
1498 1499 1500 1501 1502 1503 1504 1505 1506 |
# File 'lib/brpm_rest_client.rb', line 1498 def delete_list(list_id) result = brpm_delete "v1/lists/#{list_id}" unless result["status"] == "success" raise "Could not delete the list: #{result["error_message"]}" end result["response"] end |
#delete_list_item(list_item_id) ⇒ Object
1628 1629 1630 1631 1632 1633 1634 1635 1636 |
# File 'lib/brpm_rest_client.rb', line 1628 def delete_list_item(list_item_id) result = brpm_delete "v1/list_items/#{list_item_id}" unless result["status"] == "success" raise "Could not delete the list item: #{result["error_message"]}" end result["response"] end |
#delete_plan(plan_id) ⇒ Object
702 703 704 705 706 707 708 |
# File 'lib/brpm_rest_client.rb', line 702 def delete_plan(plan_id) result = brpm_delete "v1/plans/#{plan_id}" unless result["status"] == "success" raise "Could not delete plan: #{result["error_message"]}" end end |
#delete_request(request_id) ⇒ Object
957 958 959 960 961 962 963 |
# File 'lib/brpm_rest_client.rb', line 957 def delete_request(request_id) result = brpm_delete "v1/requests/#{request_id}" unless result["status"] == "success" raise "Could not delete request: #{result["error_message"]}" end end |
#delete_script(script_id) ⇒ Object
1730 1731 1732 1733 1734 1735 1736 |
# File 'lib/brpm_rest_client.rb', line 1730 def delete_script(script_id) result = brpm_delete "v1/scripts/#{script_id}" unless result["status"] == "success" raise "Could not delete script: #{result["error_message"]}" end end |
#delete_version_tag(version_tag_id) ⇒ Object
593 594 595 596 597 598 599 |
# File 'lib/brpm_rest_client.rb', line 593 def delete_version_tag(version_tag_id) result = brpm_delete "v1/version_tags/#{version_tag_id}" unless result["status"] == "success" raise "Could not delete version tag: #{result["error_message"]}" end end |
#get(model_name, model_id = nil, options = {}) ⇒ Object
Performs a get on the passed model
Attributes
-
model_name
- rpm model [requests, plans, steps, version_tags, etc] -
model_id
- id of a specific item in the model (optional) -
options
- hash of options includes+filters+ - string of the filter text: filters[BrpmAuto.login]=bbyrd includes all the Rest.rest_call options
Returns
-
hash of http response
20 21 22 23 24 25 26 |
# File 'lib/brpm_rest_client.rb', line 20 def get(model_name, model_id = nil, = {}) url = get_brpm_url(model_name, model_id) if get_option(, "filters") == "" url = get_brpm_url(model_name, nil, ["filters"]) if get_option(, "filters") != "" result = Rest.get(url, ) result = brpm_get "v1/#{model_name}#{model_id == nil ? "" : "/#{model_id}" }" end |
#get_app_by_id(app_id) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/brpm_rest_client.rb', line 208 def get_app_by_id(app_id) result = brpm_get "v1/apps/#{app_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for application #{app_id}: #{result["error_message"]}" end result_hash end |
#get_app_by_name(app_name) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/brpm_rest_client.rb', line 220 def get_app_by_name(app_name) result = brpm_get "v1/apps?filters[name]=#{app_name}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash=nil else raise "Could not find application #{app_name}: #{result["error_message"]}" end end result_hash end |
#get_apps ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/brpm_rest_client.rb', line 192 def get_apps result = brpm_get "v1/apps" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Error getting apps: #{result["error_message"]}" end end result_hash end |
#get_attribute_value(name, attributes) ⇒ Object
1769 1770 1771 1772 1773 |
# File 'lib/brpm_rest_client.rb', line 1769 def get_attribute_value name, attributes attribute = attributes.find { |attribute| attribute["name"] == name } return attribute["value_text"] unless attribute.nil? end |
#get_component_by_id(component_id) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/brpm_rest_client.rb', line 236 def get_component_by_id(component_id) result = brpm_get "v1/components/#{component_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for component #{component_id}: #{result["error_message"]}" end result_hash end |
#get_constraints ⇒ Object
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
# File 'lib/brpm_rest_client.rb', line 827 def get_constraints result = brpm_get "v1/constraints" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Error searching for constraints: #{result["error_message"]}" end end result_hash end |
#get_environment_by_id(environment_id) ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/brpm_rest_client.rb', line 253 def get_environment_by_id(environment_id) result = brpm_get "v1/environments/#{environment_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for environment #{environment_id}: #{result["error_message"]}" end result_hash end |
#get_environment_by_name(environment_name) ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/brpm_rest_client.rb', line 265 def get_environment_by_name(environment_name) result = brpm_get "v1/environments?filters[name]=#{environment_name}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash=nil else raise "Error searching for environment #{environment_name}: #{result["error_message"]}" end end result_hash end |
#get_environments_of_application(app_name) ⇒ Object
248 249 250 251 |
# File 'lib/brpm_rest_client.rb', line 248 def get_environments_of_application(app_name) app = get_app_by_name(app_name) app["environments"] end |
#get_first_environment_of_route_for_plan_and_app(plan_id, app_id) ⇒ Object
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 |
# File 'lib/brpm_rest_client.rb', line 871 def get_first_environment_of_route_for_plan_and_app(plan_id, app_id) BrpmAuto.log "Getting the plan route..." plan_route = get_plan_route_by_plan_and_app(plan_id, app_id) unless plan_route BrpmAuto.log "No plan route found for plan id #{plan_id} and app id #{app_id}." return nil end BrpmAuto.log "Getting the route..." route = get_route_by_id(plan_route["route"]["id"]) route_gate = route["route_gates"].find { |route_gate| route_gate["position"] == 1 } return route_gate["environment"]["name"] end |
#get_group_by_name(name) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/brpm_rest_client.rb', line 95 def get_group_by_name(name) result = brpm_get "v1/groups?filters[name]=#{name}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash=nil else raise "Could not find group #{name}: #{result["error_message"]}" end end result_hash end |
#get_id_for_project_server_type(integration_server_type) ⇒ Object
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 |
# File 'lib/brpm_rest_client.rb', line 1421 def get_id_for_project_server_type(integration_server_type) case integration_server_type.downcase when "Jira".downcase return 2 when "ServiceNow".downcase, "SNOW".downcase return 4 when "Hudson/Jenkins".downcase, "Jenkins".downcase return 5 when "Remedy via AO".downcase, "AO".downcase, "AtriumOrchestrator".downcase return 8 when "BMC Application Automation".downcase, "Bladelogic".downcase return 9 when "RLM Deployment Engine".downcase, "BRPD".downcase return 10 else return nil end end |
#get_installed_component(component_name, environment_name) ⇒ Object
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'lib/brpm_rest_client.rb', line 445 def get_installed_component(component_name, environment_name) result = brpm_get "v1/installed_components?filters[component_name]=#{component_name}&filters[environment_name]=#{environment_name}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash=nil else raise "Error searching for installed component #{component_name} / #{environment_name} #{result["error_message"]}" end end result_hash end |
#get_installed_component_by_id(component_id) ⇒ Object
433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/brpm_rest_client.rb', line 433 def get_installed_component_by_id(component_id) result = brpm_get "v1/installed_components/#{component_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for installed component #{component_id}: #{result["error_message"]}" end result_hash end |
#get_installed_components_by(filter) ⇒ Object
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/brpm_rest_client.rb', line 461 def get_installed_components_by(filter) filter_string = "?" filter.each do |key, value| filter_string += "filters[#{key}]=#{value}&" end filter_string = filter_string[0..-1] result = brpm_get "v1/installed_components#{filter_string}" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Error searching for installed_components by #{filter_string}: #{result["error_message"]}" end end result_hash end |
#get_list_by_id(list_id) ⇒ Object
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 |
# File 'lib/brpm_rest_client.rb', line 1440 def get_list_by_id(list_id) result = brpm_get "v1/lists/#{list_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for list #{list_id}: #{result["error_message"]}" end result_hash end |
#get_list_by_name(name) ⇒ Object
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 |
# File 'lib/brpm_rest_client.rb', line 1452 def get_list_by_name(name) result = brpm_get "v1/lists?filters[name]=#{name}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash = nil else raise "Could not find list item #{name}: #{result["error_message"]}" end end result_hash end |
#get_list_item_by_id(list_item_id) ⇒ Object
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 |
# File 'lib/brpm_rest_client.rb', line 1508 def get_list_item_by_id(list_item_id) result = brpm_get "v1/list_items/#{list_item_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for list item #{list_item_id}: #{result["error_message"]}" end result_hash end |
#get_list_item_by_name(list_name, list_item_name) ⇒ Object
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 |
# File 'lib/brpm_rest_client.rb', line 1520 def get_list_item_by_name(list_name, list_item_name) result = brpm_get "v1/list_items?filters[list_name]=#{list_name}&filters[value_text]=#{list_item_name}" if result["status"] == "success" result_hash = get_list_item_by_id(result["response"].first["id"]) else if result["code"] == 404 result_hash = nil else raise "Could not find list item #{list_item_name} in list #{list_name}: #{result["error_message"]}" end end result_hash end |
#get_list_items_by(filter) ⇒ Object
1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 |
# File 'lib/brpm_rest_client.rb', line 1536 def get_list_items_by(filter) filter_string = "?" filter.each do |key, value| filter_string += "filters[#{key}]=#{value}&" end filter_string = filter_string[0..-1] result = brpm_get "v1/list_items#{filter_string}" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Error searching for list items by #{filter_string}: #{result["error_message"]}" end end result_hash end |
#get_plan_by_id(plan_id) ⇒ Object
743 744 745 746 747 748 749 750 751 752 753 |
# File 'lib/brpm_rest_client.rb', line 743 def get_plan_by_id(plan_id) result = brpm_get "v1/plans/#{plan_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for plan #{plan_id}: #{result["error_message"]}" end result_hash end |
#get_plan_by_name(plan_name) ⇒ Object
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 |
# File 'lib/brpm_rest_client.rb', line 755 def get_plan_by_name(plan_name) result = brpm_get "v1/plans?filters[name]=#{plan_name}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash=nil else raise "Error searching for plan #{plan_name}: #{result["error_message"]}" end end result_hash end |
#get_plan_route_by_plan_and_app(plan_id, app_id) ⇒ Object
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 |
# File 'lib/brpm_rest_client.rb', line 843 def get_plan_route_by_plan_and_app(plan_id, app_id) result = brpm_get "v1/plan_routes?filters[plan_id]=#{plan_id}&filters[app_id]=#{app_id}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash=nil else raise "Error searching for plan route for plan id #{plan_id} and app id #{app_id}: #{result["error_message"]}" end end result_hash end |
#get_plan_stage_by_id(plan_stage_id) ⇒ Object
803 804 805 806 807 808 809 810 811 812 813 |
# File 'lib/brpm_rest_client.rb', line 803 def get_plan_stage_by_id(plan_stage_id) result = brpm_get "v1/plan_stages/#{plan_stage_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for plan stage #{plan_stage_id}: #{result["error_message"]}" end result_hash end |
#get_plan_stage_id(plan_id, stage_name) ⇒ Object
793 794 795 796 797 798 799 800 801 |
# File 'lib/brpm_rest_client.rb', line 793 def get_plan_stage_id(plan_id, stage_name) plan = get_plan_by_id(plan_id) plan["plan_template"]["stages"].each do |stage| return stage["id"].to_i if stage["name"] == stage_name end raise "Could not find a stage named #{stage_name} for plan #{plan_id}" end |
#get_plan_template_by_name(plan_template_name) ⇒ Object
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
# File 'lib/brpm_rest_client.rb', line 663 def get_plan_template_by_name(plan_template_name) result = brpm_get "v1/plan_templates?filters[name]=#{plan_template_name}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash=nil else raise "Error searching for plan template #{plan_template_name}: #{result["error_message"]}" end end result_hash end |
#get_plans_by(filter) ⇒ Object
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 |
# File 'lib/brpm_rest_client.rb', line 771 def get_plans_by(filter) filter_string = "?" filter.each do |key, value| filter_string += "filters[#{key}]=#{value}&" end filter_string = filter_string[0..-1] result = brpm_get "v1/plans#{filter_string}" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Error searching for plans by #{filter_string}: #{result["error_message"]}" end end result_hash end |
#get_project_servers ⇒ Object
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 |
# File 'lib/brpm_rest_client.rb', line 1405 def get_project_servers result = brpm_get "v1/project_servers" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Error getting project servers: #{result["error_message"]}" end end result_hash end |
#get_property_by_name(property_name) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/brpm_rest_client.rb', line 111 def get_property_by_name(property_name) result = brpm_get "v1/properties?filters[name]=#{property_name}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash=nil else raise "Could not find property #{property_name}: #{result["error_message"]}" end end result_hash end |
#get_request_by_id(request_id) ⇒ Object
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 |
# File 'lib/brpm_rest_client.rb', line 1002 def get_request_by_id(request_id) result = brpm_get "v1/requests/#{request_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for request #{request_id}: #{result["error_message"]}" end result_hash end |
#get_request_templates_by_app(app_name) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/brpm_rest_client.rb', line 174 def get_request_templates_by_app(app_name) app = get_app_by_name(app_name) result = brpm_get "v1/request_templates?filters[app_id]=#{app["id"]}" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash={} else raise "Could not find request templates for app #{app_name}: #{result["error_message"]}" end end result_hash end |
#get_requests_by(filter) ⇒ Object
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 |
# File 'lib/brpm_rest_client.rb', line 1030 def get_requests_by(filter) filter_string = "?" filter.each do |key, value| filter_string += "filters[#{key}]=#{value}&" end filter_string = filter_string[0..-1] result = brpm_get "v1/requests#{filter_string}" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Error searching for request by #{filter_string}: #{result["error_message"]}" end end result_hash end |
#get_requests_by_name(request_name) ⇒ Object
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 |
# File 'lib/brpm_rest_client.rb', line 1014 def get_requests_by_name(request_name) result = brpm_get "v1/requests?filters[name]=#{request_name}" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash=nil else raise "Error searching for request #{request_name}: #{result["error_message"]}" end end result_hash end |
#get_requests_by_name_and_plan_and_stage(request_name, plan_name, stage_name) ⇒ Object
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 |
# File 'lib/brpm_rest_client.rb', line 1052 def get_requests_by_name_and_plan_and_stage(request_name, plan_name, stage_name) result = brpm_get "v1/requests?filters[name]=#{request_name}" if result["status"] == "success" result_hash = result["response"].select { |request| request["plan_member"]["plan"]["name"] == plan_name and request["plan_member"]["stage"]["name"] == stage_name } else if result["code"] == 404 result_hash = {} else raise "Error searching for request #{request_name}: #{result["error_message"]}" end end result_hash end |
#get_requests_by_plan_id_and_stage_name(plan_id, stage_name) ⇒ Object
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 |
# File 'lib/brpm_rest_client.rb', line 1068 def get_requests_by_plan_id_and_stage_name(plan_id, stage_name) result = brpm_get "v1/plans/#{plan_id}" if result["status"] == "success" members_in_plan = result["response"]["members"] members_in_stage = members_in_plan.select { |member| member["stage"]["name"] == stage_name and member.has_key?("request") } result_hash = members_in_stage.map { |member| { "id" => member["request"]["number"].to_i - 1000, "number" => member["request"]["number"], "name" => member["request"]["name"] } } else if result["code"] == 404 result_hash = {} else raise "Error searching for requests by plan id #{plan_id} and stage name #{stage_name}: #{result["error_message"]}" end end result_hash end |
#get_requests_by_plan_id_and_stage_name_and_app_name(plan_id, stage_name, app_name) ⇒ Object
1086 1087 1088 1089 1090 1091 1092 1093 1094 |
# File 'lib/brpm_rest_client.rb', line 1086 def get_requests_by_plan_id_and_stage_name_and_app_name(plan_id, stage_name, app_name) requests_by_plan_and_stage = get_requests_by_plan_id_and_stage_name(plan_id, stage_name) request_ids_1 = requests_by_plan_and_stage.map { |request| request["id"] } requests_by_app = get_requests_by({ "app_id" => get_app_by_name(app_name)["id"] }) request_ids_2 = requests_by_app.map { |request| request["id"] } request_ids_1 & request_ids_2 end |
#get_route_by_id(route_id) ⇒ Object
815 816 817 818 819 820 821 822 823 824 825 |
# File 'lib/brpm_rest_client.rb', line 815 def get_route_by_id(route_id) result = brpm_get "v1/routes/#{route_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for route #{route_id}: #{result["error_message"]}" end result_hash end |
#get_route_gate_by_id(route_gate_id) ⇒ Object
859 860 861 862 863 864 865 866 867 868 869 |
# File 'lib/brpm_rest_client.rb', line 859 def get_route_gate_by_id(route_gate_id) result = brpm_get "v1/route_gates/#{route_gate_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for route gate #{route_gate_id}: #{result["error_message"]}" end result_hash end |
#get_run_by_id(run_id) ⇒ Object
1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 |
# File 'lib/brpm_rest_client.rb', line 1231 def get_run_by_id(run_id) result = brpm_get "v1/runs/#{run_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for run #{run_id}: #{result["error_message"]}" end result_hash end |
#get_script_by_name(name) ⇒ Object
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 |
# File 'lib/brpm_rest_client.rb', line 1638 def get_script_by_name(name) # TODO: the scripts REST API is not finished yet: get_script_by_name always returns "null". So for now we are going to create the script and if it returns an error that the name is already taken we will update it # result = brpm_get "v1/scripts?filters[name]=#{name}" result = brpm_get "v1/scripts" if result["status"] == "success" # result_hash = result["response"].first result_hash = result["response"].find { |script| script["name"] == name} else if result["code"] == 404 result_hash = nil else raise "Could not find script #{name}: #{result["error_message"]}" end end result_hash end |
#get_scripts_by(filter) ⇒ Object
1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 |
# File 'lib/brpm_rest_client.rb', line 1658 def get_scripts_by(filter) filter_string = "?" filter.each do |key, value| filter_string += "filters[#{key}]=#{value}&" end filter_string = filter_string[0..-1] result = brpm_get "v1/scripts#{filter_string}" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Error searching for scripts by #{filter_string}: #{result["error_message"]}" end end result_hash end |
#get_server_by_name(server_name) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/brpm_rest_client.rb', line 158 def get_server_by_name(server_name) result = brpm_get "v1/servers?filters[name]=#{server_name}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash=nil else raise "Could not find server #{server_name}: #{result["error_message"]}" end end result_hash end |
#get_server_group_from_step_id(step_id) ⇒ Object
534 535 536 537 538 539 540 541 542 |
# File 'lib/brpm_rest_client.rb', line 534 def get_server_group_from_step_id(step_id) step = get_step_by_id(step_id) installed_component = get_installed_component_by_id(step["installed_component"]["id"]) return nil unless installed_component["server_group"] installed_component["server_group"]["name"] end |
#get_step_by_id(step_id) ⇒ Object
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 |
# File 'lib/brpm_rest_client.rb', line 1187 def get_step_by_id(step_id) result = brpm_get "v1/steps/#{step_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for step #{step_id}: #{result["error_message"]}" end result_hash end |
#get_steps_by(filter) ⇒ Object
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 |
# File 'lib/brpm_rest_client.rb', line 1209 def get_steps_by(filter) filter_string = "?" filter.each do |key, value| filter_string += "filters[#{key}]=#{value}&" end filter_string = filter_string[0..-1] result = brpm_get "v1/steps#{filter_string}" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Error searching for steps by #{filter_string}: #{result["error_message"]}" end end result_hash end |
#get_ticket_by_foreign_id(ticket_foreign_id) ⇒ Object
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 |
# File 'lib/brpm_rest_client.rb', line 1281 def get_ticket_by_foreign_id(ticket_foreign_id) result = brpm_get "v1/tickets?filters[foreign_id]=#{ticket_foreign_id}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash = nil else raise "Could not find ticket #{ticket_foreign_id}: #{result["error_message"]}" end end result_hash end |
#get_tickets_by(filter) ⇒ Object
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 |
# File 'lib/brpm_rest_client.rb', line 1330 def get_tickets_by(filter) filter_string = "?" filter.each do |key, value| filter_string += "filters[#{key}]=#{value}&" end filter_string = filter_string[0..-1] result = brpm_get "v1/tickets#{filter_string}" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Error searching for tickets by #{filter_string}: #{result["error_message"]}" end end result_hash end |
#get_tickets_by_request_id(request_id) ⇒ Object
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 |
# File 'lib/brpm_rest_client.rb', line 1297 def get_tickets_by_request_id(request_id) result = brpm_get "v1/tickets?filters[request_id]=#{request_id}" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Error searching for tickets by rquest id #{request_id}: #{result["error_message"]}" end end result_hash end |
#get_tickets_by_run_id_and_request_state(run_id, state) ⇒ Object
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 |
# File 'lib/brpm_rest_client.rb', line 1313 def get_tickets_by_run_id_and_request_state(run_id, state) BrpmAuto.log "Getting the requests that are part of run #{run_id} and have state #{state}..." run = get_run_by_id(run_id) request_ids = run["plan_members"].select { |member| member.has_key?("request") and member["request"]["aasm_state"] == state }.map { |member| member["request"]["id"] } BrpmAuto.log "Found #{request_ids.count} requests." BrpmAuto.log "Getting the tickets that are linked to each of the found requests..." tickets = [] request_ids.each do |request_id| tickets_for_request = get_tickets_by_request_id(request_id) tickets = tickets.merge(tickets_for_request) end BrpmAuto.log "Found #{tickets.count} tickets in total." tickets end |
#get_user_by_id(user_id) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/brpm_rest_client.rb', line 67 def get_user_by_id(user_id) result = brpm_get "v1/users/#{user_id}" if result["status"] == "success" result_hash = result["response"] else raise "Error searching for user #{user_id}: #{result["error_message"]}" end result_hash end |
#get_user_by_name(first_name, last_name) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/brpm_rest_client.rb', line 79 def get_user_by_name(first_name, last_name) result = brpm_get "v1/users?filters[first_name]=#{first_name}&filters[last_name]=#{last_name}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash=nil else raise "Could not find user #{first_name} #{last_name}: #{result["error_message"]}" end end result_hash end |
#get_version_tag(app_name, component_name, environment_name, version_tag_name) ⇒ Object
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 |
# File 'lib/brpm_rest_client.rb', line 601 def get_version_tag(app_name, component_name, environment_name, version_tag_name) result = brpm_get "v1/version_tags?filters[app_name]=#{app_name}&filters[component_name]=#{component_name}&filters[environment_name]=#{environment_name}&filters[name]=#{version_tag_name}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash=nil else raise "Could not find application #{app_name}: #{result["error_message"]}" end end result_hash end |
#get_version_tags_by(filter) ⇒ Object
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
# File 'lib/brpm_rest_client.rb', line 633 def (filter) filter_string = "?" filter.each do |key, value| filter_string += "filters[#{key}]=#{value}&" end filter_string = filter_string[0..-1] result = brpm_get "v1/version_tags#{filter_string}" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Error searching for version_tags by #{filter_string}: #{result["error_message"]}" end end result_hash end |
#get_version_tags_by_app_and_comp_and_env(app_name, component_name, environment_name) ⇒ Object
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
# File 'lib/brpm_rest_client.rb', line 617 def (app_name, component_name, environment_name) result = brpm_get "v1/version_tags?filters[app_name]=#{app_name}&filters[component_name]=#{component_name}&filters[environment_name]=#{environment_name}" if result["status"] == "success" result_hash = result["response"] else if result["code"] == 404 result_hash = {} else raise "Could not find version tags for app #{app_name}, component #{component_name}, environment #{environment_name}: #{result["error_message"]}" end end result_hash end |
#get_work_task_by_name(name) ⇒ Object
1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 |
# File 'lib/brpm_rest_client.rb', line 1738 def get_work_task_by_name(name) result = brpm_get "v1/work_tasks?filters[name]=#{name}" if result["status"] == "success" result_hash = result["response"].first else if result["code"] == 404 result_hash = nil else raise "Could not find work_task #{name}: #{result["error_message"]}" end end result_hash end |
#link_environment_to_app(environment_id, app_name) ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/brpm_rest_client.rb', line 381 def link_environment_to_app(environment_id, app_name) app = get_app_by_name(app_name) app_to_update={} app_to_update["environment_ids"] = app["environments"].map{|f| f["id"]} if app_to_update["environment_ids"].include?(environment_id) BrpmAuto.log "This environment is already linked to the application. Continuing..." return end app_to_update["environment_ids"].push(environment_id) result = brpm_put "v1/apps/#{app["id"]}", { :app => app_to_update} unless result["status"] == "success" raise "Could not link environment to app: #{result["error_message"]}" end end |
#link_environment_to_server(environment_id, server_name) ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/brpm_rest_client.rb', line 329 def link_environment_to_server(environment_id, server_name) server = get_server_by_name(server_name) server_to_update={} server_to_update["environment_ids"] = server["environments"].map{|f| f["id"]} if server_to_update["environment_ids"].include?(environment_id) BrpmAuto.log "This server is already linked to the application. Continuing..." return end server_to_update["environment_ids"].push(environment_id) result = brpm_put "v1/servers/#{server["id"]}", { :server => server_to_update } unless result["status"] == "success" raise "Could not link environment to server: #{result["error_message"]}" end end |
#monitor_request(request_id, options = {}) ⇒ Object
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 |
# File 'lib/brpm_rest_client.rb', line 1106 def monitor_request(request_id, = {}) target_status = "complete" max_time = 15*60 # seconds max_time = 60 * [:max_time].to_i if .has_key?(:max_time) and ![:max_time].nil? monitor_step_name = (.has_key?(:monitor_step_name) and ![:monitor_step_name].nil?) ? [:monitor_step_name] : "none" monitor_step_id = (.has_key?(:monitor_step_id) and ![:monitor_step_id].nil?) ? [:monitor_step_id] : "none" checking_interval = 15 #seconds checking_interval = [:checking_interval].to_i if .has_key?(:checking_interval) and ![:checking_interval].nil? req_status = "none" start_time = Time.now elapsed = 0 BrpmAuto.log "Starting the monitoring loop for request #{request_id} with an interval of #{checking_interval} seconds and a maximum time of #{max_time} seconds ..." until (elapsed > max_time || req_status == target_status) request = get_request_by_id(request_id) if monitor_step_name == "none" and monitor_step_id == "none" req_status = request["aasm_state"] else found = false request["steps"].each do |step| if (monitor_step_name != "none" and step["name"] == monitor_step_name) or (monitor_step_id != "none" and step["id"] == monitor_step_id) req_status = step["aasm_state"] found = true break end end unless found raise "Step #{monitor_step_name} not found in request #{request_id}" end end if req_status == target_status BrpmAuto.log "Found request in #{target_status} status! Returning." break end if req_status == "problem" raise "Found request #{request_id} in problem state." end BrpmAuto.log "\tWaiting(#{elapsed.floor.to_s}) - Current status: #{req_status}" sleep(checking_interval) elapsed = Time.now - start_time end if elapsed > max_time raise "Maximum time: #{max_time}(secs) reached. Status is: #{req_status}, looking for: #{target_status}" end end |
#move_request_to_plan_and_stage(request_id, plan_id, stage_name) ⇒ Object
965 966 967 968 969 970 971 972 973 974 975 976 977 978 |
# File 'lib/brpm_rest_client.rb', line 965 def move_request_to_plan_and_stage(request_id, plan_id, stage_name) plan_stage_id = get_plan_stage_id(plan_id, stage_name) request = {} request["plan_member_attributes"] = { "plan_id" => plan_id, "plan_stage_id" => plan_stage_id } result = brpm_put "v1/requests/#{request_id}", { :request => request } unless result["status"] == "success" raise "Could not create the request: #{result["error_message"]}" end result["response"] end |
#notify(body, subject = "Mail from automation", recipients = nil, step_id = BrpmAuto.params.step_id) ⇒ Object
Sends an email based on step recipients
Attributes
-
subject
- text of email subject -
body
- text of email body
Returns
-
empty string
1797 1798 1799 1800 1801 1802 |
# File 'lib/brpm_rest_client.rb', line 1797 def notify(body, subject = "Mail from automation", recipients = nil, step_id = BrpmAuto.params.step_id) data = { "filters" => { "notify" => { "body" => body, "subject" => subject } } } data["filters"]["notify"]["recipients"] = recipients unless recipients.nil? result = brpm_get "v1/steps/#{step_id}/notify", { :data => data } # a REST GET with a request body??? end |
#plan_plan(plan_id) ⇒ Object
710 711 712 713 714 715 716 717 718 719 |
# File 'lib/brpm_rest_client.rb', line 710 def plan_plan(plan_id) plan = {} plan["aasm_event"] = "plan_it" result = brpm_put "v1/plans/#{plan_id}", { :plan => plan} unless result["status"] == "success" raise "Could not plan plan: #{result["error_message"]}" end end |
#plan_request(request_id) ⇒ Object
980 981 982 983 984 985 986 987 988 989 |
# File 'lib/brpm_rest_client.rb', line 980 def plan_request(request_id) request = {} request["aasm_event"] = "plan_it" result = brpm_put "v1/requests/#{request_id}", { :request => request} unless result["status"] == "success" raise "Could not plan request: #{result["error_message"]}" end end |
#rename_environment(environment_id, environment_name) ⇒ Object
301 302 303 304 305 306 307 308 309 310 |
# File 'lib/brpm_rest_client.rb', line 301 def rename_environment(environment_id, environment_name) environment={} environment["name"]="#{Time.now.strftime("%Y%m%d%H%M%S")} #{environment_name}" result = brpm_put "v1/environments/#{environment_id}", { :environment => environment } unless result["status"] == "success" raise "Could not rename environment: #{result["error_message"]}" end end |
#set_property_of_installed_component(installed_component_id, property, value) ⇒ Object
522 523 524 525 526 527 528 529 530 531 532 |
# File 'lib/brpm_rest_client.rb', line 522 def set_property_of_installed_component(installed_component_id, property, value) installed_comp= {} installed_comp["properties_with_values"] = {} installed_comp["properties_with_values"][property] = value result = brpm_put "v1/installed_components/#{installed_component_id}", { :installed_component => installed_comp } unless result["status"] == "success" raise "Could not set properties on installed component: #{result["error_message"]}" end end |
#set_property_of_server(server_id, property_id, value) ⇒ Object
555 556 557 558 559 560 561 562 563 564 565 566 567 |
# File 'lib/brpm_rest_client.rb', line 555 def set_property_of_server(server_id, property_id, value) property = {} property["property_values_with_holders"] = {} property["property_values_with_holders"]["value_holder_type"] = "Server" property["property_values_with_holders"]["value_holder_id"] = server_id property["property_values_with_holders"]["value"] = value result = brpm_put "v1/properties/#{property_id}", { :property => property } unless result["status"] == "success" raise "Could not set property on server: #{result["error_message"]}" end end |
#set_servers_of_installed_component(installed_component_id, server_names) ⇒ Object
544 545 546 547 548 549 550 551 552 553 |
# File 'lib/brpm_rest_client.rb', line 544 def set_servers_of_installed_component(installed_component_id, server_names) installed_comp= {} installed_comp["server_names"] = server_names result = brpm_put "v1/installed_components/#{installed_component_id}", { :installed_component => installed_comp } unless result["status"] == "success" raise "Could not set servers on installed component: #{result["error_message"]}" end end |
#set_version_of_steps_for_component(request, component_name, version) ⇒ Object
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 |
# File 'lib/brpm_rest_client.rb', line 1267 def set_version_of_steps_for_component(request, component_name, version) steps_for_component = request["steps"].select{ |step| step["component_name"] == component_name} steps_for_component.each do |step| step_data = {} step_data["component_version"] = version result = brpm_put "v1/steps/#{step["id"]}", { :step => step_data} unless result["status"] == "success" raise "Could not set the version of the step: #{result["error_message"]}" end end end |
#set_version_tag_of_steps_for_component(request, component_name, version_tag_name) ⇒ Object
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 |
# File 'lib/brpm_rest_client.rb', line 1243 def set_version_tag_of_steps_for_component(request, component_name, version_tag_name) steps_for_component = request["steps"].select{ |step| step["component_name"] == component_name} return if steps_for_component.count == 0 version_tag = get_version_tag(request["apps"].first["name"], component_name, request["environment"]["name"], version_tag_name) if version_tag.nil? raise "No version tag found for app #{request["apps"].first["name"]}, component #{component_name}, environment #{request["environment"]["name"]}, version tag name #{version_tag_name}" end steps_for_component.each do |step| step_data = {} step_data["version_tag_id"] = version_tag["id"] step_data["component_version"] = version_tag_name result = brpm_put "v1/steps/#{step["id"]}", { :step => step_data} unless result["status"] == "success" raise "Could not set the version tag of the step: #{result["error_message"]}" end end end |
#start_plan(plan_id) ⇒ Object
721 722 723 724 725 726 727 728 729 730 |
# File 'lib/brpm_rest_client.rb', line 721 def start_plan(plan_id) plan = {} plan["aasm_event"] = "start" result = brpm_put "v1/plans/#{plan_id}", { :plan => plan} unless result["status"] == "success" raise "Could not start plan: #{result["error_message"]}" end end |
#start_request(request_id) ⇒ Object
991 992 993 994 995 996 997 998 999 1000 |
# File 'lib/brpm_rest_client.rb', line 991 def start_request(request_id) request = {} request["aasm_event"] = "start" result = brpm_put "v1/requests/#{request_id}", { :request => request} unless result["status"] == "success" raise "Could not start request: #{result["error_message"]}" end end |
#sync_attribute(name, value, attributes) ⇒ Object
1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 |
# File 'lib/brpm_rest_client.rb', line 1775 def sync_attribute name, value, attributes attribute = attributes.find { |attribute| attribute["name"] == name } if attribute.nil? attribute = {} attribute["name"] = name attributes.push(attribute) end attribute["value_text"] = value end |
#sync_attributes(existing_attributes, updated_attributes) ⇒ Object
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 |
# File 'lib/brpm_rest_client.rb', line 1754 def sync_attributes(existing_attributes, updated_attributes) existing_attributes ||= [] updated_attributes ||= [] updated_attributes.each do |updated_attribute| existing_attribute = existing_attributes.find { |existing_attribute| existing_attribute["name"] == updated_attribute["name"] } if existing_attribute.nil? existing_attributes.push(updated_attribute) else existing_attribute["value_text"] = updated_attribute["value_text"] end end existing_attributes end |
#unlink_environment_from_app(environment_name, app_name) ⇒ Object
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/brpm_rest_client.rb', line 401 def unlink_environment_from_app(environment_name, app_name) app = get_app_by_name(app_name) if app.nil? BrpmAuto.log "This application doesn't exist. Continuing ..." return end environment = get_environment_by_name(environment_name) if environment.nil? BrpmAuto.log "This environment doesn't exist. Continuing ..." return end app_to_update={} app_to_update["environment_ids"] = app["environments"].map{|f| f["id"]} unless app_to_update["environment_ids"].include?(environment["id"]) BrpmAuto.log "This environment is not linked to the app. Continuing ..." return end app_to_update["environment_ids"].delete(environment["id"]) result = brpm_put "v1/apps/#{app["id"]}", { :app => app_to_update} unless result["status"] == "success" raise "Could not unlink environment from app: #{result["error_message"]}" end end |
#unlink_environment_from_server(environment_name, server_name) ⇒ Object
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/brpm_rest_client.rb', line 349 def unlink_environment_from_server(environment_name, server_name) server = get_server_by_name(server_name) if server.nil? BrpmAuto.log "This server doesn't exist. Continuing ..." return end environment = get_environment_by_name(environment_name) if environment.nil? BrpmAuto.log "This environment doesn't exist. Continuing ..." return end server_to_update={} server_to_update["environment_ids"] = server["environments"].map{|f| f["id"]} unless server_to_update["environment_ids"].include?(environment["id"]) BrpmAuto.log "This environment is not linked to the server. Continuing ..." return end server_to_update["environment_ids"].delete(environment["id"]) result = brpm_put "v1/servers/#{server["id"]}", { :server => server_to_update} unless result["status"] == "success" raise "Could not unlink environment from server: #{result["error_message"]}" end end |
#update(model_name, model_id, data, options = {}) ⇒ Object
Performs a put on the passed model
use this to update a single record
Attributes
-
model_name
- rpm model [requests, plans, steps, version_tags, etc] -
model_id
- id of a specific item in the model (optional) -
data
- hash of the put data -
options
- hash of options includesincludes all the Rest.rest_call
Returns
-
hash of http response
41 42 43 44 45 46 |
# File 'lib/brpm_rest_client.rb', line 41 def update(model_name, model_id, data, = {}) url = get_brpm_url(model_name, model_id) ["data"] = data result = Rest.put(url, ) result end |
#update_list_from_hash(list) ⇒ Object
1478 1479 1480 1481 1482 1483 1484 1485 1486 |
# File 'lib/brpm_rest_client.rb', line 1478 def update_list_from_hash(list) result = brpm_put "v1/lists/#{list["id"]}", { :list => list } unless result["status"] == "success" raise "Could not update the list: #{result["error_message"]}" end result["response"] end |
#update_list_item_from_hash(list_item) ⇒ Object
1568 1569 1570 1571 1572 1573 1574 1575 1576 |
# File 'lib/brpm_rest_client.rb', line 1568 def update_list_item_from_hash(list_item) result = brpm_put "v1/list_items/#{list_item["id"]}", { :list_item => list_item } unless result["status"] == "success" raise "Could not update the list item: #{result["error_message"]}" end result["response"] end |
#update_request_from_hash(request) ⇒ Object
1096 1097 1098 1099 1100 1101 1102 1103 1104 |
# File 'lib/brpm_rest_client.rb', line 1096 def update_request_from_hash(request) result = brpm_put "v1/requests/#{request["id"]}", { :request => request } unless result["status"] == "success" raise "Could not update the request: #{result["error_message"]}" end result["response"] end |
#update_script_from_hash(script) ⇒ Object
1690 1691 1692 1693 1694 1695 1696 1697 1698 |
# File 'lib/brpm_rest_client.rb', line 1690 def update_script_from_hash(script) result = brpm_put "v1/scripts/#{script["id"]}", { :script => script } unless result["status"] == "success" raise "Could not update the script: #{result["error_message"]}" end result["response"] end |
#update_step_from_hash(step) ⇒ Object
1199 1200 1201 1202 1203 1204 1205 1206 1207 |
# File 'lib/brpm_rest_client.rb', line 1199 def update_step_from_hash(step) result = brpm_put "v1/steps/#{step["id"]}", { :step => step } unless result["status"] == "success" raise "Could not update the step: #{result["error_message"]}" end result["response"] end |
#update_ticket_from_hash(ticket) ⇒ Object
1362 1363 1364 1365 1366 1367 1368 1369 1370 |
# File 'lib/brpm_rest_client.rb', line 1362 def update_ticket_from_hash(ticket) result = brpm_put "v1/tickets/#{ticket["id"]}", { :ticket => ticket } unless result["status"] == "success" raise "Could not update the ticket: #{result["error_message"]}" end result["response"] end |