Module: DeltaCloud

Defined in:
lib/documentation.rb,
lib/deltacloud.rb,
lib/base_object.rb,
lib/hwp_properties.rb,
lib/instance_state.rb,
lib/plain_formatter.rb

Overview

Copyright © 2009 Red Hat, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defined Under Namespace

Modules: HWP, InstanceState, PlainFormatter Classes: API, ActionObject, BaseObject, BaseObjectParamError, Documentation, NoHandlerForMethod, StatefulObject

Class Method Summary collapse

Class Method Details

.add_class(name, parent = :base) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/base_object.rb', line 265

def self.add_class(name, parent=:base)
  parent = parent.to_s
  parent_class = "#{parent.classify}Object"
  @defined_classes ||= []
  class_name = "#{parent.classify}::#{name.classify}"
  unless @defined_classes.include?(class_name)
    DeltaCloud::API.class_eval("class #{class_name} < DeltaCloud::#{parent_class}; end")
    @defined_classes << class_name
  end
  
  DeltaCloud::API.const_get(parent.classify).const_get(name.classify)
end

.driver_name(url) ⇒ Object

Return a API driver for specified URL

Parameters:



61
62
63
# File 'lib/deltacloud.rb', line 61

def self.driver_name(url)
  API.new(nil, nil, url).driver_name
end

.guess_model_type(response) ⇒ Object



278
279
280
281
282
283
# File 'lib/base_object.rb', line 278

def self.guess_model_type(response)
  response = Nokogiri::XML(response.to_s)
  return :action if ((response/'//actions').length == 1) and ((response/'//state').length == 0)
  return :stateful if ((response/'//actions').length == 1) and ((response/'//state').length == 1)
  return :base
end

.new(user_name, password, api_url, opts = {}, &block) ⇒ DeltaCloud::API

Get a new API client instance

Parameters:

Returns:



37
38
39
40
# File 'lib/deltacloud.rb', line 37

def self.new(user_name, password, api_url, opts={}, &block)
  opts ||= {}
  API.new(user_name, password, api_url, opts, &block)
end

.valid_credentials?(user_name, password, api_url, opts = {}) ⇒ true|false

Check given credentials if their are valid against backend cloud provider

Parameters:

Returns:

  • (true|false)


49
50
51
52
53
54
55
56
# File 'lib/deltacloud.rb', line 49

def self.valid_credentials?(user_name, password, api_url, opts={})
  api=API.new(user_name, password, api_url, opts)
  result = false
  api.request(:get, '', :force_auth => '1') do |response|
    result = true if response.code.eql?(200)
  end
  return result
end