Module: Fog::HP

Extended by:
Provider
Defined in:
lib/fog/hp/lb.rb,
lib/fog/hp/dns.rb,
lib/fog/hp/core.rb,
lib/fog/hp/network.rb,
lib/fog/hp/block_storage.rb,
lib/fog/hp/models/lb/node.rb,
lib/fog/hp/models/lb/nodes.rb,
lib/fog/hp/block_storage_v2.rb,
lib/fog/hp/models/dns/domain.rb,
lib/fog/hp/models/dns/record.rb,
lib/fog/hp/models/dns/domains.rb,
lib/fog/hp/models/dns/records.rb,
lib/fog/hp/models/lb/protocol.rb,
lib/fog/hp/models/lb/algorithm.rb,
lib/fog/hp/models/network/port.rb,
lib/fog/hp/models/lb/protocols.rb,
lib/fog/hp/models/lb/algorithms.rb,
lib/fog/hp/models/network/ports.rb,
lib/fog/hp/models/lb/virtual_ip.rb,
lib/fog/hp/models/network/subnet.rb,
lib/fog/hp/models/network/router.rb,
lib/fog/hp/models/lb/virtual_ips.rb,
lib/fog/hp/models/network/network.rb,
lib/fog/hp/models/network/routers.rb,
lib/fog/hp/models/network/subnets.rb,
lib/fog/hp/models/network/networks.rb,
lib/fog/hp/models/lb/load_balancer.rb,
lib/fog/hp/requests/lb/list_limits.rb,
lib/fog/hp/requests/dns/get_record.rb,
lib/fog/hp/requests/dns/get_domain.rb,
lib/fog/hp/models/lb/load_balancers.rb,
lib/fog/hp/requests/network/get_port.rb,
lib/fog/hp/requests/lb/list_versions.rb,
lib/fog/hp/requests/dns/list_domains.rb,
lib/fog/hp/requests/dns/update_domain.rb,
lib/fog/hp/requests/dns/delete_record.rb,
lib/fog/hp/requests/dns/delete_domain.rb,
lib/fog/hp/requests/dns/create_record.rb,
lib/fog/hp/requests/dns/update_record.rb,
lib/fog/hp/models/network/floating_ip.rb,
lib/fog/hp/requests/dns/create_domain.rb,
lib/fog/hp/requests/lb/list_protocols.rb,
lib/fog/hp/requests/lb/list_algorithms.rb,
lib/fog/hp/models/network/floating_ips.rb,
lib/fog/hp/models/block_storage/volume.rb,
lib/fog/hp/requests/network/get_router.rb,
lib/fog/hp/requests/network/get_subnet.rb,
lib/fog/hp/requests/network/list_ports.rb,
lib/fog/hp/requests/network/update_port.rb,
lib/fog/hp/requests/network/delete_port.rb,
lib/fog/hp/requests/network/create_port.rb,
lib/fog/hp/requests/network/get_network.rb,
lib/fog/hp/models/block_storage/volumes.rb,
lib/fog/hp/models/block_storage/snapshot.rb,
lib/fog/hp/models/network/security_group.rb,
lib/fog/hp/requests/lb/get_load_balancer.rb,
lib/fog/hp/requests/network/list_subnets.rb,
lib/fog/hp/requests/network/list_routers.rb,
lib/fog/hp/requests/network/list_networks.rb,
lib/fog/hp/requests/network/create_router.rb,
lib/fog/hp/models/block_storage/snapshots.rb,
lib/fog/hp/requests/network/create_subnet.rb,
lib/fog/hp/requests/network/delete_router.rb,
lib/fog/hp/models/network/security_groups.rb,
lib/fog/hp/requests/network/update_subnet.rb,
lib/fog/hp/requests/network/update_router.rb,
lib/fog/hp/requests/network/delete_subnet.rb,
lib/fog/hp/models/block_storage_v2/volume.rb,
lib/fog/hp/models/block_storage_v2/volumes.rb,
lib/fog/hp/requests/lb/list_load_balancers.rb,
lib/fog/hp/requests/network/delete_network.rb,
lib/fog/hp/requests/network/create_network.rb,
lib/fog/hp/requests/network/update_network.rb,
lib/fog/hp/requests/network/get_floating_ip.rb,
lib/fog/hp/requests/lb/update_load_balancer.rb,
lib/fog/hp/requests/lb/create_load_balancer.rb,
lib/fog/hp/requests/lb/delete_load_balancer.rb,
lib/fog/hp/models/block_storage_v2/snapshot.rb,
lib/fog/hp/models/block_storage_v2/snapshots.rb,
lib/fog/hp/requests/network/list_floating_ips.rb,
lib/fog/hp/requests/lb/get_load_balancer_node.rb,
lib/fog/hp/models/network/security_group_rule.rb,
lib/fog/hp/requests/block_storage/list_volumes.rb,
lib/fog/hp/requests/network/delete_floating_ip.rb,
lib/fog/hp/requests/network/create_floating_ip.rb,
lib/fog/hp/requests/network/get_security_group.rb,
lib/fog/hp/models/network/security_group_rules.rb,
lib/fog/hp/requests/block_storage/create_volume.rb,
lib/fog/hp/requests/block_storage/delete_volume.rb,
lib/fog/hp/requests/lb/list_load_balancer_nodes.rb,
lib/fog/hp/requests/lb/create_load_balancer_node.rb,
lib/fog/hp/requests/lb/delete_load_balancer_node.rb,
lib/fog/hp/requests/lb/update_load_balancer_node.rb,
lib/fog/hp/models/block_storage/bootable_volumes.rb,
lib/fog/hp/requests/dns/list_records_in_a_domain.rb,
lib/fog/hp/requests/network/add_router_interface.rb,
lib/fog/hp/requests/network/list_security_groups.rb,
lib/fog/hp/models/block_storage_v2/volume_backup.rb,
lib/fog/hp/requests/block_storage/list_snapshots.rb,
lib/fog/hp/requests/block_storage/create_snapshot.rb,
lib/fog/hp/requests/block_storage/delete_snapshot.rb,
lib/fog/hp/models/block_storage_v2/volume_backups.rb,
lib/fog/hp/requests/network/delete_security_group.rb,
lib/fog/hp/requests/network/create_security_group.rb,
lib/fog/hp/requests/network/associate_floating_ip.rb,
lib/fog/hp/requests/block_storage_v2/list_volumes.rb,
lib/fog/hp/requests/block_storage_v2/delete_volume.rb,
lib/fog/hp/requests/block_storage_v2/update_volume.rb,
lib/fog/hp/requests/block_storage_v2/create_volume.rb,
lib/fog/hp/requests/dns/get_servers_hosting_domain.rb,
lib/fog/hp/requests/network/remove_router_interface.rb,
lib/fog/hp/requests/network/get_security_group_rule.rb,
lib/fog/hp/requests/block_storage_v2/list_snapshots.rb,
lib/fog/hp/requests/block_storage_v2/delete_snapshot.rb,
lib/fog/hp/requests/block_storage_v2/create_snapshot.rb,
lib/fog/hp/requests/block_storage_v2/update_snapshot.rb,
lib/fog/hp/requests/block_storage/get_volume_details.rb,
lib/fog/hp/requests/network/disassociate_floating_ip.rb,
lib/fog/hp/requests/lb/list_load_balancer_virtual_ips.rb,
lib/fog/hp/requests/network/list_security_group_rules.rb,
lib/fog/hp/requests/network/create_security_group_rule.rb,
lib/fog/hp/requests/network/delete_security_group_rule.rb,
lib/fog/hp/requests/block_storage/get_snapshot_details.rb,
lib/fog/hp/requests/block_storage/list_bootable_volumes.rb,
lib/fog/hp/requests/block_storage_v2/get_volume_details.rb,
lib/fog/hp/requests/block_storage_v2/list_volume_backups.rb,
lib/fog/hp/requests/block_storage_v2/list_volumes_detail.rb,
lib/fog/hp/requests/block_storage_v2/get_snapshot_details.rb,
lib/fog/hp/requests/block_storage_v2/create_volume_backup.rb,
lib/fog/hp/requests/block_storage_v2/delete_volume_backup.rb,
lib/fog/hp/requests/block_storage_v2/restore_volume_backup.rb,
lib/fog/hp/requests/block_storage_v2/list_snapshots_detail.rb,
lib/fog/hp/requests/block_storage/get_bootable_volume_details.rb,
lib/fog/hp/requests/block_storage_v2/get_volume_backup_details.rb,
lib/fog/hp/requests/block_storage_v2/list_volume_backups_detail.rb

