softlayer_api 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,77 @@
1
+ module SoftLayer
2
+ ##
3
+ # Each SoftLayer NetworkStorageAllowedHost instance provides information about
4
+ # a hosts allowed access to a storage product group.
5
+ #
6
+ # This class roughly corresponds to the entity SoftLayer_Network_Storage_Allowed_Host
7
+ # in the API.
8
+ #
9
+ class NetworkStorageAllowedHost < ModelBase
10
+ include ::SoftLayer::DynamicAttribute
11
+
12
+ ##
13
+ # :attr_reader:
14
+ # The name of allowed host, usually an IQN or other identifier
15
+ sl_attr :name
16
+
17
+ ##
18
+ # The NetworkStorageGroup instances assigned to this host
19
+ sl_dynamic_attr :assigned_groups do |resource|
20
+ resource.should_update? do
21
+ #only retrieved once per instance
22
+ @assigned_groups == nil
23
+ end
24
+
25
+ resource.to_update do
26
+ assigned_groups = self.service.object_mask(NetworkStorageGroup.default_object_mask).getAssignedGroups
27
+ assigned_groups.collect { |assigned_group| NetworkStorageGroup.new(softlayer_client, assigned_group) unless assigned_group.empty? }.compact
28
+ end
29
+ end
30
+
31
+ ##
32
+ # The NetworkStorage instances assigned to this host
33
+ sl_dynamic_attr :assigned_volumes do |resource|
34
+ resource.should_update? do
35
+ #only retrieved once per instance
36
+ @assigned_volumes == nil
37
+ end
38
+
39
+ resource.to_update do
40
+ assigned_volumes = self.service.object_mask(NetworkStorage.default_object_mask).getAssignedVolumes
41
+ assigned_volumes.collect { |assigned_volume| NetworkStorage.new(softlayer_client, assigned_volume) unless assigned_volume.empty? }.compact
42
+ end
43
+ end
44
+
45
+ ##
46
+ # The NetworkStorageCredential instance used to access NetworkStorage for this host
47
+ sl_dynamic_attr :credential do |resource|
48
+ resource.should_update? do
49
+ #only retrieved once per instance
50
+ @credential == nil
51
+ end
52
+
53
+ resource.to_update do
54
+ credential = self.service.object_mask(NetworkStorageCredential.default_object_mask).getCredential
55
+ NetworkStorageCredential.new(softlayer_client, credential) unless credential.empty?
56
+ end
57
+ end
58
+
59
+ ##
60
+ # Returns the service for interacting with this network storage through the network API
61
+ #
62
+ def service
63
+ softlayer_client[:Network_Storage_Allowed_Host].object_with_id(self.id)
64
+ end
65
+
66
+ protected
67
+
68
+ def self.default_object_mask
69
+ {
70
+ "mask(SoftLayer_Network_Storage_Allowed_Host)" => [
71
+ 'id',
72
+ 'name'
73
+ ]
74
+ }.to_sl_object_mask
75
+ end
76
+ end
77
+ end #SoftLayer
@@ -0,0 +1,204 @@
1
+ #--
2
+ # Copyright (c) 2014 SoftLayer Technologies, Inc. All rights reserved.
3
+ #
4
+ # For licensing information see the LICENSE.md file in the project root.
5
+ #++
6
+
7
+ module SoftLayer
8
+ ##
9
+ # Each SoftLayer NetworkStorageCredential instance provides information
10
+ # on a username/password credential combination used to access a specific
11
+ # Network Storage.
12
+ #
13
+ # This class roughly corresponds to the entity SoftLayer_Network_Storage_Credential
14
+ # in the API.
15
+ #
16
+ class NetworkStorageCredential < ModelBase
17
+ include ::SoftLayer::DynamicAttribute
18
+
19
+ ##
20
+ # :attr_reader:
21
+ # This is the data that the record was created in the table.
22
+ sl_attr :created, 'createDate'
23
+
24
+ ##
25
+ # :attr_reader:
26
+ # This is the date that the record was last updated in the table.
27
+ sl_attr :modified, 'modifyDate'
28
+
29
+ ##
30
+ # :attr_reader:
31
+ # This is the password associated with the volume.
32
+ sl_attr :password
33
+
34
+ ##
35
+ # :attr_reader:
36
+ # This is the username associated with the volume.
37
+ sl_attr :username
38
+
39
+ ##
40
+ # Returns a description of the Network Storage Credential type
41
+ #
42
+ def description
43
+ self['type']['description']
44
+ end
45
+
46
+ ##
47
+ # Returns the name of the Network Storage Credential type
48
+ #
49
+ def name
50
+ self['type']['name']
51
+ end
52
+
53
+ ##
54
+ # Retrieve a list of network storage credentials from all network storage devices.
55
+ #
56
+ # The options parameter should contain:
57
+ #
58
+ # <b>+:client+</b> - The client used to connect to the API
59
+ #
60
+ # If no client is given, then the routine will try to use Client.default_client
61
+ # If no client can be found the routine will raise an error.
62
+ #
63
+ # You may filter the list returned by adding options:
64
+ # * <b>+:datacenter+</b> (string) - Include network storage account passwords associated with servers matching this datacenter
65
+ # * <b>+:domain+</b> (string) - Include network storage account passwords associated with servers matching this domain
66
+ # * <b>+:hostname+</b> (string) - Include network storage account passwords associated with servers matching this hostname
67
+ # * <b>+:network_storage_server_type+</b> (string) - Include network storage account passwords associated with services of this server type
68
+ # * <b>+:network_storage_type+</b> (string) - Include network storage account passwords from devices of this storage type
69
+ # * <b>+:service+</b> (string) - Include network storage account passwords from devices with this service fqdn
70
+ # * <b>+:tags+</b> (Array) - Include network storage account passwords associated with servers matching these tags
71
+ # * <b>+:username+</b> (string) - Include network storage account passwords with this username only
72
+ #
73
+ def self.find_network_storage_credentials(options_hash = {})
74
+ softlayer_client = options_hash[:client] || Client.default_client
75
+ raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
76
+
77
+ if(options_hash.has_key? :network_storage_object_filter)
78
+ network_storage_object_filter = options_hash[:network_storage_object_filter]
79
+ raise "Expected an instance of SoftLayer::ObjectFilter" unless network_storage_object_filter.kind_of?(SoftLayer::ObjectFilter)
80
+ else
81
+ network_storage_object_filter = ObjectFilter.new()
82
+ end
83
+
84
+ if(options_hash.has_key? :network_storage_credential_object_filter)
85
+ network_storage_credential_object_filter = options_hash[:network_storage_credential_object_filter]
86
+ raise "Expected an instance of SoftLayer::ObjectFilter" unless network_storage_credential_object_filter.kind_of?(SoftLayer::ObjectFilter)
87
+ else
88
+ network_storage_credential_object_filter = ObjectFilter.new()
89
+ end
90
+
91
+ if options_hash.has_key?(:network_storage_server_type) && ! [ :hardware, :virtual_server ].include?(options_hash[:network_storage_server_type])
92
+ raise "Expected one of :hardware or :virtual_server for :network_storage_server_type option in #{__method__}"
93
+ end
94
+
95
+ filter_label = {
96
+ :evault => "evaultNetworkStorage",
97
+ :hardware => "hardware",
98
+ :hub => "hubNetworkStorage",
99
+ :iscsi => "iscsiNetworkStorage",
100
+ :lockbox => "lockboxNetworkStorage",
101
+ :nas => "nasNetworkStorage",
102
+ :network_storage => "networkStorage",
103
+ :virtual_server => "virtualGuest"
104
+ }
105
+
106
+ option_to_filter_path = {
107
+ :datacenter => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.datacenter.name' ].join },
108
+ :domain => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.domain' ].join },
109
+ :hostname => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.hostname' ].join },
110
+ :service => lambda { |storage_type| return [ filter_label[storage_type], '.serviceResource.backendIpAddress' ].join },
111
+ :tags => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.tagReferences.tag.name' ].join },
112
+ :network_storage_credential => {
113
+ :username => "credentials.username"
114
+ }
115
+ }
116
+
117
+ if options_hash[:network_storage_type]
118
+ unless filter_label.select{|label,filter| filter.end_with?("Storage")}.keys.include?(options_hash[:network_storage_type])
119
+ raise "Expected :evault, :hub, :iscsi, :lockbox, :nas or :network_storage for option :network_storage_type in #{__method__}"
120
+ end
121
+ end
122
+
123
+ network_storage_type = options_hash[:network_storage_type] || :network_storage
124
+
125
+ if options_hash[:service]
126
+ network_storage_object_filter.modify do |filter|
127
+ filter.accept(option_to_filter_path[:service].call(network_storage_type)).when_it is(options_hash[:service])
128
+ end
129
+ end
130
+
131
+ if options_hash[:network_storage_server_type]
132
+ [ :datacenter, :domain, :hostname ].each do |option|
133
+ if options_hash[option]
134
+ network_storage_object_filter.modify do |filter|
135
+ filter.accept(option_to_filter_path[option].call(network_storage_type, options_hash[:network_storage_server_type])).when_it is(options_hash[option])
136
+ end
137
+ end
138
+ end
139
+
140
+ if options_hash[:tags]
141
+ network_storage_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags].call(network_storage_type, options_hash[:network_storage_server_type]),
142
+ {
143
+ 'operation' => 'in',
144
+ 'options' => [{
145
+ 'name' => 'data',
146
+ 'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
147
+ }]
148
+ })
149
+ end
150
+ end
151
+
152
+ option_to_filter_path[:network_storage_credential].each do |option, filter_path|
153
+ network_storage_credential_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option]
154
+ end
155
+
156
+ account_service = softlayer_client[:Account]
157
+ account_service = account_service.object_filter(network_storage_object_filter) unless network_storage_object_filter.empty?
158
+ account_service = account_service.object_mask("mask[id]")
159
+
160
+ case options_hash[:network_storage_type]
161
+ when :evault
162
+ network_storage_data = account_service.getEvaultNetworkStorage
163
+ when :hub
164
+ network_storage_data = account_service.getHubNetworkStorage
165
+ when :iscsi
166
+ network_storage_data = account_service.getIscsiNetworkStorage
167
+ when :lockbox
168
+ network_storage_data = account_service.getLockboxNetworkStorage
169
+ when :nas
170
+ network_storage_data = account_service.getNasNetworkStorage
171
+ when :network_storage, nil
172
+ network_storage_data = account_service.getNetworkStorage
173
+ end
174
+
175
+ network_storage_credentials = network_storage_data.collect do |network_storage|
176
+ network_storage_service = softlayer_client[:Network_Storage].object_with_id(network_storage['id'])
177
+ network_storage_service = network_storage_service.object_filter(network_storage_credential_object_filter) unless network_storage_credential_object_filter.empty?
178
+ network_storage_service = network_storage_service.object_mask(NetworkStorageCredential.default_object_mask)
179
+ network_storage_service = network_storage_service.object_mask(options_hash[:network_storage_credential_object_mask]) if options_hash[:network_storage_credential_object_mask]
180
+
181
+ network_storage_credentials_data = network_storage_service.getCredentials
182
+ network_storage_credentials_data.map { |credential| NetworkStorageCredential.new(softlayer_client, credential) unless credential.empty? }.compact
183
+ end
184
+
185
+ network_storage_credentials.flatten
186
+ end
187
+
188
+ protected
189
+
190
+ def self.default_object_mask
191
+ {
192
+ "mask(SoftLayer_Network_Storage_Credential)" => [
193
+ 'createDate',
194
+ 'id',
195
+ 'modifyDate',
196
+ 'password',
197
+ 'type.description',
198
+ 'type.name',
199
+ 'username'
200
+ ]
201
+ }.to_sl_object_mask
202
+ end
203
+ end
204
+ end #SoftLayer
@@ -0,0 +1,159 @@
1
+ module SoftLayer
2
+ ##
3
+ # Each SoftLayer NetworkStorageGroup instance provides information about
4
+ # a storage product group and hosts allowed access.
5
+ #
6
+ # This class roughly corresponds to the entity SoftLayer_Network_Storage_Group
7
+ # in the API.
8
+ #
9
+ class NetworkStorageGroup < ModelBase
10
+ include ::SoftLayer::DynamicAttribute
11
+
12
+ ##
13
+ # :attr_reader:
14
+ # The friendly name of this group
15
+ sl_attr :alias
16
+
17
+ ##
18
+ # :attr_reader:
19
+ # The date this group was created.
20
+ sl_attr :created, 'createDate'
21
+
22
+ ##
23
+ # :attr_reader:
24
+ # The date this group was modified.
25
+ sl_attr :modified, 'modifyDate'
26
+
27
+ ##
28
+ # The SoftLayer_Account which owns this group.
29
+ sl_dynamic_attr :account do |resource|
30
+ resource.should_update? do
31
+ #only retrieved once per instance
32
+ @account == nil
33
+ end
34
+
35
+ resource.to_update do
36
+ account = self.service.getAccount
37
+ Account.new(softlayer_client, account) unless account.empty?
38
+ end
39
+ end
40
+
41
+ ##
42
+ # The allowed hosts list for this group.
43
+ sl_dynamic_attr :allowed_hosts do |resource|
44
+ resource.should_update? do
45
+ #only retrieved once per instance
46
+ @allowed_hosts == nil
47
+ end
48
+
49
+ resource.to_update do
50
+ allowed_hosts = self.service.object_mask(NetworkStorageAllowedHost.default_object_mask).getAllowedHosts
51
+ allowed_hosts.collect { |allowed_host| NetworkStorageAllowedHost.new(softlayer_client, allowed_host) unless allowed_host.empty? }.compact
52
+ end
53
+ end
54
+
55
+ ##
56
+ # The network storage volumes this group is attached to.
57
+ sl_dynamic_attr :attached_volumes do |resource|
58
+ resource.should_update? do
59
+ #only retrieved once per instance
60
+ @attached_volumes == nil
61
+ end
62
+
63
+ resource.to_update do
64
+ attached_volumes = self.service.object_mask(NetworkStorage.default_object_mask).getAttachedVolumes
65
+ attached_volumes.collect { |attached_volume| NetworkStorage.new(softlayer_client, attached_volume) unless attached_volume.empty? }.compact
66
+ end
67
+ end
68
+
69
+ ##
70
+ # The IP address for for SoftLayer_Network_Storage_Allowed_Host objects within this group.
71
+ sl_dynamic_attr :ip_address do |resource|
72
+ resource.should_update? do
73
+ #only retrieved once per instance
74
+ @ip_address == nil
75
+ end
76
+
77
+ resource.to_update do
78
+ network_connection_details = self.service.getNetworkConnectionDetails
79
+ network_connection_details["ipAddress"] unless network_connection_details.empty?
80
+ end
81
+ end
82
+
83
+ ##
84
+ # The description of theSoftLayer_Network_Storage_OS_Type Operating System designation that this group was created for.
85
+ sl_dynamic_attr :os_description do |resource|
86
+ resource.should_update? do
87
+ #only retrieved once per instance
88
+ @os_description == nil
89
+ end
90
+
91
+ resource.to_update do
92
+ os_type = self.service.getOsType
93
+ os_type["description"] unless os_type.empty?
94
+ end
95
+ end
96
+
97
+ ##
98
+ # The name of theSoftLayer_Network_Storage_OS_Type Operating System designation that this group was created for.
99
+ sl_dynamic_attr :os_name do |resource|
100
+ resource.should_update? do
101
+ #only retrieved once per instance
102
+ @os_name == nil
103
+ end
104
+
105
+ resource.to_update do
106
+ os_type = self.service.getOsType
107
+ os_type["name"] unless os_type.empty?
108
+ end
109
+ end
110
+
111
+ ##
112
+ # The network resource this group is created on.
113
+ sl_dynamic_attr :service_resource do |resource|
114
+ resource.should_update? do
115
+ #only retrieved once per instance
116
+ @service_resource == nil
117
+ end
118
+
119
+ resource.to_update do
120
+ service_resource = self.service.object_mask(NetworkService.default_object_mask).getServiceResource
121
+ NetworkService.new(softlayer_client, service_resource) unless service_resource.empty?
122
+ end
123
+ end
124
+
125
+ ##
126
+ # The name of the SoftLayer_Network_Storage_Group_Type which describes this group.
127
+ sl_dynamic_attr :type do |resource|
128
+ resource.should_update? do
129
+ #only retrieved once per instance
130
+ @type == nil
131
+ end
132
+
133
+ resource.to_update do
134
+ group_type = self.service.getGroupType
135
+ group_type["name"]
136
+ end
137
+ end
138
+
139
+ ##
140
+ # Returns the service for interacting with this network storage through the network API
141
+ #
142
+ def service
143
+ softlayer_client[:Network_Storage_Group].object_with_id(self.id)
144
+ end
145
+
146
+ protected
147
+
148
+ def self.default_object_mask
149
+ {
150
+ "mask(SoftLayer_Network_Storage_Group)" => [
151
+ 'alias',
152
+ 'createDate',
153
+ 'id',
154
+ 'modifyDate'
155
+ ]
156
+ }.to_sl_object_mask
157
+ end
158
+ end
159
+ end #SoftLayer
@@ -10,21 +10,26 @@ module SoftLayer
10
10
  # the product order is the price_id, the rest of the information is provided
