Module: Ocular::DSL::Fog

Included in:
RunContext, Event::DefinitionProxy
Defined in:
lib/ocular/dsl/fog.rb

Constant Summary collapse

@@__aws_instance =
nil

Instance Method Summary collapse

Instance Method Details

#autoscalingObject



25
26
27
28
29
30
# File 'lib/ocular/dsl/fog.rb', line 25

def autoscaling()
    return ::Fog::AWS::AutoScaling.new({
        :aws_access_key_id => ::Ocular::Settings::get(:aws)[:aws_access_key_id],
        :aws_secret_access_key => ::Ocular::Settings::get(:aws)[:aws_secret_access_key]
        })
end

#awsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ocular/dsl/fog.rb', line 10

def aws()
    if @@__aws_instance
        return @@__aws_instance
    end
    
    @@__aws_instance = ::Fog::Compute.new({
        :provider => 'AWS',
        :aws_access_key_id => ::Ocular::Settings::get(:aws)[:aws_access_key_id],
        :aws_secret_access_key => ::Ocular::Settings::get(:aws)[:aws_secret_access_key]
        })

    return @@__aws_instance
end

#find_server_by_id(id) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/ocular/dsl/fog.rb', line 74

def find_server_by_id(id)
    ret = aws().servers.all("instance-id" => id)
    if ret.length > 1
        raise "Too many matching servers by just one ip #{ip}"
    end
    if ret.length == 0
        return nil
    end
    return ret.first
end

#find_server_by_ip(ip) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/ocular/dsl/fog.rb', line 62

def find_server_by_ip(ip)
    ret = aws().servers.all("private-ip-address" => ip)
    if ret.length > 1
        raise "Too many matching servers by just one ip #{ip}"
    end
    if ret.length == 0
        return nil
    end
    return ret.first
end

#find_servers_in_autoscaling_groups(substring) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ocular/dsl/fog.rb', line 34

def find_servers_in_autoscaling_groups(substring)
    instances = []
    for group in autoscaling.groups
        if group.id.include?(substring)
            for i in group.instances
                instances << aws.servers.get(i.id)
            end
        end
    end

    return instances
end

#get_servers_in_autoscaling_group(group_name) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ocular/dsl/fog.rb', line 48

def get_servers_in_autoscaling_group(group_name)
    instances = []
    for group in autoscaling.groups
        if group.id == group_name
            for i in group.instances
                instances << aws.servers.get(i.id)
            end
        end
    end

    return instances
end