builddog 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01ddccf468deadf7187248349a10a5932c2ef7f0
4
+ data.tar.gz: 1f97888e22968e6d7164f9124c4e9c8bcb7d3b48
5
+ SHA512:
6
+ metadata.gz: e3c0a56ccadf894639256c5631ca3bd9745baecfe94827534f9be9cbfd63d6b09c955b1a31f0c08c7d589e8c65f9e1f901d3935580cf52a1e01bd4eb7bc65b2c
7
+ data.tar.gz: c467c8cd42878b2633b252afd94de0b147d11615f00decd233679614a7d673e87e9cdf6989a01c53ec6d46d270cf24d4f5681fcc3084be69d93f0303e320f30c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ tmp/
16
+ *bdg_inventory.yaml*
17
+ *bdg_credentials.yaml*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in builddog.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 rboyapat
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Builddog
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'builddog'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install builddog
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/rboyapat/builddog/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/builddog ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'builddog'))
data/builddog.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'builddog/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "builddog"
8
+ spec.version = BuildDog::VERSION
9
+ spec.authors = ["rboyapat"]
10
+ spec.email = ["rboyapat@gmail.com"]
11
+ spec.summary = %q{ruby library to deploy servers across datacenters}
12
+ spec.description = %q{---}
13
+ spec.homepage = "http://github.com/rboyapat/builddog"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
data/lib/builddog.rb ADDED
@@ -0,0 +1,43 @@
1
+ require_relative "builddog/version"
2
+ require_relative "builddog/trollop"
3
+ require_relative "builddog/providers"
4
+
5
+ module BuildDog
6
+
7
+ def self.print
8
+ puts "#{VERSION}"
9
+ end
10
+ end
11
+
12
+
13
+
14
+ options = Trollop.options do
15
+
16
+ banner <<-EOS
17
+ Usage: builddog.rb -o vm_create --provisioner 10.0.0.1 -u admin -p password
18
+ builddog.rb --operation vm_create --provisioner 10.0.0.1 --user admin --password password
19
+ EOS
20
+
21
+ builddog_opt
22
+ end
23
+
24
+ ###
25
+
26
+ Label1 = <<EOF
27
+
28
+ Logic to check what and how many arguments are passed to program
29
+
30
+ if options.length > 0
31
+ open instance of class
32
+
33
+ elsif File.open("buildog_credentials", "r")
34
+
35
+ else
36
+
37
+
38
+ fi
39
+
40
+ EOF
41
+ #####
42
+
43
+ BuildDog.providers options
@@ -0,0 +1,19 @@
1
+ module BuildDog
2
+
3
+ require 'yaml'
4
+ require 'ipaddress'
5
+ require_relative "providers/vsphere"
6
+ require_relative "providers/aws"
7
+
8
+ def self.providers ( options )
9
+ case options[:provider]
10
+ when "vsphere"
11
+ vsphere options
12
+ when "aws"
13
+ aws options
14
+ else
15
+ puts "unknown provider"
16
+ end
17
+ end
18
+
19
+ end
File without changes
File without changes
@@ -0,0 +1,27 @@
1
+ require 'rbvmomi'
2
+
3
+ module RbVmomi
4
+ class VIM
5
+ end
6
+ end
7
+
8
+ require_relative "vsphere/vm_create"
9
+ require_relative "vsphere/vm_clone"
10
+
11
+ def vsphere options
12
+
13
+ options[:host] = options[:controller]
14
+ options[:insecure] = true
15
+
16
+ case options[:operation]
17
+ when "vm_create"
18
+ puts "creating a vm"
19
+ vm_create options
20
+ when "vm_clone"
21
+ puts "cloning a vm"
22
+ vm_clone options
23
+ else
24
+ puts "wrong vm operation"
25
+ end
26
+
27
+ end
@@ -0,0 +1,10 @@
1
+ def vm_clone opts
2
+ clone_name = opts[:clone_name]
3
+ vm_name = opts[:vm_name]
4
+ vim = RbVmomi::VIM.connect opts
5
+ dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "Datacenter not found"
6
+ vm = dc.find_vm(clone_name) or abort "VM not found"
7
+ relocateSpec = RbVmomi::VIM.VirtualMachineRelocateSpec
8
+ spec = RbVmomi::VIM.VirtualMachineCloneSpec(:location => relocateSpec, :powerOn => false, :template => false)
9
+ vm.CloneVM_Task(:folder => vm.parent, :name => vm_name, :spec => spec).wait_for_completion
10
+ end
@@ -0,0 +1,65 @@
1
+ def vm_create opts
2
+
3
+ vm_name = opts[:vm_name]
4
+ guest_id = opts[:guest_id]
5
+ vm_cpu = opts[:vm_cpu]
6
+ vm_memory = opts[:vm_memory]
7
+ vm_disk = opts[:vm_disk]
8
+ vm_cluster = opts[:vm_cluster]
9
+ vm_datastore = opts[:vm_datastore]
10
+ vm_pg = opts[:vm_pg]
11
+
12
+ vim = RbVmomi::VIM.connect opts
13
+ dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "Datacenter not found"
14
+ vmFolder = dc.vmFolder
15
+ bd_cluster=" "
16
+ dc.hostFolder.children.each do |cluster|
17
+ if cluster.name == "#{vm_cluster}"
18
+ bd_cluster=cluster
19
+ end
20
+ end
21
+
22
+ rp = bd_cluster.resourcePool
23
+
24
+ dvsm = vim.serviceContent.dvSwitchManager
25
+ bd_host = bd_cluster.host[rand(bd_cluster.host.length)]
26
+ bd_vswitch = dvsm.QueryDvsConfigTarget(:host => bd_host).distributedVirtualPortgroup
27
+ bd_pg = ""
28
+ bd_switch_uuid = ""
29
+ bd_switch_name = ""
30
+ bd_pgkey = ""
31
+ bd_vswitch.each { |t_pg|
32
+ if t_pg.portgroupName.to_s == "#{vm_pg}"
33
+ bd_pg = t_pg.portgroupName
34
+ bd_switch_uuid = t_pg.switchUuid
35
+ bd_switch_name = t_pg.switchName
36
+ bd_pgkey = t_pg.portgroupKey
37
+ end
38
+ }
39
+
40
+ vm_cfg = {
41
+ :name => vm_name,
42
+ :guestId => guest_id,
43
+ :files => { :vmPathName => "[#{vm_datastore}]" },
44
+ :numCPUs => vm_cpu,
45
+ :memoryMB => vm_memory,
46
+ :deviceChange => [
47
+ {
48
+ :operation => :add,
49
+ :device => RbVmomi::VIM.VirtualLsiLogicController( :key => 1000, :busNumber => 0, :sharedBus => :noSharing)
50
+ },
51
+ {
52
+ :operation => :add,
53
+ :fileOperation => :create,
54
+ :device => RbVmomi::VIM.VirtualDisk( :key => 0, :backing => RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo( :fileName => "[#{vm_datastore}]", :diskMode => :persistent, :thinProvisioned => true), :controllerKey => 1000, :unitNumber => 0, :capacityInKB => vm_disk )
55
+ },
56
+ {
57
+ :operation => :add,
58
+ :device => RbVmomi::VIM.VirtualE1000( :key => -1, :deviceInfo => { :label => 'Network Adapter 1', :summary => bd_pg }, :backing => RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo( :port => RbVmomi::VIM.DistributedVirtualSwitchPortConnection( :portgroupKey => bd_pgkey, :switchUuid => bd_switch_uuid)), :addressType => 'generated')
59
+ }
60
+ ],
61
+ :extraConfig => [ { :key => 'bios.bootOrder', :value => 'ethernet0' } ]
62
+ }
63
+
64
+ vmFolder.CreateVM_Task(:config => vm_cfg, :pool => rp).wait_for_completion
65
+ end
@@ -0,0 +1,38 @@
1
+ require 'trollop'
2
+
3
+ module Trollop
4
+
5
+ class Parser
6
+
7
+ def builddog_opt
8
+ opt :provider, "Server Provider", :type => :string, :short => :none, :default => 'vsphere'
9
+ opt :controller, "Server Provisioning System Controller", :type => :string, :short => :none, :default => 'none'
10
+ opt :port, "Controller port", :type => :int, :short => :none, :default => 443
11
+ opt :user, "Username", :type => :string, :short => 'u', :default => 'none'
12
+ opt :password, "Password", :type => :string, :short => 'p', :default => 'none'
13
+ opt :operation, "Operation", :type => :string, :short => 'o', :default => 'none'
14
+ opt :vm_name, "VM name", :type => :string, :short => :none, :default => "bdg_testvm"
15
+ opt :guest_id, "VM OS type", :type => :string, :short => :none, :default => "rhel6_64Guest"
16
+ opt :vm_cpu, "VM No of vCPUs", :type => :int, :short => :none, :default => 1
17
+ opt :vm_memory, "VM Memory in MB", :type => :int, :short => :none, :default => 2048
18
+ opt :vm_disk, "VM Disk Capacity in KB", :type => :int, :short => :none, :default => 4000000
19
+ opt :vm_cluster, "VM Build Cluster", :type => :string, :short => :none, :default => "bdg_cluster01"
20
+ opt :vm_datastore, "VM Build Datastore", :type => :string, :short => :none, :default => "bdg_nasstore01"
21
+ opt :vm_pg, "VM Build NW PortGroup", :type => :string, :short => :none, :default => "bdg_dvVMNetwork-PG"
22
+ opt :vm_ip, "VM IP", :type => :string, :short => :none, :default => 'none'
23
+ opt :vm_subnet, "VM Subnet", :type => :string, :short => :none, :default => 'none'
24
+ opt :vm_netmask, "VM Netmask", :type => :string, :short => :none, :default => 'none'
25
+ opt :vm_gw, "VM Gateway", :type => :string, :short => :none, :default => 'none'
26
+ opt :vm_domain, "VM Domain Name", :type => :string, :short => :none, :default => "builddog.com"
27
+ opt :vm_dns_servers, "VM DNS servers", :type => :string, :short => :none, :default => 'none'
28
+ opt :clone_name, "VM Clone Source Name", :type => :string, :short => :none, :default => "bdg_cln"
29
+ opt :template_name, "VM template Name", :type => :string, :short => :none, :default => "bdg_tmpt"
30
+ opt :datacenter, "VM Datacenter", :type => :string, :short => :none, :default => "bdg"
31
+ opt :inventory, "Datacenter Inventory File", :type => :string, :short => :none, :default => "~/.bdg_inventory.yaml"
32
+ opt :credentials, "Provisioner Credentials File", :type => :string, :short => :none, :default => "~/.bdg_credentials.yaml"
33
+ opt :vmlist, "VM Build List File", :type => :string, :short => :none, :default => "./bdg_vmlist"
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,3 @@
1
+ module BuildDog
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: builddog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - rboyapat
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: "---"
42
+ email:
43
+ - rboyapat@gmail.com
44
+ executables:
45
+ - builddog
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/builddog
55
+ - builddog.gemspec
56
+ - lib/builddog.rb
57
+ - lib/builddog/providers.rb
58
+ - lib/builddog/providers/aws.rb
59
+ - lib/builddog/providers/openstack.rb
60
+ - lib/builddog/providers/vsphere.rb
61
+ - lib/builddog/providers/vsphere/vm_clone.rb
62
+ - lib/builddog/providers/vsphere/vm_create.rb
63
+ - lib/builddog/trollop.rb
64
+ - lib/builddog/version.rb
65
+ homepage: http://github.com/rboyapat/builddog
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.2.5
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: ruby library to deploy servers across datacenters
89
+ test_files: []