Class: Fog::HP::LB::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/monkey/hp/requests/lb/get_version.rb,
lib/monkey/hp/lb.rb,
lib/monkey/hp/requests/lb/list_limits.rb,
lib/monkey/hp/requests/lb/list_versions.rb,
lib/monkey/hp/requests/lb/list_protocols.rb,
lib/monkey/hp/requests/lb/get_virtual_ips.rb,
lib/monkey/hp/requests/lb/list_algorithms.rb,
lib/monkey/hp/requests/lb/get_load_balancer.rb,
lib/monkey/hp/requests/lb/list_load_balancers.rb,
lib/monkey/hp/requests/lb/create_load_balancer.rb,
lib/monkey/hp/requests/lb/delete_load_balancer.rb,
lib/monkey/hp/requests/lb/update_load_balancer.rb,
lib/monkey/hp/requests/lb/get_load_balancer_node.rb,
lib/monkey/hp/requests/lb/list_load_balancer_nodes.rb,
lib/monkey/hp/requests/lb/create_load_balancer_node.rb,
lib/monkey/hp/requests/lb/delete_load_balancer_node.rb,
lib/monkey/hp/requests/lb/update_load_balancer_node.rb,
lib/monkey/hp/requests/lb/list_load_balancer_virtual_ips.rb

Overview

:nodoc:all

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/monkey/hp/lb.rb', line 86

def initialize(options={})
  # deprecate hp_account_id
  if options[:hp_account_id]
    Fog::Logger.deprecation(":hp_account_id is deprecated, please use :hp_access_key instead.")
    @hp_access_key = options.delete(:hp_account_id)
  end
  @hp_access_key = options[:hp_access_key]
  unless @hp_access_key
    raise ArgumentError.new("Missing required arguments: hp_access_key. :hp_account_id is deprecated, please use :hp_access_key instead.")
  end
end

Class Method Details

.dataObject



74
75
76
77
78
79
80
# File 'lib/monkey/hp/lb.rb', line 74

def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {

    }
  end
end

.resetObject



82
83
84
# File 'lib/monkey/hp/lb.rb', line 82

def self.reset
  @data = nil
end

Instance Method Details

#create_load_balancer(name, nodes, options = {}) ⇒ Object



55
56
57
58
59
60
# File 'lib/monkey/hp/requests/lb/create_load_balancer.rb', line 55

def create_load_balancer(name, nodes, options={})
  response = Excon::Response.new


  response
end

#create_load_balancer_node(load_balancer_id, options = {}) ⇒ Object



48
49
50
51
52
53
# File 'lib/monkey/hp/requests/lb/create_load_balancer_node.rb', line 48

def create_load_balancer_node(load_balancer_id, options={})
  response = Excon::Response.new


  response
end

#dataObject



98
99
100
# File 'lib/monkey/hp/lb.rb', line 98

def data
  self.class.data[@hp_access_key]
end

#delete_load_balancer(instance_id) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/monkey/hp/requests/lb/delete_load_balancer.rb', line 38

def delete_load_balancer(instance_id)
  response = Excon::Response.new
  if image = find_load_balancer(instance_id)
    response.status = 202
  else
    raise Fog::HP::LB::NotFound
  end
  response
end

#delete_load_balancer_node(instance_id, node_id) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/monkey/hp/requests/lb/delete_load_balancer_node.rb', line 39

def delete_load_balancer_node(instance_id, node_id)
  response = Excon::Response.new
  response = Excon::Response.new
  if load_b = get_load_balancer(instance_id).body
    if node = find_node(load_b, node_id)
      response.status = 202
    else
      raise Fog::HP::LB::NotFound
    end
  else
    raise Fog::HP::LB::NotFound
  end
  response
end

#find_load_balancer(record_id) ⇒ Object



82
83
84
# File 'lib/monkey/hp/requests/lb/get_load_balancer.rb', line 82

def find_load_balancer(record_id)
  list_load_balancers.body['loadBalancers'].detect { |_| _['id'] == record_id }
end

#find_node(lb, node_id) ⇒ Object



