Module: CloudstackClient::SshKeyPair

Defined in:
lib/cloudstack_client/commands/ssh_key_pair.rb

Instance Method Summary collapse

Instance Method Details

#create_ssh_key_pair(name, args = {}) ⇒ Object

Create ssh key pairs.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cloudstack_client/commands/ssh_key_pair.rb', line 44

def create_ssh_key_pair(name, args = {})
  params = {
      'command' => 'createSSHKeyPair',
      'name' => name
  }
  if args[:project]
    project = get_project(args[:project])
    unless project
      puts "Error: project #{args[:project]} not found."
      exit 1
    end
    params['projectid'] = project['id']
  end

  if args[:account]
     = list_accounts({name: args[:account]}).first
    unless 
      puts "Error: Account #{args[:account]} not found."
      exit 1
    end
    params['domainid'] = ["domainid"]
    params['account'] = args[:account]
  end
  
  json = send_request(params)['keypair']
end

#delete_ssh_key_pair(name, args = {}) ⇒ Object

Delete ssh key pairs.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/cloudstack_client/commands/ssh_key_pair.rb', line 107

def delete_ssh_key_pair(name, args = {})
  params = {
      'command' => 'deleteSSHKeyPair',
      'name' => name
  }

  if args[:project]
    project = get_project(args[:project])
    unless project
      puts "Error: project #{args[:project]} not found."
      exit 1
    end
    params['projectid'] = project['id']
  end
  
  if args[:account]
     = list_accounts({name: args[:account]}).first
    unless 
      puts "Error: Account #{args[:account]} not found."
      exit 1
    end
    params['domainid'] = ["domainid"]
    params['account'] = args[:account]
  end
  
  json = send_request(params)
end

#list_ssh_key_pairs(args = {}) ⇒ Object

Lists ssh key pairs.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cloudstack_client/commands/ssh_key_pair.rb', line 9

def list_ssh_key_pairs(args = {})
  params = {
      'command' => 'listSSHKeyPairs',
      'isrecursive' => true
  }
  params['listall'] = true if args[:listall]
  params['name'] = args[:name] if args[:name]
  
  if args[:project]
    project = get_project(args[:project])
    unless project
      puts "Error: project #{args[:project]} not found."
      exit 1
    end
    params['projectid'] = project['id']
  end

  if args[:account]
     = list_accounts({name: args[:account]}).first
    unless 
      puts "Error: Account #{args[:account]} not found."
      exit 1
    end
    params['domainid'] = ["domainid"]
    params['account'] = args[:account]
  end
  
  json = send_request(params)
  json['sshkeypair'] || []
end

#register_ssh_key_pair(name, publickey, args = {}) ⇒ Object

Register ssh key pairs.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/cloudstack_client/commands/ssh_key_pair.rb', line 75

def register_ssh_key_pair(name, publickey, args = {})
  params = {
      'command' => 'registerSSHKeyPair',
      'name' => name,
      'publickey' => publickey
  }
  if args[:project]
    project = get_project(args[:project])
    unless project
      puts "Error: project #{args[:project]} not found."
      exit 1
    end
    params['projectid'] = project['id']
  end

  if args[:account]
     = list_accounts({name: args[:account]}).first
    unless 
      puts "Error: Account #{args[:account]} not found."
      exit 1
    end
    params['domainid'] = ["domainid"]
    params['account'] = args[:account]
  end
  
  json = send_request(params)['keypair']
end