danarchy_sys 0.2.17 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5dd08ba1e4fcce5f446e2198ca93828f8f9271d9
4
- data.tar.gz: 00c68532f44cbec2e9891bf47f820419ef57e287
3
+ metadata.gz: aeb862f65f50235701c84688ad465846b206ea7d
4
+ data.tar.gz: c24cd5c66b0281c655a2a504b718d376e6f9ddf2
5
5
  SHA512:
6
- metadata.gz: 395284512dd1b5b7447cb7e3f9dafac22c5a88283d36c224f5d812389a4863628c46d3ed52f3c88e757d102dec638b59a3530e397ee6f5461ac617663dbaeec5
7
- data.tar.gz: 8c8f71e0205ed5af717fc2fe95c9f1e14bc791687cbbbf97d1dfef592ba2b83cdbb60c15cd633c0dcb7c677eca98d28dac30d55e9aba93ee2acae2a3704117ae
6
+ metadata.gz: 0e4534817fc4c50e88473c6915e91a385cdf4c9b5c084d3d5c2671c8c5c1f703af773c3145250880a727ab3b493fd16b935dc6d58fa5e80eb42cc3e30d8abc03
7
+ data.tar.gz: 06b2984a4da6b5b5d01f26a0b96824580de98ee48e9beb02c78e64aac85234e57085a01e2d136d2fd9c9ef75b427b8d7dc3625c897b5a1ec9a562bd2bd5eb252
@@ -58,7 +58,7 @@ class InstanceManager
58
58
  puts "\nInvalid action for #{instance.name}'s current status!"
59
59
  next
60
60
  end
61
-
61
+
62
62
  until status != instance.state
63
63
  instance = os_compute.instances.get_instance(instance.name)
64
64
  sleep(3)
@@ -66,9 +66,30 @@ class InstanceManager
66
66
  end
67
67
 
68
68
  printf("\n%#{instance.name.size}s %0s %0s\n", instance.name, ' => ', instance.state)
69
+ elsif cmd == 'rebuild'
70
+ print "Should we rebuild #{instance.name}? (Y/N): "
71
+ if gets.chomp =~ /^y(es)?$/i
72
+ image = PromptsCreateInstance.image(os_compute.images)
73
+ instance.rebuild(image.id, instance.name)
74
+
75
+ print "Rebuilding #{instance.name} with #{image.name}"
76
+ instance = os_compute.instances.get_instance(instance.name)
77
+ until instance.state == 'ACTIVE'
78
+ instance = os_compute.instances.get_instance(instance.name)
79
+ sleep(3)
80
+ print ' .'
81
+ end
82
+
83
+ addrs = os_compute.instances.get_public_addresses(instance.name)
84
+ addrs.each { |ip| `ssh-keygen -R #{ip} &>/dev/null` }
85
+ puts "\nRebuild successful!"
86
+ else
87
+ puts "Not rebuilding #{instance.name} at this time."
88
+ end
69
89
  elsif cmd == 'connect'
70
90
  if instance.state == 'ACTIVE'
71
- os_compute.ssh(instance.name.to_s)
91
+ connect = os_compute.ssh(instance.name)
92
+ puts connect if connect != true
72
93
  else
73
94
  puts "Unable to connect: #{instance.name} is not running!"
74
95
  end
@@ -84,12 +105,12 @@ class InstanceManager
84
105
  def self.chooser(os_compute)
85
106
  comp_inst = os_compute.instances
86
107
  instances = comp_inst.all_instances
87
- instances_numhash = Helpers.objects_to_numhash(instances)
88
- instance_name = 'nil'
89
- instance = 'nil'
108
+ instances_numhash = Helpers.objects_to_numhash(comp_inst.all_instances)
109
+ instance_name = nil
110
+ instance = nil
90
111
 
91
112
  # Create a new instances if none exist
92
- if instances_numhash.empty?
113
+ if instances.empty?
93
114
  print 'No existing instances were found. Should we create a new one? (Y/N): '
94
115
  abort('Exiting!') unless gets.chomp =~ /^y(es)?$/i
95
116
  instance = PromptsCreateInstance.create_instance(os_compute, 'nil')
@@ -97,16 +118,14 @@ class InstanceManager
97
118
  return instance
98
119
  end
99
120
 
100
- # Display existing instances in numbered hash
101
- fields = PrintFormats.printf_numhash_values(instances_numhash, [:name, :state])
102
-
103
121
  puts 'Available instances:'