53
54
55
# File 'lib/monkey/hp/requests/lb/get_load_balancer_node.rb', line 53

def find_node(lb,node_id)
  lb['nodes'].detect { |_| _['id'] == node_id }
end

#get_load_balancer(load_balancer_id) ⇒ Object



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
# File 'lib/monkey/hp/requests/lb/get_load_balancer.rb', line 37

def get_load_balancer(load_balancer_id)
  response = Excon::Response.new
  if lb = find_load_balancer(load_balancer_id)
    response.status = 200
    response.body = {
      "id"         => "#{load_balancer_id}",
      "name"       => "sample-loadbalancer",
      "protocol"   => "HTTP",
      "port"       => "80",
      "algorithm"  => "ROUND_ROBIN",
      "status"     => "ACTIVE",
      "created"    => "2010-11-30T03:23:42Z",
      "updated"    => "2010-11-30T03:23:44Z",
      "virtualIps" => [
        {
          "id"        => "1000",
          "address"   => "192.168.1.1",
          "type"      => "PUBLIC",
          "ipVersion" => "IPV4"
        }
      ],
      "nodes"      => [
        {
          "id"        => "1041",
          "address"   => "10.1.1.1",
          "port"      => "80",
          "condition" => "ENABLED",
          "status"    => "ONLINE"
        },
        {
          "id"        => "1411",
          "address"   => "10.1.1.2",
          "port"      => "80",
          "condition" => "ENABLED",
          "status"    => "ONLINE"
        }
      ],
    }

  else
    raise Fog::HP::LB::NotFound
  end
  response
end

#get_load_balancer_node(load_balancer_id, node_id) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/monkey/hp/requests/lb/get_load_balancer_node.rb', line 37

def get_load_balancer_node(load_balancer_id, node_id)
  response = Excon::Response.new
  if load_b = get_load_balancer(load_balancer_id).body
   if node = find_node(load_b,node_id)
     response.status = 200
     response.body = node
   else
     raise Fog::HP::LB::NotFound
   end
  else
    raise Fog::HP::LB::NotFound
  end

  response
end

#get_version(version_id) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/monkey/hp/requests/lb/get_version.rb', line 51

def get_version(version_id)
  unless version_id
    raise ArgumentError.new('version_id is required')
  end
  response = Excon::Response.new
  if version = list_versions.body['versions'].detect { |_| _['id'] == version_id }
    response.status = 200
    response.body   = {'version' => version}
    response
  else
    raise Fog::HP::LB::NotFound
  end

end

#get_virtual_ips(load_balancer_id) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/monkey/hp/requests/lb/get_virtual_ips.rb', line 37

def get_virtual_ips(load_balancer_id)
  response = Excon::Response.new


  response

end

#list_algorithmsObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/monkey/hp/requests/lb/list_algorithms.rb', line 36

def list_algorithms
  response = Excon::Response.new
  response.status = 200
  response.body = { "algorithms" => [
      { "name" => "ROUND_ROBIN" },
      { "name" => "LEAST_CONNECTIONS"}
    ]
  }

  response

end

#list_limitsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/monkey/hp/requests/lb/list_limits.rb', line 38

def list_limits
  response = Excon::Response.new
  response.status = 200
  response.body = {
    "limits" => {
      "absolute" => {
        "values" => {
          "maxLoadBalancerNameLength" => 128,
          "maxLoadBalancers"          => 20,
          "maxNodesPerLoadBalancer"   => 5,
          "maxVIPsPerLoadBalancer"    => 1
        }
      }
    }
  }

  response
end

#list_load_balancer_nodes(load_balancer_id) ⇒ Object



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
# File 'lib/monkey/hp/requests/lb/list_load_balancer_nodes.rb', line 36

