pec 0.4.4 → 0.5.0

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.
@@ -27,7 +27,7 @@ module Pec
27
27
  thor.say("Start Configure by OpenStack", :yellow)
28
28
  params = {}
29
29
 
30
- params = %w(auth_url username api_key tenant identity_endpoint).inject({}) do |user_input, c|
30
+ params = %w(auth_url username api_key tenant).inject({}) do |user_input, c|
31
31
  user_input["openstack_#{c}"] = thor.ask("openstack #{c}:")
32
32
  user_input
33
33
  end
@@ -0,0 +1,21 @@
1
+ module Pec
2
+ class Logger
3
+ class << self
4
+ def notice(m)
5
+ puts m.white
6
+ end
7
+
8
+ def info(m)
9
+ puts m.green
10
+ end
11
+
12
+ def warning(m)
13
+ puts m.to_s.yellow
14
+ end
15
+
16
+ def critical(m)
17
+ puts m.to_s.magenta
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Pec
2
- VERSION = "0.4.4"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["pyama@pepabo.com"]
11
11
 
12
12
  spec.summary = %q{openstack vm booter.}
13
- spec.description = %q{openstac vm booter.}
13
+ spec.description = %q{openstack vm booter.}
14
14
  spec.homepage = "http://ten-snapon.com"
15
15
  spec.license = "MIT"
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kazuhiko yamashita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-21 00:00:00.000000000 Z
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description: openstac vm booter.
125
+ description: openstack vm booter.
126
126
  email:
127
127
  - pyama@pepabo.com
128
128
  executables:
@@ -143,31 +143,15 @@ files:
143
143
  - bin/setup
144
144
  - exe/pec
145
145
  - lib/pec.rb
146
+ - lib/pec/builder/port.rb
147
+ - lib/pec/builder/server.rb
148
+ - lib/pec/builder/user_data.rb
146
149
  - lib/pec/cli.rb
147
- - lib/pec/compute/flavor.rb
148
- - lib/pec/compute/image.rb
149
- - lib/pec/compute/server.rb
150
- - lib/pec/compute/tenant.rb
151
150
  - lib/pec/configure.rb
152
- - lib/pec/configure/ethernet.rb
153
- - lib/pec/configure/host.rb
154
- - lib/pec/configure/sample.rb
155
- - lib/pec/configure/user_data.rb
156
151
  - lib/pec/director.rb
157
- - lib/pec/director/destroy_director.rb
158
- - lib/pec/director/helper.rb
159
- - lib/pec/director/make_director.rb
160
- - lib/pec/director/vm_status_director.rb
161
152
  - lib/pec/errors.rb
162
153
  - lib/pec/init.rb
163
- - lib/pec/network/port.rb
164
- - lib/pec/network/port_state.rb
165
- - lib/pec/network/security_group.rb
166
- - lib/pec/network/subnet.rb
167
- - lib/pec/query.rb
168
- - lib/pec/resource.rb
169
- - lib/pec/resource/mock.rb
170
- - lib/pec/resource/openstack.rb
154
+ - lib/pec/logger.rb
171
155
  - lib/pec/version.rb
172
156
  - pec.gemspec
173
157
  homepage: http://ten-snapon.com
@@ -190,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
174
  version: '0'
191
175
  requirements: []
192
176
  rubyforge_project:
193
- rubygems_version: 2.4.6
177
+ rubygems_version: 2.2.2
194
178
  signing_key:
195
179
  specification_version: 4
196
180
  summary: openstack vm booter.
