Module: Tama::Apis::InstanceHashBuilder

Included in:
WakameApi, WakameApiTest
Defined in:
lib/apis/wakame.rb

Instance Method Summary collapse

Instance Method Details

#build_instances_hash(w_response, account_id) ⇒ Object

Takes the response from wakame-vdc’s /api/instances and builds a hash similar to right_aws’ describe_instances but changes the layout of IP addresses



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/apis/wakame.rb', line 10

def build_instances_hash(w_response,)
  w_response.first["results"].map { |inst_map|
    # Build the final hash to return
    # This hash is based on right_aws' describe_instances but
    # changes the ip_address format
    {:aws_kernel_id=>"",
    :aws_launch_time=>inst_map["created_at"],
    :tags=>{},
    :aws_reservation_id=>"",
    :aws_owner=>,
    :instance_lifecycle=>"",
    :block_device_mappings=>[{:ebs_volume_id=>"", :ebs_status=>"", :ebs_attach_time=>"", :ebs_delete_on_termination=>false, :device_name=>""}],
    :ami_launch_index=>"",
    :root_device_name=>"",
    :aws_ramdisk_id=>"",
    :aws_availability_zone=>inst_map["host_node"],
    :aws_groups=>inst_map["security_groups"],
    :spot_instance_request_id=>"",
    :ssh_key_name=>inst_map["ssh_key_pair"],
    :virtualization_type=>"",
    :placement_group_name=>"",
    :requester_id=>"",
    :aws_instance_id=>inst_map["id"],
    :aws_product_codes=>[],
    :client_token=>"",
    :private_ip_address=>private_ip(inst_map),
    :architecture=>inst_map["arch"],
    :aws_state_code=>0,
    :aws_image_id=>inst_map["image_id"],
    :root_device_type=>"",
    :ip_address=>ip_list(inst_map),
    :dns_name=>dns_list(inst_map),
    :monitoring_state=>"",
    :aws_instance_type=>inst_map["instance_spec_id"],
    :aws_state=>inst_map["state"],
    :private_dns_name=>private_dns(inst_map),
    :aws_reason=>""
    }
  }
end

#dns_list(inst_map, separator = ",") ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/apis/wakame.rb', line 51

def dns_list(inst_map, separator = ",")
  ip_address = []
  inst_map["network"].each { |network|
    ip_address << "#{network["network_name"]}=#{network["dns_name"]}" unless network["network_name"].nil? || network["dns_name"].nil?
    ip_address << "#{network["nat_network_name"]}=#{network["nat_#{"dns_name"}"]}" unless network["nat_network_name"].nil? || network["nat_dns_name"].nil?
  }
  ip_address.uniq.join(separator)
end

#ip_list(inst_map, separator = ",") ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/apis/wakame.rb', line 60

def ip_list(inst_map, separator = ",")
  ip_address = []
  inst_map["network"].each { |network|
    ip_address << "#{network["network_name"]}=#{network["ipaddr"].first}" unless network["network_name"].nil? || network["ipaddr"].nil?
    ip_address << "#{network["nat_network_name"]}=#{network["nat_ipaddr"].first}" unless network["nat_network_name"].nil? || network["nat_ipaddr"].nil?
  }
  ip_address.uniq.join(separator)
end

#private_dns(inst_map, private_network = self.private_network_name) ⇒ Object



69
70
71
72
73
74
# File 'lib/apis/wakame.rb', line 69

def private_dns(inst_map, private_network = self.private_network_name)
  output = inst_map["network"].find(lambda { {"dns_name" => ""} }) { |network|
    network["network_name"] == private_network
  }
  output["dns_name"]
end

#private_ip(inst_map, private_network = self.private_network_name) ⇒ Object



76
77
78
79
80
81
# File 'lib/apis/wakame.rb', line 76

def private_ip(inst_map, private_network = self.private_network_name)
  output = inst_map["network"].find(lambda { {"ipaddr" => [""]} }) { |network|
    network["network_name"] == private_network
  }
  output["ipaddr"].first
end