Class: CloudInteractor::SSHKey

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_interactor/sshkey.rb

Constant Summary collapse

IDENTITY =
'ssh_keys'
RESOURCE =
'compute'

Instance Method Summary collapse

Constructor Details

#initialize(main_obj, classes, options = {}) ⇒ SSHKey

Returns a new instance of SSHKey.



7
8
9
10
11
# File 'lib/cloud_interactor/sshkey.rb', line 7

def initialize main_obj, classes, options={} 
  @main_obj  = main_obj
  @options   = options
  @classes   = classes
end

Instance Method Details

#bootstrap(output = true) ⇒ Object

special method for digitalocean api, will attempt to create the sshkeyid on DO if one matching the user’s hostname is not found



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cloud_interactor/sshkey.rb', line 42

def bootstrap output=true
  read Socket.gethostname, false

  if @main_obj["specific_#{ IDENTITY }"].empty?
    puts "Did not detect an SSHKey on DigitalOcean for the system #{ Socket.gethostname }, creating..."
    create_hash = {}
    create_hash['name']       = Socket.gethostname
    create_hash['ssh_pub_key'] = File.read(File.expand_path('~/.ssh/id_rsa.pub'))

    create create_hash

    sleep 5

    read Socket.gethostname, false
  end
end

#create(args) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/cloud_interactor/sshkey.rb', line 27

def create args
  puts "Creating #{ args['name'] } in #{ IDENTITY }..."

  puts("Creating #{ IDENTITY.singularize } with args #{ ap(args) }") if @options['verbose']

  @main_obj["#{ IDENTITY }_create_request"] = JSON.parse(@classes['auth'].auth_service(RESOURCE).instance_eval(IDENTITY).create(args).to_json)
end

#destroy(args) ⇒ Object



35
36
37
38
39
# File 'lib/cloud_interactor/sshkey.rb', line 35

def destroy args
  read args, false

  @classes['helper'].generic_destroy_parse args, IDENTITY, RESOURCE
end

#list(args = {}, output = true) ⇒ Object



17
18
19
# File 'lib/cloud_interactor/sshkey.rb', line 17

def list args={}, output=true
  @classes['helper'].generic_list_call IDENTITY, RESOURCE, output
end

#read(args, output = true) ⇒ Object



21
22
23
24
25
# File 'lib/cloud_interactor/sshkey.rb', line 21

def read args, output=true
  list [], false

  @classes['helper'].generic_read_parse args, IDENTITY, output
end

#run(method, args) ⇒ Object



13
14
15
# File 'lib/cloud_interactor/sshkey.rb', line 13

def run method, args
  self.send(method, args)
end