Module: InfraResources

Extended by:
Discover::Infrastructure, Util::Logging
Defined in:
lib/infra_resources.rb

Constant Summary

Constants included from Util::Logging

Util::Logging::SEV_LABEL, Util::Logging::TRACE

Class Method Summary collapse

Methods included from Util::Logging

logger, logger=

Methods included from Discover::Infrastructure

fetch_cluster_details, fetch_compartment_list, fetch_free_text_details, fetch_load_balancer_details, fetch_node_pool_lists, fetch_subnet_list_response, fetch_vcn_response

Methods included from Util::OCIClients

create_clients, get_auth_config_object, get_clients, initialize_auth_config, initialize_ce_client, initialize_id_client, initialize_la_client, initialize_lb_client, initialize_rs_client, initialize_vnc_client, set_auth_config_object, set_clients

Class Method Details

.get_infra_resources(auth_object, cluster_id) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/infra_resources.rb', line 26

def get_infra_resources(auth_object, cluster_id)
  # Fetch cluster details using cluster OCID provided as argument during program run
  logger.debug('Fetching cluster details.')
  ce_response = Discover::Infrastructure.fetch_cluster_details(auth_object, cluster_id)
  cluster_entity_payload = Dto::Infra::ClusterEntityPayload.new(ce_response.name, ce_response.id)

  # Fetch VCN associated with cluster
  logger.debug('Fetching virtual cloud network details.')
  vcn_response = Discover::Infrastructure.fetch_vcn_response(auth_object, ce_response.vcn_id)
  vcn_entity_payload = Dto::Infra::VcnEntityPayload.new(vcn_response.display_name, vcn_response.id)

  # Fetch subnets falling under same compartment as that of cluster using VCN OCID
  logger.debug('Fetching subnet details.')
  subnet_response = Discover::Infrastructure.fetch_subnet_list_response(auth_object, ce_response.compartment_id, vcn_response.id)

  # Loop subnet response to get individual subnets.
  subnet_entity_payload = []
  subnet_response.each do |subnet|
    next if subnet.nil?

    subnet_entity_payload.push(Dto::Infra::SubnetEntityPayload.new(subnet.display_name, subnet.id))
  end

  # Use resource search query to fetch load balancers associated with cluster OCID
  logger.debug('Fetching load balancers associated with cluster.')
  free_text_response = Discover::Infrastructure.fetch_free_text_details(auth_object, ce_response.id)

  load_balancer_entity_payload = nil
  free_text_response.items.each do |item|
    next if item.nil?

    next unless item.resource_type == 'LoadBalancer'

    logger.info('Fetching load balancers details.')
    lb_response = Discover::Infrastructure.fetch_load_balancer_details(auth_object, item.identifier)
    lb_compartment_id = lb_response.defined_tags['Oracle-Tags']['CreatedBy']
    if lb_compartment_id == ce_response.id
      load_balancer_entity_payload = Dto::Infra::LoadBalancerEntityPayload.new(lb_response.display_name, lb_compartment_id)
    end
  end

  # Iterate through all the compartments (starting from root tenancy level) and fetch node pools
  # associated with the cluster OCID
  node_pool_entity_payload = []
  compartment_list_response = Discover::Infrastructure.fetch_compartment_list(auth_object, auth_object[:oci_config].tenancy)
  compartment_list_response.each do |compartment|
    next if compartment.nil?

    node_pool_response = Discover::Infrastructure.fetch_node_pool_lists(auth_object, compartment.id, ce_response.id)

    node_pool_response.each do |node_pool|
      next if node_pool.nil?

      node_pool_entity_payload.push(Dto::Infra::NodePoolEntityPayload.new(node_pool.node_image_name, node_pool.node_image_id, node_pool.compartment_id))
    end
  end

  Dto::InfraObjectsPayLoad.new(
    cluster_entity_payload, vcn_entity_payload, subnet_entity_payload,
    load_balancer_entity_payload, node_pool_entity_payload
  )
rescue StandardError => e
  logger.error("Error in getting infrastructure resources: #{e}")
  raise
end