Class: Softlayer::Model

Inherits:
Object
  • Object
show all
Extended by:
Operations
Includes:
Operations
Defined in:
lib/softlayer/model.rb,
lib/softlayer/model/mask.rb,
lib/softlayer/model/limit.rb,
lib/softlayer/model/filter.rb,
lib/softlayer/model/response.rb,
lib/softlayer/model/operations.rb

Direct Known Subclasses

Entity, Network::Storage::Iscsi::Os::Type

Defined Under Namespace

Modules: Operations Classes: Filter, Limit, Mask, Response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Operations

extended, filter, included, limit, mask, request_headers

Class Method Details

.allObject



28
29
30
31
32
33
# File 'lib/softlayer/model.rb', line 28

def all
  request = all_request_for(self)
  return nil if request.nil?
  Softlayer::Account.headers = request_headers
  Softlayer::Account.send(request)
end

.all_request_for(klass) ⇒ Object



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/softlayer/model.rb', line 53

def all_request_for(klass)
  klass = klass.to_s
  requests = {
    'Softlayer::Account::AbuseEmail' => :get_abuse_emails,
    'Softlayer::Account::Address' => :get_addresses,
    'Softlayer::Account::Agreement' => :get_billing_agreements,
    'Softlayer::Account::Attribute' => :get_attributes,
    'Softlayer::Account::Contact' => :get_account_contacts,
    'Softlayer::Account::Link' => :get_account_links,
    'Softlayer::Account::Note' => :get_internal_notes,
    'Softlayer::Account::Regional::Registry::Detail' => :get_subnet_registration_details,
    'Softlayer::Account::Shipment' => :get_shipments,
    'Softlayer::Account::Status' => :get_account_status,
    'Softlayer::Billing::Invoice' => :get_invoices,
    'Softlayer::Billing::Item' => :get_all_billing_items,
    'Softlayer::Billing::Order' => :get_orders,
    'Softlayer::Billing::Order::Quote' => :get_quotes,
    'Softlayer::Billing::Payment::Processor' => :get_payment_processors,
    'Softlayer::Catalyst::Enrollment' => :get_catalyst_enrollments,
    'Softlayer::Container::Utility::Message' => :get_auxiliary_notifications,
    'Softlayer::Container::Utility::Microsoft::Windows::UpdateServices::Status' => :get_windows_update_status,
    'Softlayer::Dns::Domain' => :get_domains,
    'Softlayer::Dns::Domain::Registration' => :get_domain_registrations,
    'Softlayer::Dns::Secondary' => :get_secondary_domains,
    'Softlayer::FlexibleCredit::Enrollment' => :get_flexible_credit_enrollments,
    'Softlayer::Hardware' => :get_hardware,
    'Softlayer::Hardware::Component::Model::Generic' => :get_owned_hardware_generic_component_models,
    'Softlayer::Hardware::Component::RemoteManagement::Command::Request' => :get_remote_management_command_requests,
    'Softlayer::Network::Application::Delivery::Controller' => :get_application_delivery_controllers,
    'Softlayer::Network::Application::Delivery::Controller::LoadBalancer::VirtualIpAddress' => :get_adc_load_balancers,
    'Softlayer::Network::Bandwidth::Version1::Allotment' => :get_bandwidth_allotments,
    'Softlayer::Network::ContentDelivery::Account' => :get_cdn_accounts,
    'Softlayer::Network::Gateway' => :get_network_gateways,
    'Softlayer::Network::LoadBalancer::Global::Account' => :get_global_load_balancer_accounts,
    'Softlayer::Network::LoadBalancer::VirtualIpAddress' => :get_load_balancers,
    'Softlayer::Network::Media::Transcode::Account' => :get_transcode_accounts,
    'Softlayer::Network::Message::Delivery' => :get_network_message_delivery_accounts,
    'Softlayer::Network::Message::Queue' => :get_message_queue_accounts,
    'Softlayer::Network::Security::Scanner::Request' => :get_security_scan_requests,
    'Softlayer::Network::Storage::Group' => :get_network_storage_groups,
    'Softlayer::Network::Subnet' => :get_subnets,
    'Softlayer::Network::Subnet::IpAddress' => :get_ip_addresses,
    'Softlayer::Network::Subnet::IpAddress::Global' => :get_global_ip_records,
    'Softlayer::Network::Subnet::Registration' => :get_subnet_registrations,
    'Softlayer::Network::Tunnel::Module::Context' => :get_network_tunnel_contexts,
    'Softlayer::Network::Vlan' => :get_network_vlans,
    'Softlayer::Notification::Subscriber' => :get_notification_subscribers,
    'Softlayer::Product::Item::Price::Account::Restriction' => :get_price_restrictions,
    'Softlayer::Product::Upgrade::Request' => :get_upgrade_requests,
    'Softlayer::Provisioning::Hook' => :get_post_provisioning_hooks,
    'Softlayer::Resource::Group' => :get_resource_groups,
    'Softlayer::Scale::Group' => :get_scale_groups,
    'Softlayer::Security::Certificate' => :get_security_certificates,
    'Softlayer::Security::Certificate::Entry' => :get_valid_security_certificate_entries,
    'Softlayer::Security::Ssh::Key' => :get_ssh_keys,
    'Softlayer::Tag' => :get_tags,
    'Softlayer::Ticket' => :get_tickets,
    'Softlayer::User::Access::Facility::Log' => :get_facility_logs,
    'Softlayer::User::Customer' => :get_users,
    'Softlayer::User::Permission::Group' => :get_permission_groups,
    'Softlayer::User::Permission::Role' => :get_permission_roles,
    'Softlayer::Virtual::Disk::Image' => :get_virtual_disk_images,
    'Softlayer::Virtual::Guest' => :get_virtual_guests,
    'Softlayer::Virtual::Guest::Block::Device::Template::Group' => :get_block_device_template_groups
  }
  return nil unless requests.has_key?(klass)
  requests[klass]
