Class: Fog::Compute::OracleCloud::Instance

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/oraclecloud/models/compute/instance.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Instance



42
43
44
45
# File 'lib/fog/oraclecloud/models/compute/instance.rb', line 42

def initialize(attributes={})
	self.shape ||= 'oc3'
	super
end

Instance Method Details

#add_public_ip_addressObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# 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_nameObject



51
52
53
# File 'lib/fog/oraclecloud/models/compute/instance.rb', line 51

def clean_name 
	name.sub %r{\/.*\/}, ''
end

#createObject



60
61
62
63
64
65
# 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") ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 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

#destroyObject



67
68
69
70
# File 'lib/fog/oraclecloud/models/compute/instance.rb', line 67

def destroy
	requires :name
	service.delete_instance(name)
end

#get_public_ip_addressObject



101
102
103
104
105
106
107
108
109
# 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_listsObject



72
73
74
75
76
77
78
79
80
# 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?Boolean



47
48
49
# File 'lib/fog/oraclecloud/models/compute/instance.rb', line 47

def ready?
	state == 'running'
end

#saveObject



55
56
57
58
# File 'lib/fog/oraclecloud/models/compute/instance.rb', line 55

def save
  #identity ? update : create
  create
end