Class: OracleCloud::InstanceRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/oraclecloud/instance_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, opts) ⇒ InstanceRequest

Returns a new instance of InstanceRequest.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/oraclecloud/instance_request.rb', line 21

def initialize(client, opts)
  @client    = client
  @opts      = opts

  @name      = opts[:name]
  @shape     = opts[:shape]
  @imagelist = opts[:imagelist]
  @public_ip = opts[:public_ip]
  @label     = opts.fetch(:label, @name)
  @sshkeys   = opts.fetch(:sshkeys, [])

  validate_options!
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



20
21
22
# File 'lib/oraclecloud/instance_request.rb', line 20

def client
  @client
end

#imagelistObject (readonly)

Returns the value of attribute imagelist.



20
21
22
# File 'lib/oraclecloud/instance_request.rb', line 20

def imagelist
  @imagelist
end

#labelObject (readonly)

Returns the value of attribute label.



20
21
22
# File 'lib/oraclecloud/instance_request.rb', line 20

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



20
21
22
# File 'lib/oraclecloud/instance_request.rb', line 20

def name
  @name
end

#optsObject (readonly)

Returns the value of attribute opts.



20
21
22
# File 'lib/oraclecloud/instance_request.rb', line 20

def opts
  @opts
end

#public_ipObject (readonly)

Returns the value of attribute public_ip.



20
21
22
# File 'lib/oraclecloud/instance_request.rb', line 20

def public_ip
  @public_ip
end

#shapeObject (readonly)

Returns the value of attribute shape.



20
21
22
# File 'lib/oraclecloud/instance_request.rb', line 20

def shape
  @shape
end

#sshkeysObject (readonly)

Returns the value of attribute sshkeys.



20
21
22
# File 'lib/oraclecloud/instance_request.rb', line 20

def sshkeys
  @sshkeys
end

Instance Method Details

#full_nameObject



50
51
52
# File 'lib/oraclecloud/instance_request.rb', line 50

def full_name
  "#{client.full_identity_domain}/#{client.username}/#{name}"
end

#missing_required_optionsObject



44
45
46
47
48
# File 'lib/oraclecloud/instance_request.rb', line 44

def missing_required_options
  [ :name, :shape, :imagelist ].each_with_object([]) do |opt, memo|
    memo << opt unless opts[opt]
  end
end

#natObject



54
55
56
57
# File 'lib/oraclecloud/instance_request.rb', line 54

def nat
  return unless public_ip
  (public_ip == :pool) ? 'ippool:/oracle/public/ippool' : "ipreservation:#{public_ip}"
end

#networkingObject



59
60
61
62
63
64
65
# File 'lib/oraclecloud/instance_request.rb', line 59

def networking
  networking = {}
  networking['eth0'] = {}
  networking['eth0']['nat'] = nat unless nat.nil?

  networking
end

#to_hObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/oraclecloud/instance_request.rb', line 67

def to_h
  {
    'shape'      => shape,
    'label'      => label,
    'imagelist'  => imagelist,
    'name'       => full_name,
    'sshkeys'    => sshkeys,
    'networking' => networking
  }
end

#validate_options!Object

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
42
# File 'lib/oraclecloud/instance_request.rb', line 35

def validate_options!
  raise ArgumentError, "The following required options are missing: #{missing_required_options.join(', ')}" unless
    missing_required_options.empty?

  raise ArgumentError, "#{shape} is not a valid shape" unless client.shapes.exist?(shape)
  raise ArgumentError, "#{imagelist} is not a valid imagelist" unless client.imagelists.exist?(imagelist)
  raise ArgumentError, 'sshkeys must be an array of key names' unless sshkeys.respond_to?(:each)
end