@@ -1,7 +0,0 @@
1
- module Pec
2
- class Compute
3
- class Flavor
4
- extend Query
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module Pec
2
- class Compute
3
- class Image
4
- extend Query
5
- end
6
- end
7
- end
@@ -1,30 +0,0 @@
1
- module Pec
2
- class Compute
3
- class Server
4
- extend Query
5
- class << self
6
- def create(name, image_ref, flavor_ref, options)
7
- response = Pec::Resource.get.create_server(name, image_ref, flavor_ref, options)
8
- raise(Pec::Errors::Host, "server_name:#{name} response err status:#{response[:status]}") unless response[:status] == 202
9
- puts "success create for server_name:#{name.to_s}".blue
10
-
11
- response.data[:body]["server"]["id"]
12
- end
13
-
14
- def exists?(server_name)
15
- fetch(server_name)
16
- end
17
-
18
- def destroy!(server_name)
19
- server = fetch(server_name)
20
- raise(Pec::Errors::Host, "server_name:#{server_name} is not fond!") unless server
21
- response = Pec::Resource.get.delete_server(server["id"]) if server
22
-
23
- raise(Pec::Errors::Host, "server_name:#{name} response err status:#{response[:status]}") unless response[:status] == 204
24
- puts "server_name:#{server_name} is deleted!".green
25
- true
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,16 +0,0 @@
1
- module Pec
2
- class Compute
3
- class Tenant
4
- extend Query
5
- class << self
6
- def get_name(id)
7
- begin
8
- list.find {|p| p["id"] == id }["name"]
9
- rescue
10
- Pec::Resource.get_tenant
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,81 +0,0 @@
1
- module Pec
2
- class Configure
3
- class Ethernet
4
- attr_reader :name, :bootproto, :ip_address, :options
5
- def initialize(name, config)
6
- check_require_key(name, config)
7
- check_network_key(name, config)
8
-
9
- @name = config[0];
10
- @bootproto = config[1]["bootproto"];
11
- @ip_address = config[1]["ip_address"];
12
- @options = config[1].reject do |k,v|
13
- { k => v } if k == "bootproto" || k == "ip_address"
14
- end
15
- end
16
-
17
- def get_port_content(ports)
18
- base = {
19
- "bootproto" => @bootproto,
20
- "name" => config_name,
21
- "device" => device_name,
22
- "type" => type,
23
- "onboot" => onboot,
24
- "hwaddr" => mac_address(ports),
25
- }
26
- base.merge!({ "netmask" => netmask(ports), "ipaddr" => port_ip_address(ports) }) if static?
27
- base.merge!(@options) if @options
28
- base.map {|k,v| "#{k.upcase}=#{v}"}.join("\n")
29
- end
30
-
31
-
32
- def config_name
33
- @options["name"] || @name
34
- end
35
-
36
- def device_name
37
- @options["device"] || @name
38
- end
39
-
40
- def type
41
- @options["type"] || 'Ethernet'
42
- end
43
-
44
- def onboot
45
- @options["onboot"] || 'yes'
46
- end
47
-
48
- def mac_address(ports)
49
- ports.find { |p| p.device_name == @name }.mac_address
50
- end
51
-
52
- def netmask(ports)
53
- ports.find { |p| p.device_name == @name }.netmask(@ip_address.split("/").last)
54
- end
55
-
56
- def port_ip_address(ports)
57
- ports.find { |p| p.device_name == @name }.ip_address
58
- end
59
-
60
- def static?
61
- @bootproto == "static"
62
- end
63
-
64
- def check_require_key(name, config)
65
- raise(Pec::Errors::Ethernet, "skip! #{name}: bootproto is required!") if config[1]["bootproto"].nil?
66
- true
67
- end
68
-
69
- def check_network_key(name, config)
70
- net = config[1]
71
- case
72
- when (net["bootproto"] == "static" && net["ip_address"].nil?)
73
- raise(Pec::Errors::Ethernet, "skip! #{name}: ip_address is required by bootproto static")
74
- when (net["bootproto"] != "static" && net["bootproto"] != "dhcp")
75
- raise(Pec::Errors::Ethernet, "skip! #{name}: bootproto set the value dhcp or static")
76
- end
77
- true
78
- end
79
- end
80
- end
81
- end
@@ -1,40 +0,0 @@
1
- module Pec
2
- class Configure
3
- class Host
4
- attr_reader :name, :image, :flavor,:security_group, :user_data, :networks, :templates, :tenant, :availability_zone
5
- def initialize(config)
6
- check_format(config)
7
- append_network(config[1])
8
- @name = config[0];
9
- @image = config[1]["image"];
10
- @flavor = config[1]["flavor"];
11
- @security_group = config[1]["security_group"];
12
- @user_data = config[1]["user_data"];
13
- @templates = config[1]["templates"]
14
- @tenant = config[1]["tenant"]
15
- @availability_zone = config[1]["availability_zone"]
16
- end
17
-
18
- def append_network(config)
19
- @networks ||= []
20
- config["networks"].each do |net|
21
- raise(Pec::Errors::Ethernet, "please! network interface format is Array") unless net.kind_of?(Array)
22
-
23
- if ethernet = Pec::Configure::Ethernet.new(config, net)
24
- @networks << ethernet
25
- end
26
-
27
- end if config["networks"]
28
- end
29
-
30
- def check_format(config)
31
- err = %w(image flavor tenant).find {|r| !config[1].key?(r) || config[1][r].nil? }
32
- raise(Pec::Errors::Host,"skip! #{config[0]}: #{err} is required!") unless err.nil?
33
-
34
- err = %w(security_group templates).find {|r| config[1].key?(r) && !config[1][r].kind_of?(Array) }
35
- raise(Pec::Errors::Host,"#{config[0]}: please! #{err} format is Array!") unless err.nil?
36
- true
37
- end
38
- end
39
- end
40
- end
@@ -1,55 +0,0 @@
1
- module Pec
2
- class Configure
3
- class Sample
4
- class << self
5
- def pec_file
6
- {
7
- "your_sever_name" => {
8
- "tenant" => "your_tenant",
9
- "image" => "centos-7",
10
- "flavor" => "m1.small",
11
- "networks" => {
12
- "eth0" => {
13
- "bootproto" => "static",
14
- "ip_address" => "10.0.0.0/24",
15
- "gateway" => "10.0.0.254",
16
- "dns1" => "10.0.0.10"
17
- },
18
- "eth1" => {
19
- "bootproto" => "static",
20
- "ip_address" => "20.0.0.11/24",
21
- "gateway" => "20.0.0.254",
22
- "dns1" => "20.0.0.10"
23
- }
24
- },
25
- "security_group" => [
26
- "default",
27
- "www from any"
28
- ],
29
- "templates" => [
30
- "web_server.yaml"
31
- ],
32
- "user_data" => {
33
- "hostname" => "pec",
34
- "fqdn" => "pec.pyama.com"
35
- }
36
- }
37
- }
38
- end
39
- def user_data
40
- {
41
- "hostname" => "pec",
42
- "fqdn" => "pec.pyama.com",
43
- "users" => [
44
- {
45
- "name" => "centos",
46
- "groups" => "sudo",
47
- "shell" => "/bin/sh"
48
- }
49
- ]
50
- }
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,36 +0,0 @@
1
- require 'base64'
2
- module Pec
3
- class Configure
4
- class UserData
5
- class << self
6
- def make(config, ports)
7
- user_data = {}
8
- user_data["write_files"] = make_port_content(config, ports) if ports
9
- user_data.deep_merge!(config.user_data) if config.user_data
10
- user_data.deep_merge!(get_template(config)) if get_template(config)
11
- Base64.encode64("#cloud-config\n" + user_data.to_yaml)
12
- end
13
-
14
- def get_template(config)
15
- config.templates.inject({}) do |merge_template, template|
16
- template.to_s.concat('.yaml') unless template.to_s.match(/.*\.yaml/)
17
- raise(Pec::Errors::UserData, "template:#{template} is not fond!") unless FileTest.exist?("user_data/#{template}")
18
- merge_template.deep_merge!(YAML.load_file("user_data/#{template}").to_hash)
19
- end if config.templates
20
- end
21
-
22
- def make_port_content(config, ports)
23
- config.networks.map do |ether|
24
- path = ether.options['path'] || "/etc/sysconfig/network-scripts/ifcfg-#{ether.name}"
25
- {
26
- 'content' => ether.get_port_content(ports),
27
- 'owner' => "root:root",
28
- 'path' => path,
29
- 'permissions' => "0644"
30
- }
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,23 +0,0 @@
1
- module Pec
2
- class Director
3
- class DestroyDirector
4
- def initialize(command_options)
5
- @command_options = command_options
6
- end
7
-
8
- def execute!(host)
9
- Pec::Resource.set_tenant(host.tenant)
10
- Pec::Compute::Server.destroy!(host.name)
11
- end
12
-
13
- def do_it?(host)
14
- @command_options[:force] || Thor.new.yes?("#{host.name}: Are you sure you want to destroy the '#{host.name}' VM? [y/N]")
15
- end
16
-
17
- def err_message(e, host)
18
- puts e.to_s.magenta
19
- puts "can't destroy server:#{host.name}".magenta if host
20
- end
21
- end
22
- end
23
- end
@@ -1,51 +0,0 @@
1
- module Pec
2
- class Director
3
- class Helper
4
- class << self
5
-
6
- def ports_assign(host)
7
- host.networks.map do |ether|
8
- ip = IP.new(ether.ip_address)
9
-
10
- unless port_subnet = Pec::Network::Subnet.fetch_by_cidr(ip.network.to_s)
11
- raise(Pec::Errors::Subnet, "subnet:#{ip.network.to_s} is not fond!")
12
- end
13
-
14
- unless port = Pec::Network::Port.assign(ether.name, ip, port_subnet, get_security_group_id(host.security_group))
15
- raise(Pec::Errors::Port, "ip addess:#{ip.to_addr} can't create port!")
16
- end
17
-
18
- puts "#{host.name}: assingn ip #{port.ip_address}".green
19
- port
20
- end if host.networks
21
- rescue ArgumentError => e
22
- raise(Pec::Errors::Port, "ip:#{ether.ip_address} #{e}")
23
- end
24
-
25
- def set_nics(options, ports)
26
- ports ? options.merge({ 'nics' => ports.map { |port| { port_id: port.id } } }) : options
27
- end
28
-
29
- def set_availability_zone(options, host)
30
- host.availability_zone ? options.merge({ 'availability_zone' => host.availability_zone }) : options
31
- end
32
-
33
- def get_security_group_id(security_groups)
34
- security_groups.map do |sg_name|
35
- sg = Pec::Network::Security_Group.fetch(sg_name)
36
- raise(Pec::Errors::SecurityGroup, "security_group:#{sg_name} is not found!") unless sg
37
- sg["id"]
38
- end if security_groups
39
- end
40
-
41
- def parse_from_addresses(addresses)
42
- addresses.map do |net, ethers|
43
- ethers.map do |ether|
44
- ether["addr"]
45
- end
46
- end.flatten
47
- end
48
- end
49
- end
50
- end
51
- end