cloudstack-cli 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudstack-cli (0.0.5)
4
+ cloudstack-cli (0.1.0)
5
5
  net-ssh (~> 2.6.7)
6
6
  rainbow (~> 1.1.4)
7
7
  thor (~> 0.18.1)
@@ -5,8 +5,7 @@ module CloudstackCli
5
5
 
6
6
  # catch control-c and exit
7
7
  trap("SIGINT") {
8
- puts
9
- puts "bye"
8
+ puts " bye"
10
9
  exit!
11
10
  }
12
11
 
@@ -68,6 +68,9 @@ module CloudstackCli
68
68
  desc "network SUBCOMMAND ...ARGS", "Manage networks"
69
69
  subcommand "network", Network
70
70
 
71
+ desc "physicalnetwork SUBCOMMAND ...ARGS", "Manage physical networks"
72
+ subcommand "physicalnetwork", PhysicalNetwork
73
+
71
74
  desc "lb SUBCOMMAND ...ARGS", "Manage load balancing rules"
72
75
  subcommand "lb", Lb
73
76
 
@@ -7,43 +7,33 @@ class Network < CloudstackCli::Base
7
7
 
8
8
  desc "list", "list networks"
9
9
  option :project
10
- option :physical, type: :boolean
10
+ option :account, default: ""
11
11
  def list
12
12
  project = find_project if options[:project]
13
- if options[:physical]
14
- networks = client.list_physical_networks
15
- if networks.size < 1
16
- puts "No networks found"
17
- else
18
- table = [['Name', 'State', 'ID', 'Zone ID']]
19
- networks.each do |network|
20
- table << [
21
- network["name"],
22
- network["state"],
23
- network["id"],
24
- network["zoneid"]
25
- ]
26
- end
27
- print_table table
28
- end
13
+
14
+ networks = []
15
+ if project
16
+ networks = client.list_networks(project['id'])
17
+ else
18
+ networks = client.list_networks(-1, options[:account] != '' ? options[:account] : nil )
19
+ networks + client.list_networks(nil, options[:account] != '' ? options[:account] : nil )
20
+ end
21
+
22
+ if networks.size < 1
23
+ puts "No networks found"
29
24
  else
30
- networks = client.list_networks(project ? project['id'] : -1)
31
- if networks.size < 1
32
- puts "No networks found"
33
- else
34
- table = [["Name", "Displaytext", "Account", "Project", "State", "ID"]]
35
- networks.each do |network|
36
- table << [
37
- network["name"],
38
- network["displaytext"],
39
- network["account"],
40
- network["project"],
41
- network["state"],
42
- network["id"]
43
- ]
44
- end
45
- print_table table
25
+ table = [["Name", "Displaytext", "Account", "Project", "State", "ID"]]
26
+ networks.each do |network|
27
+ table << [
28
+ network["name"],
29
+ network["displaytext"],
30
+ network["account"],
31
+ network["project"],
32
+ network["state"],
33
+ network["id"]
34
+ ]
46
35
  end
36
+ print_table table
47
37
  end
48
38
  end
49
39
 
@@ -0,0 +1,24 @@
1
+ class PhysicalNetwork < CloudstackCli::Base
2
+
3
+ desc "list", "list physical networks"
4
+ option :project
5
+ def list
6
+ project = find_project if options[:project]
7
+ networks = client.list_physical_networks
8
+ if networks.size < 1
9
+ puts "No networks found"
10
+ else
11
+ table = [['Name', 'State', 'ID', 'Zone ID']]
12
+ networks.each do |network|
13
+ table << [
14
+ network["name"],
15
+ network["state"],
16
+ network["id"],
17
+ network["zoneid"]
18
+ ]
19
+ end
20
+ print_table table
21
+ end
22
+ end
23
+
24
+ end
@@ -32,13 +32,13 @@ class Server < CloudstackCli::Base
32
32
  end
33
33
 
34
34
  desc "create NAME", "create a server"
35
- option :zone, :required => true
36
- option :template, :required => true
37
- option :offering, :required => true
38
- option :networks, :type => :array, :required => true
35
+ option :zone, required: true
36
+ option :template, required: true
37
+ option :offering, required: true
38
+ option :networks, type: :array, required: true
39
39
  option :project
40
- option :port_forwarding, :type => :array, :aliases => :pf, :default => [], :description => "public_ip:port"
41
- option :interactive, :type => :boolean
40
+ option :port_forwarding, type: :array, aliases: :pf, default: [], description: "public_ip:port"
41
+ option :interactive, type: :boolean
42
42
  def create(name)
43
43
  CloudstackCli::Helper.new(options[:config]).bootstrap_server(
44
44
  name,
@@ -51,6 +51,25 @@ class Server < CloudstackCli::Base
51
51
  )
52
52
  end
53
53
 
54
+ desc "destroy NAME", "destroy a server"
55
+ option :force, description: "destroy without asking", type: :boolean, aliases: '-f'
56
+ def destroy(name)
57
+ server = client.get_server(name)
58
+ unless server
59
+ error "Server not found."
60
+ exit
61
+ end
62
+ ask = "Are you sure you want to destroy the following server?\n"
63
+ ask += "#{server['name']} (#{server['state']})?"
64
+
65
+ unless options[:force] == true || yes?(ask)
66
+ exit
67
+ end
68
+
69
+ client.destroy_server(server["id"])
70
+ puts
71
+ end
72
+
54
73
  desc "bootstrap", "interactive creation of a server with network access"