104
- InstanceStatus.all_instances(os_compute, instances)
105
-
122
+ istatus = InstanceStatus.new(os_compute)
123
+ istatus.all_instances(instances)
124
+
106
125
  # Loop input until an existing instance is selected
107
126
  print 'Enter an instance to manage or enter a name for a new instance: '
108
127
 
109
- until Helpers.check_nested_hash_value(instances_numhash, :name, instance_name) == true
128
+ until comp_inst.check_instance(instance_name) == true
110
129
  instance_name = gets.chomp
111
130
 
112
131
  until instance_name.empty? == false
@@ -127,13 +146,12 @@ class InstanceManager
127
146
  instance_name = instances_numhash[instance_name.to_i][:name].to_s
128
147
  end
129
148
 
130
- unless Helpers.check_nested_hash_value(instances_numhash, :name, instance_name) == true
149
+ unless comp_inst.check_instance(instance_name) == true
131
150
  print "#{instance_name} is not a valid instance.
132
151
  Should we create a new instance named #{instance_name}? (Y/N): "
133
152
 
134
153
  if gets.chomp =~ /^y(es)?$/i
135
154
  PromptsCreateInstance.create_instance(os_compute, instance_name)
136
- instances_numhash = Helpers.objects_to_numhash(comp_inst.all_instances)
137
155
  else
138
156
  puts "Not creating new instance: #{instance_name}."
139
157
  return false
@@ -142,9 +160,8 @@ Should we create a new instance named #{instance_name}? (Y/N): "
142
160
  end
143
161
 
144
162
  instance = comp_inst.get_instance(instance_name)
145
- status = instance.state
146
163
  Menus.print_menu('instance')
147
- puts "Managing instance: #{instance_name}\tStatus: #{status}"
164
+ puts "Managing instance: #{instance_name}\tStatus: #{instance.state}"
148
165
  instance
149
166
  end
150
167
  end
@@ -1,22 +1,25 @@
1
1
 
2
2
  class InstanceStatus
3
- def self.all_instances(os_compute, instances)
3
+ def initialize(os_compute)
4
+ @images = os_compute.images
5
+ @flavors = os_compute.flavors
6
+ end
7
+
8
+ def all_instances(instances)
4
9
  istats = {}
5
10
 
6
- id = 1
7
- instances.each do |instance|
8
- istats[id] = single_instance(os_compute, instance)
9
- id += 1
11
+ instances.map.with_index(1) do |instance, id|
12
+ istats[id] = single_instance(instance)
10
13
  end
11
14
 
12
- fields = %w[name state image vcpus ram disk keypair]
15
+ fields = %w[name status image vcpus ram disk keypair]
13
16
  format = PrintFormats.printf_numhash_values(istats, fields)
14
17
  _header(format)
15
-
18
+
16
19
  istats.each do |id, i|
17
20
  printf("#{format}\n", "#{id}.",
18
21
  i['name'],
19
- i['state'],
22
+ i['status'],
20
23
  i['image'],
21
24
  i['vcpus'],
22
25
  i['ram'],
@@ -24,18 +27,18 @@ class InstanceStatus
24
27
  i['keypair'],
25
28
  )
26
29
  end
30
+
31
+ istats
27
32
  end
28
33
 
29
- def self.single_instance(os_compute, instance)
30
- comp_inst = os_compute.instances
31
- comp_imgs = os_compute.images
32
- comp_flvs = os_compute.flavors
34
+ def single_instance(instance)
35
+ image = @images.get_image_by_id(instance.image['id'])
36
+ flavor = @flavors.get_flavor_by_id(instance.flavor['id'])
33
37
 
34
- image = comp_imgs.get_image_by_id(instance.image['id'])
35
- flavor = comp_flvs.get_flavor_by_id(instance.flavor['id'])
38
+ image = NilImage.new if image == nil
36
39
 
37
40
  istats = { 'name' => instance.name,
38
- 'state' => instance.state,
41
+ 'status' => instance.state,
39
42
  'image' => image.name,
40
43
  'vcpus' => flavor.vcpus,
41
44
  'ram' => flavor.ram,
@@ -44,7 +47,14 @@ class InstanceStatus
44
47
  }
45
48
  end
46
49
 
47
- def self._header(format)
48
- printf("#{format}\n", 'Id', 'Name', 'State', 'Image', 'VCPUS', 'RAM', 'Disk', 'KeyPair')
50
+ def _header(format)
51
+ printf("#{format}\n", 'Id', 'Name', 'Status', 'Image', 'VCPUS', 'RAM', 'Disk', 'KeyPair')
52
+ end
53
+
54
+ class NilImage
55
+ def name
56
+ 'Not Found'
57
+ end
49
58
  end
