vop-plugins 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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +50 -0
  3. data/.project +23 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +68 -0
  6. data/Rakefile +6 -0
  7. data/standard/debian-iso/commands/fetch_debian_iso.rb +3 -0
  8. data/standard/debian-iso/commands/fetch_ubuntu_iso.rb +22 -0
  9. data/standard/debian-iso/commands/list_isos.rb +6 -0
  10. data/standard/debian-iso/commands/rebuild_debian_iso.rb +40 -0
  11. data/standard/debian-iso/debian-iso.plugin +2 -0
  12. data/standard/debian-iso/files/rebuild-debian-iso +74 -0
  13. data/standard/debian-iso/templates/preseed.cfg +45 -0
  14. data/standard/libvirt/commands/delete_vm.rb +16 -0
  15. data/standard/libvirt/commands/list_local_vms.rb +4 -0
  16. data/standard/libvirt/commands/list_vms.rb +15 -0
  17. data/standard/libvirt/commands/new_vm.rb +61 -0
  18. data/standard/libvirt/commands/start_vm.rb +6 -0
  19. data/standard/libvirt/commands/stop_vm.rb +6 -0
  20. data/standard/libvirt/libvirt.plugin +2 -0
  21. data/standard/linux/commands/disk_free.rb +26 -0
  22. data/standard/linux/commands/disk_used.rb +4 -0
  23. data/standard/linux/commands/distro.rb +19 -0
  24. data/standard/linux/commands/download_file.rb +17 -0
  25. data/standard/linux/commands/find.rb +15 -0
  26. data/standard/linux/commands/list_files.rb +19 -0
  27. data/standard/linux/commands/listen_ports.rb +18 -0
  28. data/standard/linux/commands/mkdir.rb +6 -0
  29. data/standard/linux/commands/processes.rb +33 -0
  30. data/standard/linux/commands/processes_like.rb +11 -0
  31. data/standard/linux/commands/read_file.rb +6 -0
  32. data/standard/linux/commands/write_file.rb +26 -0
  33. data/standard/linux/helpers/regex.rb +50 -0
  34. data/standard/linux/linux.plugin +2 -0
  35. data/standard/linux/todo +2 -0
  36. data/standard/machines/commands/list_machines_old.rb +7 -0
  37. data/standard/machines/commands/localhost.rb +3 -0
  38. data/standard/machines/commands/machine.rb +3 -0
  39. data/standard/machines/commands/run_command.rb +10 -0
  40. data/standard/machines/commands/select_machine.rb +8 -0
  41. data/standard/machines/machines.plugin +1 -0
  42. data/standard/plugin.vop +1 -0
  43. data/standard/services/loader/service.rb +3 -0
  44. data/standard/vagrant/commands/vagrant_global_status.rb +32 -0
  45. data/standard/vagrant/vagrant.plugin +1 -0
  46. data/standard/working_copies/commands/git_working_copies.rb +11 -0
  47. data/standard/working_copies/commands/list_project_folders.rb +8 -0
  48. data/standard/working_copies/commands/working_copy.rb +3 -0
  49. data/standard/working_copies/working_copies.plugin +1 -0
  50. data/vop-plugins.gemspec +24 -0
  51. metadata +149 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dccf1f897586ad21a75f282c0fae260a0d313d2b
