Class: CloudControl::Client

Inherits:
Object
  • Object
show all
Includes:
Connection, Params
Defined in:
lib/cloudcontrol/client.rb

Constant Summary collapse

IMAGES =
{suse_ent_64: "d4edfe22-e2f0-11e2-84e5-180373fb68df", ubuntu_14_04: "abef3a94-3361-4ce4-a937-5e587042586a", ubuntu_12_04: "d4ed6d40-e2f0-11e2-84e5-180373fb68df", ubuntu_10_04: "d4edba02-e2f0-11e2-84e5-180373fb68df"}
API_URL =
{na: "https://api-na.dimensiondata.com/caas/2.8", 
eu: "https://api-eu.dimensiondata.com/caas/2.8", 
au: "https://api-au.dimensiondata.com/caas/2.8", 
mea: "https://api-mea.dimensiondata.com/caas/2.8", 
ap: "https://api-ap.dimensiondata.com/caas/2.8"}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Params

#camelize_keys, #symbolize_keys, #underscore_keys, #url_query

Methods included from Connection

#append_query, #build_request, #log_response, #perform_request

Constructor Details

#initialize(api_base, org_id, username, password, colors = true, silent = true) ⇒ Client

Returns a new instance of Client.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cloudcontrol/client.rb', line 27

def initialize(api_base, org_id, username, password, colors = true, silent = true)
  @api_base = api_base
  @org_id       = org_id
  @username     = username
  @password     = password
  @colors = colors
  @silent = silent

  if @colors
    require 'colorize'
  end
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



8
9
10
# File 'lib/cloudcontrol/client.rb', line 8

def 
  @account
end

#api_baseObject (readonly)

include CloudControl::XML



7
8
9
# File 'lib/cloudcontrol/client.rb', line 7

def api_base
  @api_base
end

#colorsObject

FILTERS client.page_size = 10 client.page_number = 1 client.order_by = ‘location,created.DESCENDING’ client.filter_with = %w(NA1 NA2), key: ‘value’



16
17
18
# File 'lib/cloudcontrol/client.rb', line 16

def colors
  @colors
end

#datacenterObject (readonly)

Returns the value of attribute datacenter.



9
10
11
# File 'lib/cloudcontrol/client.rb', line 9

def datacenter
  @datacenter
end

#default_passwordObject (readonly)

Returns the value of attribute default_password.



9
10
11
# File 'lib/cloudcontrol/client.rb', line 9

def default_password
  @default_password
end

#filter_withObject

Returns the value of attribute filter_with.



17
18
19
# File 'lib/cloudcontrol/client.rb', line 17

def filter_with
  @filter_with
end

#imageObject (readonly)

def directory

CloudControl::API::Directory.new(self)

end



44
45
46
# File 'lib/cloudcontrol/client.rb', line 44

def image
  @image
end

#networkObject (readonly)

Returns the value of attribute network.



8
9
10
# File 'lib/cloudcontrol/client.rb', line 8

def network
  @network
end

#order_byObject

Returns the value of attribute order_by.



17
18
19
# File 'lib/cloudcontrol/client.rb', line 17

def order_by
  @order_by
end

#org_idObject (readonly)

include CloudControl::XML



7
8
9
# File 'lib/cloudcontrol/client.rb', line 7

def org_id
  @org_id
end

#page_numberObject

Returns the value of attribute page_number.



17
18
19
# File 'lib/cloudcontrol/client.rb', line 17

def page_number
  @page_number
end

#page_sizeObject

Returns the value of attribute page_size.



17
18
19
# File 'lib/cloudcontrol/client.rb', line 17

def page_size
  @page_size
end

#passwordObject (readonly)

include CloudControl::XML



7
8
9
# File 'lib/cloudcontrol/client.rb', line 7

def password
  @password
end

#reportObject (readonly)

Returns the value of attribute report.



8
9
10
# File 'lib/cloudcontrol/client.rb', line 8

def report
  @report
end

#serverObject (readonly)

Returns the value of attribute server.



8
9
10
# File 'lib/cloudcontrol/client.rb', line 8

def server
  @server
end

#silentObject

FILTERS client.page_size = 10 client.page_number = 1 client.order_by = ‘location,created.DESCENDING’ client.filter_with = %w(NA1 NA2), key: ‘value’



16
17
18
# File 'lib/cloudcontrol/client.rb', line 16

def silent
  @silent
end

#usernameObject (readonly)

include CloudControl::XML



7
8
9
# File 'lib/cloudcontrol/client.rb', line 7

def username
  @username
end

Instance Method Details

#filter_paramsObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cloudcontrol/client.rb', line 68

def filter_params
  params = {}
  params[:page_size] = @page_size if @page_size.present?
  params[:page_number] = @page_number if @page_number.present?
  params[:order_by] = @order_by if @order_by.present?

  if @filter_with.present?
    @filter_with.each do |k, val|
      params[k.to_sym] = val
    end
  end
  params
end

#log(message, color = nil, mode = nil, error = nil) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'lib/cloudcontrol/client.rb', line 86

def log(message, color = nil, mode = nil, error=nil)
  return if (@silent && (not error))
  if @colors
    color = color.to_sym if color
    mode = mode.to_sym if mode
    puts message.colorize(:color => color, :mode => mode)
  else
    puts message
  end
end

#log_error(message, color = nil, mode = nil) ⇒ Object

mode: bold, underscore, default



83
84
85
# File 'lib/cloudcontrol/client.rb', line 83

def log_error(message, color=nil, mode=nil)
	log message, color, mode, true
end

#vipObject



64
65
66
# File 'lib/cloudcontrol/client.rb', line 64

def vip
  CloudControl::API::VIP.new(self)
end