50
59
  end
60
+
@@ -8,7 +8,7 @@ class PromptsCreateInstance
8
8
  comp_keys = os_compute.keypairs
9
9
 
10
10
  # Prompt for and check that instance_name is unused
11
- if instance_name == 'nil'
11
+ if instance_name == nil
12
12
  print "\nWhat should we name the instance?: "
13
13
  instance_name = gets.chomp
14
14
  end
@@ -40,7 +40,7 @@ class PromptsCreateInstance
40
40
  puts " Keypair: #{keypair.name}"
41
41
 
42
42
  print 'Should we continue with creating the instance? (Y/N): '
43
- instance = 'nil'
43
+ instance = nil
44
44
  continue = gets.chomp
45
45
 
46
46
  if continue =~ /^y(es)?$/i
@@ -62,79 +62,40 @@ class PromptsCreateInstance
62
62
  end
63
63
 
64
64
  def self.image(comp_imgs)
65
- images_numbered = Helpers.array_to_numhash(comp_imgs.list_images)
66
- image_name = 'nil'
65
+ images_numbered = Helpers.objects_to_numhash(comp_imgs.all_images({'status' => 'ACTIVE'}))
67
66
 
68
67
  # List available images in a numbered hash.
69
68
  puts "\nAvailable Images:"
70
- i_name_length = Helpers.hash_largest_value(images_numbered).length
69
+ i_name_length = images_numbered.values.collect{|i| i[:name]}.max.size
71
70
  printf("%0s %-#{i_name_length}s\n", 'Id', 'Image')
72
- images_numbered.each do |id, i_name|
73
- printf("%0s %-#{i_name_length}s\n", "#{id}.", i_name)
74
- end
75
-
76
- # Loop input until existing image is selected
77
- print 'Which image should we use for this instance?: '
78
- until images_numbered.values.include?(image_name)
79
- image_name = gets.chomp
80
-
81
- if image_name =~ /^[0-9]*$/
82
- until images_numbered.keys.include?(image_name.to_i)
83
- print "#{image_name} is not a valid Id. Enter an Id from above: "
84
- image_name = gets.chomp
85
- end
86
-
87
- image_name = images_numbered[image_name.to_i]
88
- end
89
-
90
- image_check = images_numbered.values.include?(image_name)
91
- print "#{image_name} is not a valid image. Please enter an option from above: " if image_check == false
71
+ images_numbered.each do |id, image|
72
+ printf("%0s %-#{i_name_length}s\n", "#{id}.", image[:name])
92
73
  end
93
74
 
75
+ image_name = item_chooser(images_numbered, 'image')
94
76
  print "Image Name: #{image_name}\n"
95
77
  comp_imgs.get_image_by_name(image_name)
96
78
  end
97
79
 
98
80
  def self.flavor(comp_flvs)
99
- flavors = Helpers.objects_to_numhash(comp_flvs.all_flavors.sort_by(&:ram))
100
- flavor_name = 'nil'
81
+ flavors_numbered = Helpers.objects_to_numhash(comp_flvs.all_flavors.sort_by(&:ram))
82
+ flavor_name = nil
101
83
 
102
84
  puts "\nAvailable Instance Flavors:"
103
85
  puts sprintf("%0s %-15s %-10s %-10s %0s", 'Id', 'Name', 'RAM', 'VCPUs', 'Disk')
104
- flavors.each do |id, flavor|
86
+ flavors_numbered.each do |id, flavor|
105
87
  print sprintf("%0s %-15s %-10s %-10s %0s\n",
106
88
  "#{id}.", flavor[:name].split('.')[1], flavor[:ram], flavor[:vcpus], flavor[:disk])
107
89
  end
108
90
 
109
- print 'Which flavor should we use for this instance?: '
110
- flavor_check = false
111
-
112
- until flavor_check == true
113
- flavor_name = gets.chomp
114
-
115
- if flavor_name =~ /^[0-9]*$/
116
- until flavors.keys.include?(flavor_name.to_i)
117
- print "#{flavor_name} is not a valid Id. Enter an Id from above: "
118
- flavor_name = gets.chomp
119
- end
120
-
121
- flavor_name = flavors[flavor_name.to_i][:name].split('.')[1]
122
- end
123
-
124
- flavors.each_value do |flavor|
125
- flavor_check = true if flavor[:name].end_with?(flavor_name)
126
- end
127
-
128
- print "#{flavor_name} is not a valid flavor. Please enter an option from above: " if flavor_check == false
129
- end
130
-
131
- print "Flavor Name: #{flavor_name}\n"
91
+ flavor_name = item_chooser(flavors_numbered, 'flavor')
92
+ print "Flavor Name: #{flavor_name.split('.')[1]}\n"
132
93
  comp_flvs.get_flavor(flavor_name)