Defined Under Namespace

Modules: Errors Classes: BlockStorage, BlockStorageV2, DNS, LB, Mock, Network

Constant Summary collapse

VERSION =
'0.0.22'

Class Method Summary collapse

Class Method Details

.authenticate_v1(options, connection_options = {}) ⇒ Object

legacy swauth 1.0/1.1 style authentication



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
# File 'lib/fog/hp/core.rb', line 70

def self.authenticate_v1(options, connection_options = {})
  hp_auth_uri = options[:hp_auth_uri] || "https://region-a.geo-1.objects.hpcloudsvc.com/auth/v1.0/"
  endpoint = URI.parse(hp_auth_uri)
  @scheme = endpoint.scheme || "http"
  @host = endpoint.host || "region-a.geo-1.objects.hpcloudsvc.com"
  @port = endpoint.port.to_s || "80"
  if (endpoint.path)
    @auth_path = endpoint.path.slice(1, endpoint.path.length)  # remove the leading slash
  else
    @auth_path = "auth/v1.0"
  end
  service_url = "#{@scheme}://#{@host}:#{@port}"
  # Set the User-Agent
  @user_agent = options[:user_agent]
  set_user_agent_header(connection_options, "fog/#{Fog::VERSION}", @user_agent)
  connection = Fog::XML::Connection.new(service_url, false, connection_options)
  @hp_access_key = options[:hp_access_key]
  @hp_secret_key  = options[:hp_secret_key]
  response = connection.request({
    :expects  => [200, 204],
    :headers  => {
      'X-Auth-Key'  => @hp_secret_key,
      'X-Auth-User' => @hp_access_key
    },
    :method   => 'GET',
    :path     => @auth_path
  })
  response.headers.reject do |key, value|
    !['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
  end

  return {
    :auth_token => response.headers['X-Auth-Token'],
    :endpoint_url => nil,
    :cdn_endpoint_url => response.headers['X-Storage-Url']
  }
end

.authenticate_v2(options, connection_options = {}) ⇒ Object

keystone based control services style authentication



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/fog/hp/core.rb', line 116

def self.authenticate_v2(options, connection_options = {})
  unless options[:credentials].nil?
    expires = true
    begin
      expire = DateTime.parse(options[:credentials][:expires])
      expires = false if expire > DateTime.now
    rescue
    end
    if expires
      options = options.clone
      options.delete(:credentials)
    else
      service_catalog = options[:credentials][:service_catalog]
      type  = options[:hp_service_type]
      zone   = options[:hp_avl_zone]
      begin
        creds = options[:credentials].clone
        creds[:endpoint_url] = get_endpoint_url(service_catalog, type, zone)
        begin
          creds[:cdn_endpoint_url] = get_endpoint_url(service_catalog, "CDN", zone)
        rescue
        end
        return creds
      rescue
      end
      options = options.clone
      options.delete(:credentials)
    end
  end
  hp_auth_uri = options[:hp_auth_uri] || "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens"
  # append /tokens if missing from auth uri
  @hp_auth_uri = hp_auth_uri.include?('tokens')? hp_auth_uri : hp_auth_uri + "tokens"
  endpoint = URI.parse(@hp_auth_uri)
  @scheme = endpoint.scheme || "https"
  @host = endpoint.host || "region-a.geo-1.identity.hpcloudsvc.com"
  @port = endpoint.port.to_s || "35357"
  if (endpoint.path)
    @auth_path = endpoint.path.slice(1, endpoint.path.length)  # remove the leading slash
  else
    @auth_path = "v2.0/tokens"
  end
  service_url = "#{@scheme}://#{@host}:#{@port}"
  # Set the User-Agent. If the caller sets a user_agent, use it.
  @user_agent = options[:user_agent]
  set_user_agent_header(connection_options, "fog/#{Fog::VERSION}", @user_agent)
  connection = Fog::XML::Connection.new(service_url, false, connection_options)

  ### Implement HP Control Services Authentication services ###
  # Get the style of auth credentials passed, defaults to access/secret key style
  @hp_use_upass_auth_style = options[:hp_use_upass_auth_style] || false
  @hp_access_key = options[:hp_access_key]
  @hp_secret_key = options[:hp_secret_key]
  @hp_tenant_id  = options[:hp_tenant_id]
  @hp_service_type  = options[:hp_service_type]
  @hp_avl_zone   = options[:hp_avl_zone]

  ### Decide which auth style to use
  unless (@hp_use_upass_auth_style)
    # If Access Key style credentials are provided, use that
    request_body = {
        'auth' => {
            'apiAccessKeyCredentials' => {
                'accessKey' => "#{@hp_access_key}",
                'secretKey' => "#{@hp_secret_key}"
            }
        }
    }
  else
    # Otherwise use the Username/Password style
    request_body = {
        'auth' => {
            'passwordCredentials' => {
                'username' => "#{@hp_access_key}",
                'password' => "#{@hp_secret_key}"
            }
        }
    }
  end
  # add tenant_id if specified
  request_body['auth']['tenantId'] = @hp_tenant_id if @hp_tenant_id

  ### Make the call to CS to get auth token and service catalog
  response = connection.request(
    {
      :expects => 200,
      :headers => {
          'Content-Type' => 'application/json'
      },
      :method => 'POST',
      :body => Fog::JSON.encode(request_body),
      :path => @auth_path
    }
  )

  body = Fog::JSON.decode(response.body)

  ### fish out auth_token and endpoint for the service
  auth_token = body['access']['token']['id']
  expires = body['access']['token']['expires']
  service_catalog = get_service_catalog(body['access']['serviceCatalog'])
  endpoint_url = get_endpoint_url(service_catalog, @hp_service_type, @hp_avl_zone)
  begin
    cdn_endpoint_url = get_endpoint_url(service_catalog, "CDN", @hp_avl_zone)
  rescue
  end

  creds = {
    :auth_token => auth_token,
    :expires => expires,
    :service_catalog => service_catalog,
    :endpoint_url => endpoint_url,
    :cdn_endpoint_url => cdn_endpoint_url
  }
  return creds
end

.convert_aliased_attributes_to_original(model, attributes) ⇒ Object

converts any attributes hash from aliased keys to original attribute keys



240
241
242
243
244
245
246
247
248
249
250
# File 'lib/fog/hp/core.rb', line 240

def self.convert_aliased_attributes_to_original(model, attributes)
  original_attributes = {}
  attributes.each do |k, v|
    if orig_key = model.aliases.invert[k]
      original_attributes[orig_key] = v
    else
      original_attributes[k] = v
    end
  end
  original_attributes
end

.escape(str, extra_exclude_chars = '') ⇒ Object

CGI.escape, but without special treatment on spaces



233
234
235
236
237
# File 'lib/fog/hp/core.rb', line 233

def self.escape(str,extra_exclude_chars = '')
  str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do
    '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
  end
end

.service_catalog(options, connection_options = {}) ⇒ Object



108
109
110
111
112
113
# File 'lib/fog/hp/core.rb', line 108

def self.service_catalog(options, connection_options = {})
  creds = authenticate_v2(options, connection_options)
  return {} if creds.nil?
  return {} if creds[:service_catalog].nil?
  return creds[:service_catalog]
end