Module: CloudstackClient::ServiceOffering

Defined in:
lib/cloudstack_client/commands/service_offering.rb

Instance Method Summary collapse

Instance Method Details

#create_offering(args) ⇒ Object

Create a service offering.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cloudstack_client/commands/service_offering.rb', line 49

def create_offering(args)
  params = {
      'command' => 'createServiceOffering',
      'name' => args[:name],
      'cpunumber' => args[:cpunumber],
      'cpuspeed' => args[:cpuspeed],
      'displaytext' => args[:displaytext],
      'memory' => args[:memory]
  }

  if args['domain']
    params['domainid'] = list_domains(args['domain']).first["id"]
  end

  params['tags'] = args[:tags] if args[:tags]
  params['offerha'] = 'true' if args[:ha]

  json = send_request(params)
  json['serviceoffering'].first
end

#delete_offering(id) ⇒ Object

Delete a service offering.



73
74
75
76
77
78
79
80
81
# File 'lib/cloudstack_client/commands/service_offering.rb', line 73

def delete_offering(id)
  params = {
      'command' => 'deleteServiceOffering',
      'id' => id
  }

  json = send_request(params)
  json['success']
end

#get_service_offering(name) ⇒ Object

Finds the service offering with the specified name.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cloudstack_client/commands/service_offering.rb', line 8

def get_service_offering(name)

  # TODO: use name parameter
  # listServiceOfferings in CloudStack 2.2 doesn't seem to work
  # when the name parameter is specified. When this is fixed,
  # the name parameter should be added to the request.
  params = {
      'command' => 'listServiceOfferings'
  }
  json = send_request(params)

  services = json['serviceoffering']
  return nil unless services

  services.each { |s|
    if s['name'] == name then
      return s
    end
  }
  nil
end

#list_service_offerings(domain = nil) ⇒ Object

Lists all available service offerings.



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cloudstack_client/commands/service_offering.rb', line 33

def list_service_offerings(domain = nil)
  params = {
      'command' => 'listServiceOfferings'
  }

  if domain
    params['domainid'] = list_domains(domain).first["id"]
  end

  json = send_request(params)
  json['serviceoffering'] || []
end

#update_offering(args) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cloudstack_client/commands/service_offering.rb', line 83

def update_offering(args)
  params = {
      'command' => 'updateServiceOffering',
      'id' => args['id']
  }
  params['name'] = args['name'] if args['name']
  params['displaytext'] = args['displaytext'] if args['displaytext']
  params['sortkey'] = args['sortkey'] if args['sortkey']

  json = send_request(params)
  json['serviceoffering']
end