55
74
  def bootstrap
56
75
  CloudstackCli::Helper.new(options[:config]).bootstrap_server_interactive()
@@ -1,8 +1,14 @@
1
1
  class Stack < CloudstackCli::Base
2
2
 
3
3
  desc "create STACKFILE", "create a stack of servers"
4
- def create(stackfile)
5
- # TODO
4
+ def create(stack_file)
5
+ #begin
6
+ stack = JSON.parse(File.read(stack_file))
7
+ #rescue Exception => e
8
+ $stderr.puts "Can't find the stack file #{stack_file}."
9
+ exit
10
+ #end
11
+ p stack
6
12
  end
7
13
 
8
14
  end
@@ -1,3 +1,3 @@
1
1
  module CloudstackCli
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -272,6 +272,20 @@ module CloudstackClient
272
272
  json['virtualmachine']
273
273
  end
274
274
 
275
+ ##
276
+ # Destroy the server with the specified name.
277
+ #
278
+
279
+ def destroy_server(id)
280
+ params = {
281
+ 'command' => 'destroyVirtualMachine',
282
+ 'id' => id
283
+ }
284
+
285
+ json = send_async_request(params)
286
+ json['virtualmachine']
287
+ end
288
+
275
289
  ##
276
290
  # Finds the service offering with the specified name.
277
291
 
@@ -468,12 +482,21 @@ module CloudstackClient
468
482
  ##
469
483
  # Lists all available networks.
470
484
 
471
- def list_networks(project_id = nil)
485
+ def list_networks(project_id = nil, account = nil)
472
486
  params = {
473
- 'command' => 'listNetworks',
474
- 'listall' => true,
487
+ 'command' => 'listNetworks',
488
+ 'listall' => true,
475
489
  }
476
490
  params['projectid'] = project_id if project_id
491
+ if account
492
+ domain = list_accounts({name: account})
493
+ if domain.size > 0
494
+ params['account'] = account
495
+ params['domainid'] = domain.first["domainid"]
496
+ else
497
+ puts "Account #{account} not found."
498
+ end
499
+ end
477
500
  json = send_request(params)
478
501
  json['network'] || []
479
502
  end
@@ -4,8 +4,8 @@ module CloudstackClient
4
4
  begin
5
5
  return YAML::load(IO.read(config_file))
6
6
  rescue Exception => e
7
- $stderr.puts "Can't find the config file '#{config_file}'"
8
- $stderr.puts "Please see https://bitbucket.org/swisstxt/cloudstack-cli under 'Setup'"
7
+ $stderr.puts "Can't find the config file #{config_file}."
8
+ $stderr.puts "To create a new configuration file run \"cs setup\"."
9
9
  exit
10
10
  end
11
11
  end
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "hadoop_cluster_a",
3
+ "description": "A small hadoop cluster with hbase",
4
+ "version": "1.0",
5
+ "servers": [
6
+ {
7
+ "name": "zookeeper-a, zookeeper-b, zookeeper-c",
8
+ "description": "Zookeeper nodes",
9
+ "template": "rhel-5.6-base",
10
+ "service": "small",
11
+ "port_rules": "2181",
12
+ },
13
+ {
14
+ "name": "hadoop-master",
15
+ "description": "Hadoop master node",
16
+ "template": "rhel-5.6-base",
17
+ "service": "large",
18
+ "networks": "app-net, storage-net",
19
+ "port_rules": "50070, 50030, 60010",
20
+ },
21
+ {
22
+ "name": "hadoop-worker-a hadoop-worker-b hadoop-worker-c",
23
+ "description": "Hadoop worker nodes",
24
+ "template": "rhel-5.6-base",
25
+ "service": "medium",
26
+ "port_rules": "50075, 50060, 60030",
27
+ }
28
+ ]
29
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudstack-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-25 00:00:00.000000000 Z
12
+ date: 2013-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -115,6 +115,7 @@ files:
115
115
  - lib/cloudstack-cli/commands/load_balancer.rb
116
116
  - lib/cloudstack-cli/commands/network.rb
117
117
  - lib/cloudstack-cli/commands/offering.rb
118
+ - lib/cloudstack-cli/commands/physical_network.rb
118
119
  - lib/cloudstack-cli/commands/project.rb
119
120
  - lib/cloudstack-cli/commands/publicip.rb
120
121
  - lib/cloudstack-cli/commands/router.rb
@@ -130,6 +131,7 @@ files:
130
131
  - lib/cloudstack-client/ssh_command.rb
131
132
  - lib/cloudstack_cli.rb
132
133
  - lib/cloudstack_client.rb
134
+ - test/stack_example.json
133
135
  homepage: https://bitbucket.org/swisstxt/cloudstack-cli
134
136
  licenses: []
135
137
  post_install_message:
@@ -156,4 +158,5 @@ rubygems_version: 1.8.23
156
158
  signing_key:
157
159
  specification_version: 3
158
160
  summary: cloudstack-cli CloudStack API client
159
- test_files: []
161
+ test_files:
162
+ - test/stack_example.json