133
94
  end
134
95
 
135
96
  def self.keypair(comp_keys)
136
97
  keypairs = Helpers.objects_to_numhash(comp_keys.all_keypairs)
137
- keypair_name = 'nil'
98
+ keypair_name = nil
138
99
 
139
100
  # List available keypairs
140
101
  puts "\nAvailable Keypairs:"
@@ -179,4 +140,28 @@ Should we create a new keypair named #{keypair_name}? (Y/N): "
179
140
 
180
141
  comp_keys.get_keypair(keypair_name)
181
142
  end
143
+
144
+ private
145
+ def self.item_chooser(items_numbered, item)
146
+ # Loop input until existing object is selected
147
+ item_name = nil
148
+ print "Which #{item} should we use for this instance?: "
149
+
150
+ until items_numbered.values.collect{|i| i[:name]}.include?(item_name)
151
+ item_name = gets.chomp
152
+
153
+ if item_name =~ /^[0-9]*$/
154
+ until items_numbered.keys.include?(item_name.to_i)
155
+ print "#{item_name} is not a valid Id. Enter an Id from above: "
156
+ item_name = gets.chomp
157
+ end
158
+
159
+ item_name = items_numbered[item_name.to_i][:name]
160
+ end
161
+
162
+ item_check = items_numbered.values.collect{|i| i[:name]}.include?(item_name)
163
+ print "#{item_name} is not a valid item. Please enter an option from above: " if item_check == false
164
+ end
165
+ item_name
166
+ end
182
167
  end
@@ -14,6 +14,7 @@ class Menus
14
14
  'unpause' => 'Unpause instance from paused state',
15
15
  'suspend' => 'Suspend Instance (to disk)',
16
16
  'resume' => 'Resume instance from suspended state',
17
+ 'rebuild' => 'Rebuilds instance with a chosen image',
17
18
  'create' => 'Create a new instance',
18
19
  'delete' => 'Delete this instance'
19
20
  },
@@ -2,6 +2,7 @@ require_relative 'compute/instances'
2
2
  require_relative 'compute/keypairs'
3
3
  require_relative 'compute/images'
4
4
  require_relative 'compute/flavors'
5
+ require_relative 'compute/secgroups'
5
6
 
6
7
  module DanarchySys
7
8
  module OpenStack
@@ -29,29 +30,64 @@ module DanarchySys
29
30
  ComputeFlavors.new(@compute)
30
31
  end
31
32
 
33
+ def secgroups
34
+ ComputeSecgroups.new(@compute)
35
+ end
36
+
32
37
  def ssh(instance_name)
33
38
  (comp_inst, comp_kp, comp_img) = instances, keypairs, images
34
39
  instance = comp_inst.get_instance(instance_name)
35
40
  keypair_name = instance.key_name
36
41
  pemfile = comp_kp.pemfile_path(keypair_name)
37
42
 
43
+ addrs = comp_inst.get_public_addresses(instance_name)
44
+ ipv4 = addrs.grep(/\./).first
45
+ ipv6 = addrs.grep(/:/).first
46
+
38
47
  # Define user by image_id
39
- image_info = instance.image
40
- image_id = image_info['id']
48
+ image_id = instance.image['id']
41
49
  image = comp_img.get_image_by_id(image_id)
42
50
 
51
+ if image == nil
52
+ puts "Image not found for #{instance.name}! This instance needs to be rebuild with a current image."
53
+ return fallback_ssh(ipv4, pemfile)
54
+ end
55
+
43
56
  # CoreOS is an exception with user as simply 'core' and not 'coreos'
44
- user = ''
45
- if image.name =~ /CoreOS/i
46
- user = 'core'
47
- else
48
- user = image.name.downcase.split('-')[0]
57
+ user = 'ubuntu' if image.name =~ /ubuntu/i
58
+ user = 'debian' if image.name =~ /debian/i
59
+ user = 'centos' if image.name =~ /centos/i
60
+ user = 'fedora' if image.name =~ /fedora/i
61
+ user = 'core' if image.name =~ /coreos/i
62
+
63
+ puts "Connecting as user: #{user} => #{ipv4}"
64
+ connect = "ssh #{user}@#{ipv4} -i '#{pemfile}'"
65
+ ssh = system(connect)
66
+
67
+ attempts = 1
68
+ until ssh == true || attempts > 3
69
+ puts "Connection failed. Attempting again after 5 seconds..."
70
+ sleep(5)
71
+ fallback_ssh(ipv4, pemfile)
72
+ attempts += 1
49
73
  end