end

.create(message) ⇒ Object



24
25
26
# File 'lib/softlayer/model.rb', line 24

def create(message)
  create_object(message)
end

.find(id) ⇒ Object

user friendly methods



16
17
18
19
20
21
22
# File 'lib/softlayer/model.rb', line 16

def find(id)
  object = self.new.tap do |obj|
    obj.id = id.to_s
  end
  object.headers = request_headers
  object.get_object
end

.parse(hash, return_object, method) ⇒ Object



43
44
45
# File 'lib/softlayer/model.rb', line 43

def parse(hash, return_object, method)
  Response.new(hash).process(return_object)
end

.process_message(message) ⇒ Object



122
123
124
125
126
127
# File 'lib/softlayer/model.rb', line 122

def process_message(message)
  message.each_pair do |k, v|
    message[k] = v.to_softlayer if v.respond_to?(:to_softlayer)
  end
  message
end

.request(method, return_object, message = {}, headers = {}) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/softlayer/model.rb', line 35

def request(method, return_object, message = {}, headers = {})
  headers.merge! request_headers
  message = process_message(message)

  return Softlayer::Mock.request(service_name, method, return_object, message, headers) if Softlayer.mock?
  parse(Softlayer::Client.new(service_name).call(method, message, headers), return_object, method)
end

.service_nameObject



47
48
49
50
51
# File 'lib/softlayer/model.rb', line 47

def service_name
  name = Generator::Converter.to_softlayer_name(self.to_s)
  name = self::SERVICE if defined?(self::SERVICE)
  name
end

Instance Method Details

#init_headersObject

Raises:

  • (Exception)


159
160
161
162
163
164
165
166
# File 'lib/softlayer/model.rb', line 159

def init_headers
  raise Exception.new('You need to set the ID on object') if id.nil?
  {
    "#{self.class.service_name}InitParameters" => {
      "id" => self.id.to_i
    }
  }
end

#request(method, return_object, message = {}) ⇒ Object



130
131
132
133
134
# File 'lib/softlayer/model.rb', line 130

def request(method, return_object, message = {})
  headers = request_headers.merge(init_headers)

  self.class.request(method, return_object, message, headers)
end

#service_nameObject



140
141
142
# File 'lib/softlayer/model.rb', line 140

def service_name
  self.class.service_name
end

#to_hashObject



136
137
138
# File 'lib/softlayer/model.rb', line 136

def to_hash
  (self.class.to_s+"::Representer").constantize.new(self).to_hash
end

#to_softlayerObject



144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/softlayer/model.rb', line 144

def to_softlayer
  hash = "#{self.class}::Representer".constantize.new(self).to_hash
  self.instance_variables.each do |var|
    value = self.instance_variable_get(var)
    unless value.nil?
      if value.respond_to?(:to_softlayer)
        hash[var.to_s.tr('@', '').camelize(:lower)] = value.to_softlayer
      else
        hash[var.to_s.tr('@', '').camelize(:lower)] = value
      end
    end
  end
  hash.camelize_keys!
end