def list_load_balancer_nodes(load_balancer_id)
  response = Excon::Response.new
  if lb = find_load_balancer(load_balancer_id)
    response.status = 200
    response.body   = {
      "nodes" => [
        {
          "id"        => "410",
          "address"   => "10.1.1.1",
          "port"      => "80",
          "condition" => "ENABLED",
          "status"    => "ONLINE"
        },
        {
          "id"        => "236",
          "address"   => "10.1.1.2",
          "port"      => "80",
          "condition" => "ENABLED",
          "status"    => "ONLINE"
        },
        {
          "id"        => "2815",
          "address"   => "10.1.1.3",
          "port"      => "83",
          "condition" => "DISABLED",
          "status"    => "OFFLINE"
        },
      ]
    }
  else
    raise Fog::HP::LB::NotFound
  end

  response

end

#list_load_balancer_virtual_ips(load_balancer_id) ⇒ Object



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
# File 'lib/monkey/hp/requests/lb/list_load_balancer_virtual_ips.rb', line 36

def list_load_balancer_virtual_ips(load_balancer_id)
  response = Excon::Response.new
  if lb = find_load_balancer(load_balancer_id)
    response.status = 200
    response.body   = {
      "virtualIps" => [
        {
          "id"        => "1410",
          "address"   => "101.1.1.1",
          "type"      => "PUBLIC",
          "ipVersion" => "IPV4"
        },
        {
          "id"        => "1236",
          "address"   => "101.1.1.2",
          "type"      => "PUBLIC",
          "ipVersion" => "IPV4"
        },
        {
          "id"        => "2815",
          "address"   => "101.1.1.3",
          "type"      => "PUBLIC",
          "ipVersion" => "IPV4"
        },
      ]
    }
  else
    raise Fog::HP::LB::NotFound
  end

  response

end

#list_load_balancersObject



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
# File 'lib/monkey/hp/requests/lb/list_load_balancers.rb', line 37

def list_load_balancers
  response = Excon::Response.new
  response.status = 200
  response.body = {
      "loadBalancers" => [
        {
          "name"      => "lb-site1",
          "id"        => "71",
          "protocol"  => "HTTP",
          "port"      => "80",
          "algorithm" => "LEAST_CONNECTIONS",
          "status"    => "ACTIVE",
          "created"   => "2010-11-30T03=>23=>42Z",
          "updated"   => "2010-11-30T03=>23=>44Z"
      },
        {
          "name"      => "lb-site2",
          "id"        => "166",
          "protocol"  => "TCP",
          "port"      => "9123",
          "algorithm" => "ROUND_ROBIN",
          "status"    => "ACTIVE",
          "created"   => "2010-11-30T03:23:42Z",
          "updated"   => "2010-11-30T03:23:44Z"
      }
    ]
  }
  response
end

#list_protocolsObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/monkey/hp/requests/lb/list_protocols.rb', line 36

def list_protocols
  response = Excon::Response.new
  response.status = 200
  response.body   = {
    "protocols" => [
      { "name" => "HTTP", "port" => 80 },
      { "name" => "TCP", "port" => 443 }
    ]
  }

  response
end

#list_versionsObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/monkey/hp/requests/lb/list_versions.rb', line 37

def list_versions
  response        = Excon::Response.new
  response.status = 200
  response.body   = {
    "versions" => [
      {"id" => "v1.1", "links" => [{"href" => "http://api-docs.hpcloud.com", "rel" => "self"}], "status" => "CURRENT", "updated" => "2012-12-18T18:30:02.25Z"}
    ]
  }
  response
end

#reset_dataObject



102
103
104
# File 'lib/monkey/hp/lb.rb', line 102

def reset_data
  self.class.data.delete(@hp_access_key)
end

#update_load_balancer(load_balancer_id, options = {}) ⇒ Object



37
38
39
40
41
42
# File 'lib/monkey/hp/requests/lb/update_load_balancer.rb', line 37

def update_load_balancer(load_balancer_id, options={})
  response = Excon::Response.new


  response
end

#update_load_balancer_node(load_balancer_id, node_id, condition) ⇒ Object



41
42
43
44
45
46
# File 'lib/monkey/hp/requests/lb/update_load_balancer_node.rb', line 41

def update_load_balancer_node(load_balancer_id, node_id, condition)
  response = Excon::Response.new


  response
end