74
+ end
50
75
 
51
- ipv4, ipv6 = comp_inst.get_addresses(instance_name)
76
+ def fallback_ssh(ipv4, pemfile)
77
+ users = ['ubuntu','debian','centos','fedora','core']
78
+ ssh = false
52
79
 
53
- ssh = "ssh #{user}@#{ipv4} -i '#{pemfile}'"
54
- system(ssh)
80
+ users.each do |user|
81
+ puts "Attempting connection as user: #{user} => #{ipv4}"
82
+ connect = "ssh #{user}@#{ipv4} -i '#{pemfile}'"
83
+ ssh = system(connect)
84
+ return true if ssh == true
85
+ end
86
+
87
+ if ssh == false
88
+ puts 'Unable to connect after 3 tries!'
89
+ return false
90
+ end
55
91
  end
56
92
  end
57
93
  end
@@ -4,47 +4,34 @@ class ComputeImages
4
4
  def initialize(compute)
5
5
  @compute = compute
6
6
  end
7
-
8
- def all_images
9
- @compute.images
10
- end
11
7
 
12
- def list_images
13
- images = all_images
14
- image_list = []
8
+ def all_images(*filter)
9
+ filter = filter.shift || {}
10
+ @compute.images(filters: filter)
11
+ end
15
12
 
16
- # Get image names into array
17
- images.each do |i|
18
- next unless i.status == 'ACTIVE'
19
- image_list.push(i.name)
20
- end
13
+ def list_all_images
14
+ all_images.collect { |i| i.name }
15
+ end
21
16
 
22
- image_list
17
+ def list_active_images
18
+ all_images({'status' => 'ACTIVE'})
23
19
  end
24
20
 
25
21
  def get_image_by_name(image_name)
26
- images = all_images
27
-
28
- # Get image based on input image_name.
29
- image = 'nil'
30
- images.each do |i|
31
- next unless i.name == image_name
32
- next unless i.status == 'ACTIVE'
33
- image = i
34
- end
35
-
36
- image
22
+ all_images({
23
+ 'status' => 'ACTIVE',
24
+ 'name' => image_name
25
+ }).first
26
+ # .first may become a problem here
27
+ # if names are duplicates
37
28
  end
38
29
 
39
30
  def get_image_by_id(image_id)
40
- images = all_images
41
-
42
- # Get image based on input image_id.
43
- image = 'nil'
44
- images.each do |i|
45
- next unless i.id == image_id
46
- next unless i.status == 'ACTIVE'
47
- image = i
31
+ image = nil
32
+
33
+ all_images.each do |i|
34
+ image = i if i.id == image_id
48
35
  end
49
36
 
50
37
  image
@@ -6,100 +6,115 @@ class ComputeInstances
6
6
  @settings = settings
7
7
  end
8
8
 
9
- def all_instances
10
- @compute.servers
9
+ def all_instances(*filter)
10
+ filter = filter.shift || {}
11
+ @compute.servers(filters: filter)
11
12
  end
12
13
 
13
14
  def list_all_instances
14
- instances = all_instances
15
- instances.map(&:name)
15
+ all_instances.collect { |i| i.name }
16
16
  end
17
17
 
18
18
  def list_active_instances
19
- instances = all_instances
20
- instance_list = []
21
-
22
- instances.each do |i|
23
- instance_list.push(i.name) if i.state == 'ACTIVE'
24
- end
25
-
26
- instance_list
19
+ all_instances({ 'status' => ['ACTIVE'] }).collect { |i| i.name }
27
20
  end
28
21
 
29
22
  def check_instance(instance_name)
30
- instances = list_all_instances
31
-
32
- return true if instances.include?(instance_name)
23
+ return false if instance_name == nil || instance_name.empty? == true
24
+ return true if get_instance(instance_name)
33
25
  false
34
26
  end
35
27
 
36
28
  def get_instance(instance_name)
37
- servers = all_instances
29
+ instance = all_instances({ 'name' => [instance_name] })
30
+ return false if !instance.first
31
+ return false if !instance.collect{ |i| i.name }.include?(instance_name)
32
+ instance.first
33
+ end
38
34
 
