class Fog::Compute::OracleCloud::Instance

Public Class Methods

new(attributes={}) click to toggle source
Calls superclass method
# File lib/fog/oraclecloud/models/compute/instance.rb, line 42
def initialize(attributes={})
 self.shape ||= 'oc3'
 super
end

Public Instance Methods

add_public_ip_address() click to toggle source
# File lib/fog/oraclecloud/models/compute/instance.rb, line 111
def add_public_ip_address
        existing = get_public_ip_address 
        if existing then
                raise ArgumentError.new "Can't add public id address to instance that already has one (#{existing.ip})"
        end
        begin 
                ip = Fog::Compute[:oraclecloud].ip_reservations.get("#{name}_publicIp")
        rescue Fog::Compute::OracleCloud::NotFound    
                # Doesn't exist yet. Create it now
               ip = Fog::Compute[:oraclecloud].ip_reservations.create(
                       :name => "#{name}_publicIp"
               )
        end
        # Attach it to this instance
        Fog::Logger.debug "Associating IP Reservation (#{name}_publicIp) with vcable: #{vcable_id}"
        assoc = Fog::Compute[:oraclecloud].ip_associations.create(
                :parentpool => "ipreservation:#{name}_publicIp",
                :vcable => vcable_id
        )
        Fog::Logger.debug "Created IP Association - #{assoc.uri}"
        ip
end
clean_name() click to toggle source
# File lib/fog/oraclecloud/models/compute/instance.rb, line 51
def clean_name 
 name.sub %r{\/.*\/}, ''
end
create() click to toggle source
# File lib/fog/oraclecloud/models/compute/instance.rb, line 60
def create
        requires :name, :sshkeys
  
  data = service.create_instance(name, shape || 'oc3', imagelist || '/oracle/public/oel_6.4_2GB_v1', label, sshkeys)
  merge_attributes(data.body['instances'][0])
end
create_security_list(seclist_name=nil, description=nil, policy="deny", outbound_policy="permit") click to toggle source
# File lib/fog/oraclecloud/models/compute/instance.rb, line 82
def create_security_list(seclist_name=nil, description=nil, policy="deny", outbound_policy="permit")
        if !seclist_name then
                seclist_name = "#{name}_SecList"
        end
        data = Fog::Compute[:oraclecloud].security_lists.create(
                :name => seclist_name,
                :description => description,
                :policy => policy,
                :outbound_cidr_policy => outbound_policy
        )
        # Now attach to this instance
        Fog::Compute[:oraclecloud].security_associations.create(
                :name => "#{name}_SecAssoc",
                :seclist => seclist_name,
                :vcable => vcable_id
        )
        data
end
destroy() click to toggle source
# File lib/fog/oraclecloud/models/compute/instance.rb, line 67
def destroy
        requires :name
        service.delete_instance(name)
end
get_public_ip_address() click to toggle source
# File lib/fog/oraclecloud/models/compute/instance.rb, line 101
def get_public_ip_address
        if !networking['eth0'] or !networking['eth0']['nat'] or !networking['eth0']['nat'].include? 'ipreservation:' then
                # Instance doesn't have a public ip reservation yet
                return false
        end
        ip_name = networking['eth0']['nat'].sub "ipreservation:", ''
        ip = Fog::Compute[:oraclecloud].ip_reservations.get(ip_name)
        ip.ip
end
get_security_lists() click to toggle source
# File lib/fog/oraclecloud/models/compute/instance.rb, line 72
def get_security_lists
        seclists = []
        networking['eth0']['seclists'].each do |seclist| 
                seclists.push(Fog::Compute[:oraclecloud].security_lists.new({
                        'name'=>seclist
                }))
        end
        seclists
end
ready?() click to toggle source
# File lib/fog/oraclecloud/models/compute/instance.rb, line 47
def ready?
 state == 'running'
end
save() click to toggle source
# File lib/fog/oraclecloud/models/compute/instance.rb, line 55
                        def save
  #identity ? update : create
  create
end