Class: CpOraclecloud::Image

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
app/models/cp_oraclecloud/image.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Image

Returns a new instance of Image.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/cp_oraclecloud/image.rb', line 11

def initialize(attributes = {})
  if !attributes[:name].blank?
    regex = attributes[:name].match(/\/.*\/(.*)/)
    if regex && regex.length > 1
      clean_name = regex[1]
      attributes[:id] = clean_name
      attributes[:name] = clean_name
    end
  end
  attributes.each do |field, value|
    send("#{field}=", value)
  end
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



7
8
9
# File 'app/models/cp_oraclecloud/image.rb', line 7

def default
  @default
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'app/models/cp_oraclecloud/image.rb', line 7

def description
  @description
end

#entriesObject

Returns the value of attribute entries.



7
8
9
# File 'app/models/cp_oraclecloud/image.rb', line 7

def entries
  @entries
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'app/models/cp_oraclecloud/image.rb', line 7

def id
  @id
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'app/models/cp_oraclecloud/image.rb', line 7

def name
  @name
end

#uriObject

Returns the value of attribute uri.



7
8
9
# File 'app/models/cp_oraclecloud/image.rb', line 7

def uri
  @uri
end

Class Method Details

.allObject



37
38
39
40
41
# File 'app/models/cp_oraclecloud/image.rb', line 37

def self.all
  result = []
  connection.image_lists.each { |k| result.push(CpOraclecloud::Image.new(k.attributes))}
  result
end

.connectionObject



67
68
69
70
71
72
73
74
75
# File 'app/models/cp_oraclecloud/image.rb', line 67

def self.connection
  @connection ||= Fog::Compute.new(
    :provider => 'OracleCloud',
    :oracle_username => CpOraclecloud.username,
    :oracle_password => CpOraclecloud.password,
    :oracle_domain => CpOraclecloud.domain,
    :oracle_compute_api => CpOraclecloud.compute_api
    )
end

.create(params) ⇒ Object



48
49
50
51
52
# File 'app/models/cp_oraclecloud/image.rb', line 48

def self.create(params)
  connection.image_lists.create(:name => params[:name],
                             :default => params[:default],
                             :description => params[:description])
end

.delete(id) ⇒ Object



63
64
65
# File 'app/models/cp_oraclecloud/image.rb', line 63

def self.delete(id)
  connection.image_lists.get(id).destroy
end

.find_by_id(id) ⇒ Object



43
44
45
46
# File 'app/models/cp_oraclecloud/image.rb', line 43

def self.find_by_id(id)
  data = connection.image_lists.get(id)
  CpOraclecloud::Image.new(data.attributes)
end

Instance Method Details

#persisted?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/cp_oraclecloud/image.rb', line 33

def persisted?
  !id.blank?
end

#to_modelObject



29
30
31
# File 'app/models/cp_oraclecloud/image.rb', line 29

def to_model
  self
end

#to_sObject



25
26
27
# File 'app/models/cp_oraclecloud/image.rb', line 25

def to_s
  name
end

#update(params) ⇒ Object



54
55
56
57
58
59
60
61
# File 'app/models/cp_oraclecloud/image.rb', line 54

def update(params)
  fog = self.class.connection.image_lists.get(id)

  [:name, :default, :description].each do |field|
    fog.attributes[field.to_sym] = params[field.to_sym]
  end
  fog.update
end