39
- # Get servers ID based on input instance_name
40
- instance = 'nil'
41
- servers.each do |i|
42
- instance = i if i.name.end_with?(instance_name)
35
+ def get_public_addresses(instance)
36
+ if instance.class == String
37
+ instance = get_instance(instance)
43
38
  end
44
39
 
45
- return false unless instance
46
- instance
40
+ addrs = instance.addresses
41
+ return false if !addrs['public']
42
+ addrs['public'].map{|a| a['addr']}
47
43
  end
48
44
 
49
- def get_addresses(instance_name)
50
- instance = get_instance(instance_name)
51
- (ipv6, ipv4) = nil, nil
52
- addresses = instance.addresses['public']
53
-
54
- addresses.each do |i|
55
- ipv4 = i['addr'] if i['addr'].include?('.')
56
- ipv6 = i['addr'] if i['addr'].include?(':')
45
+ def get_private_addresses(instance)
46
+ if instance.class == String
47
+ instance = get_instance(instance)
57
48
  end
58
49
 
59
- return ipv4, ipv6
50
+ addrs = instance.addresses
51
+ return false if !addrs['private']
52
+ addrs['public'].map{|a| a['addr']}
60
53
  end
61
54
 
62
- def pause(instance_name)
63
- instance = get_instance(instance_name)
55
+ def pause(instance)
56
+ if instance.class == String
57
+ instance = get_instance(instance)
58
+ end
59
+
64
60
  return false unless instance.state == 'ACTIVE'
65
- @compute.pause_server(instance.id)
61
+ instance.pause
66
62
  end
67
63
 
68
- def unpause(instance_name)
69
- instance = get_instance(instance_name)
64
+ def unpause(instance)
65
+ if instance.class == String
66
+ instance = get_instance(instance)
67
+ end
68
+
70
69
  return false unless instance.state == 'PAUSED'
71
- @compute.unpause_server(instance.id)
70
+ instance.start
72
71
  end
73
72
 
74
- def suspend(instance_name)
75
- instance = get_instance(instance_name)
73
+ def suspend(instance)
74
+ if instance.class == String
75
+ instance = get_instance(instance)
76
+ end
77
+
76
78
  return false unless instance.state == 'ACTIVE'
77
- @compute.suspend_server(instance.id)
79
+ instance.suspend
78
80
  end
79
81
 
80
- def resume(instance_name)
81
- instance = get_instance(instance_name)
82
+ def resume(instance)
83
+ if instance.class == String
84
+ instance = get_instance(instance)
85
+ end
86
+
82
87
  return false unless instance.state == 'SUSPENDED'
83
- @compute.resume_server(instance.id)
88
+ instance.start
84
89
  end
85
90
 
86
- def start(instance_name)
87
- instance = get_instance(instance_name)
91
+ def start(instance)
92
+ if instance.class == String
93
+ instance = get_instance(instance)
94
+ end
95
+
88
96
  return false unless instance.state == 'SHUTOFF'
89
- @compute.start_server(instance.id)
97
+ instance.start
90
98
  end
91
99
 
92
- def stop(instance_name)
93
- instance = get_instance(instance_name)
100
+ def stop(instance)
101
+ if instance.class == String
102
+ instance = get_instance(instance)
103
+ end
104
+
94
105
  return false unless instance.state == 'ACTIVE'
95
- @compute.stop_server(instance.id)
106
+ instance.stop
96
107
  end
97
108
 
98
- def create_instance(instance_name, image_id, flavor_id, keypair_name)
109
+ def create_instance(instance_name, image_id, flavor_id, keypair_name, *user_data)
110
+ user_data = nil if user_data.empty?
111
+
99
112
  instance = @compute.servers.create(name: instance_name,
100
113
  image_ref: image_id,
101
114
  flavor_ref: flavor_id,
102
- key_name: keypair_name)
115
+ key_name: keypair_name,
116
+ user_data: user_data)
117
+
103
118
  # add security_group
104
119
 
105
120
  # Put error handling from instance_prompts here
@@ -1,3 +1,3 @@
1
1
  module DanarchySys
2
- VERSION = "0.2.17"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danarchy_sys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.17
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan James
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-30 00:00:00.000000000 Z
11
+ date: 2017-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-openstack
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  requirements: []
146
146
  rubyforge_project:
147
- rubygems_version: 2.5.2
147
+ rubygems_version: 2.6.14
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: Facilitates the deployment and management of OpenStack.