4
+ data.tar.gz: 2b3c97ca568c9db21ebc8db4a77a9d4d4475e476
5
+ SHA512:
6
+ metadata.gz: 4f3546550acdef0a6c61468a66cd2b1497eb0a373dfafdb12df11f7f64700af3275bed8cf6addc300526684e28965bf864cfdf73aea42f775b4523f157dd4edd
7
+ data.tar.gz: d67584ce8c0cf94c1180b88ff943d2bca40032d80c22cb4f90790ec619268215ea7d0cbc64d21f8d1c6da95d2c39d8560a6b66c830e23554b34818c8d597364a
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.project ADDED
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>plugins</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
10
+ <triggers>full,incremental,</triggers>
11
+ <arguments>
12
+ <dictionary>
13
+ <key>LaunchConfigHandle</key>
14
+ <value>&lt;project&gt;/.externalToolBuilders/com.aptana.ide.core.unifiedBuilder.launch</value>
15
+ </dictionary>
16
+ </arguments>
17
+ </buildCommand>
18
+ </buildSpec>
19
+ <natures>
20
+ <nature>com.aptana.ruby.core.rubynature</nature>
21
+ <nature>org.rubypeople.rdt.core.rubynature</nature>
22
+ </natures>
23
+ </projectDescription>
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vop-plugins (0.3.1)
5
+ vop (>= 0.3.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activesupport (5.0.0.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (~> 0.7)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ coderay (1.1.1)
16
+ concurrent-ruby (1.0.3)
17
+ diff-lcs (1.2.5)
18
+ docopt (0.5.0)
19
+ i18n (0.7.0)
20
+ method_source (0.8.2)
21
+ minitest (5.10.1)
22
+ net-scp (1.2.1)
23
+ net-ssh (>= 2.6.5)
24
+ net-ssh (3.2.0)
25
+ pry (0.10.4)
26
+ coderay (~> 1.1.0)
27
+ method_source (~> 0.8.1)
28
+ slop (~> 3.4)
29
+ rake (12.0.0)
30
+ rspec (3.4.0)
31
+ rspec-core (~> 3.4.0)
32
+ rspec-expectations (~> 3.4.0)
33
+ rspec-mocks (~> 3.4.0)
34
+ rspec-core (3.4.4)
35
+ rspec-support (~> 3.4.0)
36
+ rspec-expectations (3.4.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.4.0)
39
+ rspec-mocks (3.4.1)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.4.0)
42
+ rspec-support (3.4.1)
43
+ slop (3.6.0)
44
+ terminal-table (1.7.3)
45
+ unicode-display_width (~> 1.1.1)
46
+ thread_safe (0.3.5)
47
+ tzinfo (1.2.2)
48
+ thread_safe (~> 0.1)
49
+ unicode-display_width (1.1.2)
50
+ vop (0.3.1)
51
+ activesupport
52
+ docopt
53
+ net-scp
54
+ net-ssh
55
+ pry
56
+ terminal-table
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ bundler (~> 1.10)
63
+ rake
64
+ rspec
65
+ vop-plugins!
66
+
67
+ BUNDLED WITH
68
+ 1.10.6
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ run do
2
+ # http://cdimage.debian.org/debian-cd/8.5.0/amd64/iso-cd/debian-8.5.0-amd64-netinst.iso
3
+ end
@@ -0,0 +1,22 @@
1
+ param! 'machine'
2
+ param! 'dir'
3
+
4
+ param! 'version', :default => '16.04'
5
+
6
+ run do |machine, dir, version|
7
+ # sigh
8
+ urls = {
9
+ '16.04' => 'http://releases.ubuntu.com/16.04/ubuntu-16.04-server-amd64.iso',
10
+ '14.04' => 'http://releases.ubuntu.com/14.04/ubuntu-14.04.4-server-amd64.iso'
11
+ }
12
+ url = urls[version]
13
+ unless url
14
+ url = "http://releases.ubuntu.com/%s/ubuntu-%s-server-amd64.iso" % [version, version]
15
+ end
16
+
17
+ file_name = url.split('/').last
18
+ machine.download_file(
19
+ url: url,
20
+ file: "#{dir}/#{file_name}"
21
+ )
22
+ end
@@ -0,0 +1,6 @@
1
+ param! 'machine'
2
+ param! 'dir'
3
+
4
+ run do |machine, dir|
5
+ machine.list_files(dir: dir)
6
+ end
@@ -0,0 +1,40 @@
1
+ param! 'machine'
2
+ param! 'source'
3
+ param 'just_kidding'
4
+
5
+ run do |machine, plugin, source, just_kidding = false|
6
+ puts "plugin : #{plugin.plugin_dir('files')}"
7
+
8
+ # upload the script to rebuild
9
+ machine.scp(
10
+ "local_path" => plugin.plugin_dir('files') + "/rebuild-debian-iso",
11
+ "remote_path" => "/tmp/rebuild-debian-iso"
12
+ )
13
+
14
+ # prepare preseed.cfg
15
+ machine.ssh("ls /tmp/iso-rebuild || mkdir /tmp/iso-rebuild")
16
+ # TODO might want to actually evaluate the template
17
+ machine.scp(
18
+ "local_path" => plugin.plugin_dir('templates') + "/preseed.cfg",
19
+ "remote_path" => "/tmp/iso-rebuild/preseed.cfg"
20
+ )
21
+
22
+ # figure out names
23
+ source_parts = source.split(".")
24
+ source_parts.pop
25
+ source_parts << "rebuilt"
26
+ source_parts << "iso"
27
+ target = source_parts.join(".")
28
+
29
+ # run and grep the filename from the output
30
+ rebuild_cmd = "/tmp/rebuild-debian-iso #{source} #{target} /tmp/iso-rebuild/preseed.cfg"
31
+ if just_kidding
32
+ puts "[noop] would run >>#{rebuild_cmd}<<"
33
+ else
34
+ output = machine.ssh("command" => rebuild_cmd, "user" => "root")
35
+ matched = /Output ISO generated:\s+(.+)/m.match(output)
36
+ matched.captures.first
37
+
38
+ # TODO chown the resulting ISO?
39
+ end
40
+ end
@@ -0,0 +1,2 @@
1
+ depends :core
2
+ depends :machines
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # from https://github.com/cdown/rebuild-debian-iso
4
+
5
+ shopt -s globstar
6
+
7
+ input_iso=$1
8
+ output_iso=$2
9
+ preseed=$3
10
+ input_file_dir=$4
11
+
12
+ msg() {
13
+ printf '>>> %s\n' "$@"
14
+ }
15
+
16
+ if ! [[ -r $input_iso && -r $preseed ]]; then
17
+ printf '%s\n' \
18
+ "Usage: ${0##*/} <input-iso> <output-iso> <preseed-file> [file-dir]" \
19
+ "" \
20
+ "input-iso: the debian iso to modify" \
21
+ "output-iso: where to store the modified iso" \
22
+ "preseed-file: the location of a preseed file to inject" \
23
+ "file-dir: an optional directory to be put at extra/ in the iso"
24
+ exit 1
25
+ fi
26
+
27
+ iso_dir=$(mktemp -d)
28
+ initrd_dir=$(mktemp -d)
29
+
30
+ msg "Extracting source image"
31
+ bsdtar -C "$iso_dir" -xf "$input_iso"
32
+
33
+ ls $iso_dir/install
34
+ initrd=$iso_dir/install/initrd.gz
35
+
36
+ (
37
+ cd "$initrd_dir"
38
+ msg "Extracting initrd"
39
+ gzip -d < "$initrd" | cpio -i --no-absolute-filenames
40
+ )
41
+
42
+ msg "Injecting preseed"
43
+ cp "$preseed" "$initrd_dir/preseed.cfg"
44
+
45
+ (
46
+ msg "Rebuilding initrd"
47
+ cd "$initrd_dir"
48
+ find . -print0 | cpio -H newc -o -0 | gzip -9 > "$initrd"
49
+ )
50
+
51
+ msg "Setting up automatic booting to preseed"
52
+ sed -i 's/timeout 0/timeout 5/' "$iso_dir/isolinux/isolinux.cfg"
53
+ sed -i '/^\tappend/d' "$iso_dir/isolinux/txt.cfg"
54
+ printf '\tappend vga=788 initrd=/install.amd/initrd.gz auto text\n' >> "$iso_dir/isolinux/txt.cfg"
55
+
56
+ if [[ $input_file_dir ]]; then
57
+ msg "Adding custom files to 'extra' dir on image"
58
+ cp -a "$input_file_dir" "$iso_dir/extra"
59
+ fi
60
+
61
+ msg "Generating md5sums"
62
+ ( cd "$iso_dir" && find . -type f -exec md5sum {} + > md5sum.txt )
63
+
64
+ msg "Generating output ISO image"
65
+ mkisofs -quiet \
66
+ -o "$output_iso" \
67
+ -r -J -no-emul-boot -boot-load-size 4 -boot-info-table \
68
+ -b isolinux/isolinux.bin -c isolinux/boot.cat \
69
+ "$iso_dir"
70
+
71
+ msg "Removing temporary directories"
72
+ rm -rf "$iso_dir" "$initrd_dir"
73
+
74
+ msg "Output ISO generated: $output_iso"
@@ -0,0 +1,45 @@
1
+ ## Options to set on the command line
2
+ d-i keyboard-configuration/layoutcode string de
3
+ d-i debian-installer/locale string en_US
4
+ d-i console-setup/ask_detect boolean false
5
+ d-i console-setup/layoutcode string us
6
+ d-i netcfg/choose_interface select eth0
7
+ d-i base-installer/kernel/override-image string linux-server
8
+ d-i clock-setup/utc-auto boolean true
9
+ d-i clock-setup/utc boolean true
10
+ d-i time/zone string US/Pacific
11
+ d-i clock-setup/ntp boolean true
12
+ d-i mirror/country string US
13
+ d-i mirror/http/proxy string
14
+ d-i mirror/http/mirror select mirror.facebook.net
15
+ d-i pkgsel/install-language-support boolean false
16
+ d-i pkgsel/update-policy select none
17
+ d-i tasksel/first select OpenSSH server
18
+ d-i netcfg/get_hostname string unassigned-hostname
19
+ d-i netcfg/get_domain string unassigned-domain
20
+ d-i partman-auto/method string lvm
21
+ d-i partman-lvm/device_remove_lvm boolean true
22
+ d-i partman-md/device_remove_md boolean true
23
+ d-i partman-lvm/confirm boolean true
24
+ d-i partman-lvm/confirm_nooverwrite boolean true
25
+ d-i partman-auto-lvm/guided_size string max
26
+ d-i partman-auto/choose_recipe select atomic
27
+ d-i partman/default_filesystem string xfs
28
+ d-i partman-partitioning/confirm_write_new_label boolean true
29
+ d-i partman/choose_partition select finish
30
+ d-i partman/confirm boolean true
31
+ d-i partman/confirm_nooverwrite boolean true
32
+ d-i partman-md/confirm boolean true
33
+ d-i partman-partitioning/confirm_write_new_label boolean true
34
+ d-i partman/choose_partition select finish
35
+ d-i partman/confirm boolean true
36
+ d-i partman/confirm_nooverwrite boolean true
37
+ d-i partman/unmount_active boolean false
38
+ d-i passwd/make-user boolean false
39
+ d-i passwd/root-password password foobar123
40
+ d-i passwd/root-password-again password foobar123
41
+ d-i passwd/root-login boolean true
42
+ d-i user-setup/encrypt-home boolean false
43
+ d-i grub-installer/only_debian boolean true
44
+ d-i grub-installer/with_other_os boolean true
45
+ d-i finish-install/reboot_in_progress note
@@ -0,0 +1,16 @@
1
+ param! "machine", :description => "the host machine on which the VM lives"
2
+ param! "name"
3
+
4
+ run do |machine, name|
5
+ vm_row = machine.list_vms.select { |x| x[:name] == name }.first
6
+
7
+ raise "VM not found in list_vms" unless vm_row
8
+
9
+ if vm_row[:state] == 'running'
10
+ machine.stop_vm(name: name)
11
+ end
12
+
13
+ machine.ssh("virsh undefine #{name}")
14
+
15
+ # TODO cleanup volumes
16
+ end
@@ -0,0 +1,4 @@
1
+ #contribute :to => 'machine' do
2
+ run do
3
+ @op.list_vms('localhost')
4
+ end
@@ -0,0 +1,15 @@
1
+ param! 'machine'
2
+
3
+ #contribute :to => 'machine' do |machine|
4
+ run do |machine|
5
+ output = machine.ssh 'virsh list --all'
6
+
7
+ data = output.strip.lines[2,output.length-1]
8
+ data.map do |line|
9
+ (unused_id, name, *state) = line.strip.split
10
+ {
11
+ name: name,
12
+ state: state.join(" ")
13
+ }
14
+ end
15
+ end
@@ -0,0 +1,61 @@
1
+ param! 'machine'
2
+ param! 'name', :default_param => true
3
+
4
+ param 'memory_size'
5
+ param 'cpu_count'
6
+ param 'os_variant'
7
+ param 'os_type'
8
+ param 'location'
9
+ param 'cdrom'
10
+ param 'extra_args'
11
+ param 'disk_size'
12
+
13
+ param 'vnc_password'
14
+ param 'vnc_listen'
15
+
16
+ run do |params, name, machine|
17
+ pp params
18
+
19
+ memory_size ||= 512
20
+ cpu_count ||= 1
21
+ os_variant ||= 'virtio26'
22
+ os_type ||= 'linux'
23
+ disk_size ||= 25
24
+
25
+ image_dir = "/var/lib/libvirt/images"
26
+ image_path = "#{image_dir}/#{name}.img"
27
+
28
+ command = "virt-install --name '#{name}' --ram #{memory_size} --vcpus=#{cpu_count}" +
29
+ " --accelerate --os-variant=#{os_variant} --os-type=#{os_type}"
30
+
31
+ command += " --disk path=#{image_path},size=#{disk_size},sparse=false,cache=none"
32
+
33
+ if params.has_key?('cdrom')
34
+ command += " --cdrom=#{params['cdrom']}"
35
+ end
36
+
37
+ if params.has_key?('location')
38
+ command += " --location #{params["location"]}"
39
+ if params.has_key?('extra_arg')
40
+ command += " --extra-args=\""
41
+ params['extra_arg'].each do |extra_arg|
42
+ command += " #{extra_arg}"
43
+ end
44
+ command += "\""
45
+ end
46
+ end
47
+
48
+ if params.has_key?("vnc_password")
49
+ command += " --graphics vnc,password=#{params["vnc_password"]}"
50
+ elsif params.has_key?("vnc_listen")
51
+ command += " --graphics vnc,listen=#{params["vnc_listen"]}"
52
+ else
53
+ command += " --nographics"
54
+ end
55
+ command += " --noautoconsole"
56
+
57
+ puts "command: >>#{command}<<"
58
+ machine.ssh("command" => command, "user" => "root")
59
+
60
+ command
61
+ end
@@ -0,0 +1,6 @@
1
+ param! "machine", :description => "the host machine on which the VM lives"
2
+ param! "name"
3
+
4
+ run do |machine, name|
5
+ machine.ssh("virsh start #{name}")
6
+ end
@@ -0,0 +1,6 @@
1
+ param! "machine", :description => "the host machine on which the VM lives"
2
+ param! "name"
3
+
4
+ run do |machine, name|
5
+ machine.ssh("virsh destroy #{name}")
6
+ end
@@ -0,0 +1,2 @@
1
+ depends :core
2
+ depends :machines
@@ -0,0 +1,26 @@
1
+ param! :machine
2
+ param "dir"
3
+
4
+ run do |machine, params|
5
+ command = "df -hl"
6
+ if params.has_key? "dir"
7
+ command += " #{params["dir"]}"
8
+ end
9
+
10
+ machine.ssh(command).split("\n")[1..-1].map do |line|
11
+ (path, size, used, available, percent, mount_point) = line.split
12
+ {
13
+ :path => path,
14
+ :size => size,
15
+ :used => used,
16
+ :available => available,
17
+ :percent => percent,
18
+ :mount_point => mount_point
19
+ }
20
+ end
21
+ end
22
+
23
+ __END__
24
+
25
+ # Filesystem Size Used Avail Use% Mounted on
26
+ # /dev/sda8 481G 283G 174G 62% /data
@@ -0,0 +1,4 @@
1
+ run do
2
+ puts "foo"
3
+
4
+ end
@@ -0,0 +1,19 @@
1
+ description "tries to return a meaningful string for the linux distribution running on this machine"
2
+
3
+ param! :machine
4
+
5
+ # TODO mark_as_read_only
6
+
7
+ run do |machine, params|
8
+ input = machine.ssh("cat /etc/issue")
9
+
10
+ input.strip!
11
+ first_line = input.split("\n").first
12
+ result = 'unknown'
13
+ if (matched = /SUSE\s+Linux\s+Enterprise\s+Server\s(\d+)\s+(SP\d+)?/.match(first_line))
14
+ result = 'sles_' + matched.captures[0] + ' ' + matched.captures[1]
15
+ elsif matched = /(\w+)[^\d]+([\d\.]+)/.match(first_line)
16
+ result = matched.captures.first.downcase + '_' + matched.captures[1]
17
+ end
18
+ result
19
+ end
@@ -0,0 +1,17 @@
1
+ param! 'machine'
2
+ param! 'url'
3
+ param! 'file'
4
+
5
+ run do |machine, url, file|
6
+ has_curl = machine.ssh("which curl")
7
+
8
+ puts "has_curl: #{has_curl}"
9
+ raise "no curl" unless has_curl
10
+
11
+ command = "curl --silent --location"
12
+ command += " --create-dirs -o #{file}"
13
+ command += " #{url}"
14
+
15
+ puts "command: #{command}"
16
+ machine.ssh(command)
17
+ end
@@ -0,0 +1,15 @@
1
+ param! 'machine'
2
+ param! 'path'
3
+ param 'type'
4
+ param 'name'
5
+ param 'maxdepth'
6
+
7
+ run do |machine, path, params|
8
+ path += "/" unless /\/$/ =~ path
9
+ find_command = "find #{path}"
10
+ find_command += " -maxdepth #{params["maxdepth"]}" if params.key? "maxdepth"
11
+ find_command += " -type #{params["type"]}" if params.key? "type"
12
+ find_command += " -name #{params["name"]}" if params.key? "name"
13
+ $logger.debug find_command
14
+ machine.ssh(find_command).split("\n")
15
+ end
@@ -0,0 +1,19 @@
1
+ param! 'machine'
2
+ param! 'dir'
3
+
4
+ show columns: %i|name owner group permissions size timestamp|
5
+
6
+ run do |machine, dir|
7
+ ssh_regex(machine, "ls -l --full-time #{dir}",
8
+ # drwxrwxr-x 3 philipp philipp 4096 2016-01-16 04:16:24.621111156 +0100 lib
9
+ /(\S+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d+)\s+([\d-]+)\s+([\d:]+)\.\d+\s+(\+\d+)\s+(.+)$/,
10
+ %i|permissions links owner group size date time time_zone name|,
11
+ {
12
+ :post_process => lambda { |parsed|
13
+ date, time, zone = parsed.delete(:date), parsed.delete(:time), parsed.delete(:time_zone)
14
+ parsed[:timestamp] = "#{date} #{time} #{zone}"
15
+ parsed
16
+ }
17
+ }
18
+ )
19
+ end
@@ -0,0 +1,18 @@
1
+ param! 'machine'
2
+
3
+ run do |machine|
4
+ input = machine.ssh("ss -tnl")
5
+
6
+ result = Hash.new { |h,k| h[k] = [] }
7
+
8
+ # State Recv-Q Send-Q Local Address:Port Peer Address:Port
9
+ # LISTEN 0 128 *:111 *:*
10
+ input.split("\n")[1..-1].map do |line|
11
+ (state, recvq, sendq, local, peer) = line.split()
12
+ parts = local.split(':')
13
+ (listen_address, listen_port) = parts[0..-2].join(':'), parts.last.to_i
14
+ result[listen_port] << listen_address
15
+ end
16
+
17
+ result
18
+ end
@@ -0,0 +1,6 @@
1
+ param! 'machine'
2
+ param! 'dir'
3
+
4
+ run do |machine, dir|
5
+ machine.ssh("mkdir #{dir}")
6
+ end
@@ -0,0 +1,33 @@
1
+ param! "machine"
2
+
3
+ show columns: %i|pid command_short|
4
+
5
+ run do |params, machine|
6
+ input = machine.ssh("ps aux")
7
+
8
+ input.split("\n")[1..-1].map do |line|
9
+ parts = line.split()
10
+ (user, pid, cpu, mem, vsz, rss, tty, stat, start, time) = parts[0..9]
11
+ command = parts[10..parts.length-1].join(" ")
12
+ {
13
+ pid: pid,
14
+ command: command,
15
+ command_short: command[0..119],
16
+ user: user
17
+ }
18
+ end
19
+ end
20
+
21
+ __END__
22
+
23
+ # USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
24
+ # root 1 0.0 0.0 185312 5832 ? Ss Feb03 0:01 /sbin/init splash
25
+ # root 2 0.0 0.0 0 0 ? S Feb03 0:00 [kthreadd]
26
+ # root 3 0.0 0.0 0 0 ? S Feb03 0:00 [ksoftirqd/0]
27
+ # root 5 0.0 0.0 0 0 ? S< Feb03 0:00 [kworker/0:0H]
28
+ # [..]
29
+ # philipp 15036 0.0 0.0 28424 4264 pts/5 Ss 04:47 0:00 /bin/bash
30
+ # philipp 15144 0.0 0.0 28416 4216 pts/8 Ss+ 04:49 0:00 /bin/bash
31
+ # root 15168 0.0 0.0 0 0 ? S 04:51 0:00 [kworker/u8:0]
32
+ # philipp 15193 0.0 0.0 25668 2932 pts/5 R+ 04:53 0:00 ps aux
33
+ # philipp 15194 0.0 0.0 14452 2232 pts/5 S+ 04:53 0:00 tail -n5
@@ -0,0 +1,11 @@
1
+ param! "machine"
2
+ param! "expression", :default_param => true
3
+
4
+ show columns: %i|pid command_short|
5
+
6
+ run do |params, expression|
7
+ column_name = :command_short
8
+ @op.processes(params).select do |item|
9
+ item[column_name] =~ Regexp.new(expression)
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ param! :machine
2
+ param! "file"
3
+
4
+ run do |machine, file|
5
+ machine.ssh("cat #{file}")
6
+ end
@@ -0,0 +1,26 @@
1
+ require "tempfile"
2
+
3
+ param! :machine
4
+ param! "file"
5
+ param! "content"
6
+
7
+ run do |machine, file, content|
8
+ bytes_written = 0
9
+ name_fragment = "vop_#{$$}_"
10
+ tmp = Tempfile.new(name_fragment)
11
+ begin
12
+ tmp.write content
13
+ bytes_written = tmp.size
14
+ tmp.flush()
15
+ tmp.close()
16
+
17
+ $logger.debug "scp from #{tmp.path} to #{file}"
18
+ machine.scp(
19
+ local_path: tmp.path,
20
+ remote_path: file
21
+ )
22
+ ensure
23
+ tmp.delete
24
+ end
25
+ bytes_written
26
+ end
@@ -0,0 +1,50 @@
1
+ def regex_hash(line, regex, keys)
2
+ result = nil
3
+
4
+ matched = regex.match(line)
5
+ if matched
6
+ result = {}
7
+ keys.each_with_index do |key, index|
8
+ result[key] = matched.captures[index]
9
+ end
10
+ end
11
+
12
+ result
13
+ end
14
+
15
+ # calls +command+ on +machine+ and uses +regex+ to parse into +keys+
16
+ # +options+ support an `:except` key holding a hash of regex => handler
17
+ # for special-casing by regex, e.g.
18
+ # {
19
+ # except: {
20
+ # /total\s+(\d+)/ => lambda { |matched|
21
+ # puts "total is #{matched.captures.first}"
22
+ # }
23
+ # }
24
+ # }
25
+ # also supported is a `:post_process` block for transmogrifying parsed results
26
+ def ssh_regex(machine, command, regex, keys, options = {except: {}})
27
+ result = []
28
+
29
+ machine.ssh(command).lines.map do |line|
30
+ if options.has_key? :except
31
+ options[:except].each do |regex, block|
32
+ if matched = regex.match(line)
33
+ block.call(matched)
34
+ next
35
+ end
36
+ end
37
+ end
38
+
39
+ parsed = regex_hash(line, regex, keys)
40
+ if parsed
41
+ if options.has_key? :post_process
42
+ parsed = options[:post_process].call(parsed)
43
+ end
44
+
45
+ result << parsed
46
+ end
47
+ end
48
+
49
+ result
50
+ end
@@ -0,0 +1,2 @@
1
+ depends :core
2
+ depends :machines
@@ -0,0 +1,2 @@
1
+ # TODO cat /proc/sys/net/ipv4/ip_local_port_range
2
+ # TODO ulimit -a
@@ -0,0 +1,7 @@
1
+ run do
2
+ [
3
+ {
4
+ name: 'localhost'
5
+ }
6
+ ]
7
+ end
@@ -0,0 +1,3 @@
1
+ contribute :to => 'machine' do
2
+ [{ name: "localhost" }]
3
+ end
@@ -0,0 +1,3 @@
1
+ entity('name') do |params|
2
+ params[:contributions]
3
+ end
@@ -0,0 +1,10 @@
1
+ param! 'machine'
2
+ param! 'command_string'
3
+
4
+ run do |params, machine|
5
+ if machine.name == 'localhost'
6
+ @op.system_call(params["command_string"])
7
+ else
8
+ machine.ssh(params)
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ param! "machine_name",
2
+ lookup: lambda { |params| @op.list_machines.map { |x| x[:name] }}
3
+
4
+ run do |context, machine_name|
5
+ context['machine'] = machine_name
6
+ context['prompt'] = "#{machine_name} >> "
7
+ true
8
+ end
@@ -0,0 +1 @@
1
+ dependency :core
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,3 @@
1
+ class Service < Loader
2
+
3
+ end
@@ -0,0 +1,32 @@
1
+ param! 'machine'
2
+
3
+ run do |machine|
4
+ machine.ssh "vagrant global-status --prune"
5
+ output = machine.ssh "vagrant global-status"
6
+
7
+ result = []
8
+
9
+ # id name provider state directory
10
+ # --------------------------------------------------------------------------
11
+ # 96c4f6f bar virtualbox poweroff /home/philipp/lab/vagrant/bar
12
+ # 7b81b7a foo libvirt shutoff /home/philipp/lab/vagrant/foo
13
+ output.lines[2..-1].each do |line|
14
+ parts = line.strip.split
15
+ break if parts.size < 5
16
+
17
+ (vagrant_id, name, provider, state, directory) = parts
18
+
19
+ # the vm name as produced by vagrant-libvirt seems to be the project directory name plus the name defined in the Vagrantfile
20
+ full_name = directory.split('/')[-1] + '_' + name
21
+ result << {
22
+ id: vagrant_id,
23
+ name: name,
24
+ full_name: full_name,
25
+ provider: provider,
26
+ state: state,
27
+ directory: directory
28
+ }
29
+ end
30
+
31
+ result
32
+ end
@@ -0,0 +1 @@
1
+ depends :core
@@ -0,0 +1,11 @@
1
+ param! 'machine'
2
+
3
+ contribute :to => 'working_copy' do |machine|
4
+ result = []
5
+ @op.list_project_folders.each do |project_folder|
6
+ machine.find("path" => project_folder, "type" => 'd', "name" => '.git').each { |folder|
7
+ result << { name: folder }
8
+ }
9
+ end
10
+ result
11
+ end
@@ -0,0 +1,8 @@
1
+ description "project folders are locations in which working copies are searched"
2
+
3
+ run do
4
+ [
5
+ File.join(ENV["HOME"], "projects"),
6
+ File.join(ENV["HOME"], "Sites"),
7
+ ]
8
+ end
@@ -0,0 +1,3 @@
1
+ entity('name', on: 'machine') do |params|
2
+ params[:contributions]
3
+ end
@@ -0,0 +1 @@
1
+ depends :core
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ require 'vop'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "vop-plugins"
6
+ spec.version = Vop::VERSION
7
+ spec.authors = ["Philipp T."]
8
+ spec.email = ["philipp@virtualop.org"]
9
+
10
+ spec.summary = %q{Default plugins for the virtualop (see gem "vop").}
11
+ spec.description = %q{The standard plugins are always loaded in a normal vop installation, the extended ones only if configured.}
12
+ spec.homepage = "http://www.virtualop.org"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.bindir = "exe"
16
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "vop", ">= 0.3.0"
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vop-plugins
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Philipp T.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: vop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: The standard plugins are always loaded in a normal vop installation,
70
+ the extended ones only if configured.
71
+ email:
72
+ - philipp@virtualop.org
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".project"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - Rakefile
82
+ - standard/debian-iso/commands/fetch_debian_iso.rb
83
+ - standard/debian-iso/commands/fetch_ubuntu_iso.rb
84
+ - standard/debian-iso/commands/list_isos.rb
85
+ - standard/debian-iso/commands/rebuild_debian_iso.rb
86
+ - standard/debian-iso/debian-iso.plugin
87
+ - standard/debian-iso/files/rebuild-debian-iso
88
+ - standard/debian-iso/templates/preseed.cfg
89
+ - standard/libvirt/commands/delete_vm.rb
90
+ - standard/libvirt/commands/list_local_vms.rb
91
+ - standard/libvirt/commands/list_vms.rb
92
+ - standard/libvirt/commands/new_vm.rb
93
+ - standard/libvirt/commands/start_vm.rb
94
+ - standard/libvirt/commands/stop_vm.rb
95
+ - standard/libvirt/libvirt.plugin
96
+ - standard/linux/commands/disk_free.rb
97
+ - standard/linux/commands/disk_used.rb
98
+ - standard/linux/commands/distro.rb
99
+ - standard/linux/commands/download_file.rb
100
+ - standard/linux/commands/find.rb
101
+ - standard/linux/commands/list_files.rb
102
+ - standard/linux/commands/listen_ports.rb
103
+ - standard/linux/commands/mkdir.rb
104
+ - standard/linux/commands/processes.rb
105
+ - standard/linux/commands/processes_like.rb
106
+ - standard/linux/commands/read_file.rb
107
+ - standard/linux/commands/write_file.rb
108
+ - standard/linux/helpers/regex.rb
109
+ - standard/linux/linux.plugin
110
+ - standard/linux/todo
111
+ - standard/machines/commands/list_machines_old.rb
112
+ - standard/machines/commands/localhost.rb
113
+ - standard/machines/commands/machine.rb
114
+ - standard/machines/commands/run_command.rb
115
+ - standard/machines/commands/select_machine.rb
116
+ - standard/machines/machines.plugin
117
+ - standard/plugin.vop
118
+ - standard/services/loader/service.rb
119
+ - standard/vagrant/commands/vagrant_global_status.rb
120
+ - standard/vagrant/vagrant.plugin
121
+ - standard/working_copies/commands/git_working_copies.rb
122
+ - standard/working_copies/commands/list_project_folders.rb
123
+ - standard/working_copies/commands/working_copy.rb
124
+ - standard/working_copies/working_copies.plugin
125
+ - vop-plugins.gemspec
126
+ homepage: http://www.virtualop.org
127
+ licenses: []
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.5.1
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Default plugins for the virtualop (see gem "vop").
149
+ test_files: []