11
11
  # to make the object friendly to humans who may be searching for the
12
12
  # meaning of a given price_id.
13
- class ProductConfigurationOption < Struct.new(:price_id, :description, :capacity, :units, :setupFee, :laborFee,
14
- :oneTimeFee, :recurringFee, :hourlyRecurringFee)
13
+ class ProductConfigurationOption < Struct.new(:capacity, :capacityRestrictionMaximum, :capacityRestrictionMinimum,
14
+ :capacityRestrictionType, :description, :hourlyRecurringFee, :laborFee, :oneTimeFee, :price_id, :recurringFee,
15
+ :requiredCoreCount, :setupFee, :units)
15
16
  # Is it evil, or just incongruous to give methods to a struct?
16
17
 
17
18
  def initialize(package_item_data, price_item_data)
19
+ self.capacity = package_item_data['capacity']
18
20
  self.description = package_item_data['description']
19
- self.capacity = package_item_data['capacity']
20
- self.units = package_item_data['units']
21
+ self.units = package_item_data['units']
21
22
 
22
- self.price_id = price_item_data['id']
23
- self.setupFee = price_item_data['setupFee'] ? price_item_data['setupFee'].to_f : 0.0
24
- self.laborFee = price_item_data['laborFee'] ? price_item_data['laborFee'].to_f : 0.0
25
- self.oneTimeFee = price_item_data['oneTimeFee'] ? price_item_data['oneTimeFee'].to_f : 0.0
26
- self.recurringFee = price_item_data['recurringFee'] ? price_item_data['recurringFee'].to_f : 0.0
27
- self.hourlyRecurringFee = price_item_data['hourlyRecurringFee'] ? price_item_data['hourlyRecurringFee'].to_f : 0.0
23
+ self.capacityRestrictionMaximum = price_item_data['capacityRestrictionMaximum'] ? price_item_data['capacityRestrictionMaximum'] : nil
24
+ self.capacityRestrictionMinimum = price_item_data['capacityRestrictionMinimum'] ? price_item_data['capacityRestrictionMinimum'] : nil
25
+ self.capacityRestrictionType = price_item_data['capacityRestrictionType'] ? price_item_data['capacityRestrictionType'] : nil
26
+ self.hourlyRecurringFee = price_item_data['hourlyRecurringFee'] ? price_item_data['hourlyRecurringFee'].to_f : 0.0
27
+ self.laborFee = price_item_data['laborFee'] ? price_item_data['laborFee'].to_f : 0.0
28
+ self.oneTimeFee = price_item_data['oneTimeFee'] ? price_item_data['oneTimeFee'].to_f : 0.0
29
+ self.price_id = price_item_data['id']
30
+ self.recurringFee = price_item_data['recurringFee'] ? price_item_data['recurringFee'].to_f : 0.0
31
+ self.requiredCoreCount = price_item_data['requiredCoreCount'] ? price_item_data['requiredCoreCount'] : nil
32
+ self.setupFee = price_item_data['setupFee'] ? price_item_data['setupFee'].to_f : 0.0
28
33
  end
29
34
 
30
35
  # returns true if the configurtion option has no fees associated with it.
@@ -121,4 +126,4 @@ module SoftLayer
121
126
  return @is_required
122
127
  end
123
128
  end
124
- end
129
+ end