vcli 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 22a270ef67bcde8b555c88c42188261bbe332945
4
+ data.tar.gz: c5995cf83bdbc697a2431f111f1e7dc8f3a4beb0
5
+ SHA512:
6
+ metadata.gz: e6d5635da49bd1aa5c7e84b3b2b3fa6d46a29e585fdaa67d31e01460044885c0985a07400a8f82b56a1b645498dafdb4d6a919a1e480c568f7f72922a8ef5ecc
7
+ data.tar.gz: 2cbf7eca73f081b4698e3a87776bea58a7994608e41a0602a04cdee7a25af25acf2d5e7ef3dfe5baba1d38ac647b4d69ff9bf0dc03674decc4033ebb2a35d276
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vcli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/bin/vcli ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'vcli'
3
+
4
+ Vcli::Cli.start( ARGV )
data/lib/vcli.rb ADDED
@@ -0,0 +1,61 @@
1
+ require "vcli/version"
2
+ require "vcli/cli"
3
+ require "yaml"
4
+
5
+ module Vcli
6
+
7
+ # Set Config directory and file
8
+ CONFIG_DIR = "#{ENV['HOME']}/.vcli/"
9
+ CONFIG_FILE = CONFIG_DIR + "vcli.yml"
10
+
11
+ attr_reader :target
12
+ attr_reader :user
13
+ attr_reader :password
14
+
15
+ def self.set_config(key, value)
16
+ # Read in YAML file
17
+ config = YAML::load(File.read(CONFIG_FILE)) || {}
18
+ # change to new value
19
+ config[key.to_sym] = value
20
+ # Write it back out to the YAML file
21
+ open(CONFIG_FILE, 'w') { |f| YAML::dump(config, f) }
22
+ # ReRead the configuration file
23
+ readconfig
24
+ end
25
+
26
+ def self.readconfig
27
+ # read in yaml file and store as instance variables
28
+ config = YAML.load_file(CONFIG_FILE)
29
+ config.each { |key, value|
30
+ instance_variable_set("@#{key}", value) }
31
+ end
32
+
33
+ def self.create_file
34
+ # create file
35
+ f = File.open(CONFIG_FILE, 'w')
36
+ f.write("")
37
+ # set some default null values
38
+ set_config("target","")
39
+ set_config("user","")
40
+ set_config("password","")
41
+ end
42
+
43
+ def self.create_dir
44
+ # create directory
45
+ Dir::mkdir CONFIG_DIR
46
+ end
47
+
48
+ unless File.directory? CONFIG_DIR
49
+ # if configuration directory does not exist then create it
50
+ create_dir
51
+ end
52
+
53
+ unless File.file? CONFIG_FILE
54
+ #if yaml file does not exist then create it
55
+ create_file
56
+ end
57
+
58
+ #Read in YAML file into instance variables
59
+ readconfig
60
+
61
+ end
data/lib/vcli/cli.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'thor'
2
+ require 'vcli/cli/show'
3
+ require 'vcli/cli/resource'
4
+ require 'abiquo-api'
5
+ include Vcli
6
+
7
+ module Vcli
8
+ class Cli < Thor
9
+ desc "target URL", "Set the target of the CLI to URL"
10
+ def target(url)
11
+ Vcli.set_config("target",url)
12
+ command = "Set target of cli to #{url}"
13
+ puts command
14
+ end
15
+
16
+ desc "login", "Login to the Abiquo VDC with stored details"
17
+ def login()
18
+ abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target,
19
+ :abiquo_username => Vcli::user,
20
+ :abiquo_password => Vcli::password)
21
+ abq.user
22
+ enterprise=abq.user.link(:enterprise).get
23
+ puts "Logged into Abiquo Portal as User - #{abq.user.id} - #{abq.user.name} #{abq.user.surname}"
24
+ puts " in Enterprise - #{enterprise.id} - #{abq.enterprise.title}"
25
+ end
26
+
27
+ desc "user username password", "Set user details for accessing the Abiquo VDC"
28
+ def user(username, password)
29
+ Vcli.set_config("user",username)
30
+ Vcli.set_config("password",password)
31
+ puts "Set user details complete"
32
+ end
33
+
34
+ desc "show COMMANDS", "Show items within the Abiquo VDC"
35
+ subcommand "show", Vcli::CLI::Show
36
+ end
37
+ end
@@ -0,0 +1 @@
1
+ abiquo = lambda {AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password)}
@@ -0,0 +1,18 @@
1
+ module Vcli
2
+ module CLI
3
+ module SHOW
4
+ class Resource < Thor
5
+ desc "limits", "Show limits"
6
+ def limits( )
7
+ command = "showing limits"
8
+ puts command
9
+ end
10
+ desc "usage", "Show usage"
11
+ def usage( )
12
+ command = "showing usage"
13
+ puts command
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,112 @@
1
+ ############################################################################
2
+ #
3
+ # VCLI::CLI::Show
4
+ #
5
+ ############################################################################
6
+ # Jay Fearn
7
+ ############################################################################
8
+ # Very Messy needs to be refactored to create classes for each object type
9
+ # like datacenters, virtualappliances, enterprises, virtual machines, etc
10
+ ############################################################################
11
+ # DATE # Ver # Description
12
+ ############################################################################
13
+ # 16072015 # 0.1 # Initial Creation
14
+ ############################################################################
15
+
16
+ module Vcli
17
+ module CLI
18
+ class Show < Thor
19
+
20
+ # Data Centers
21
+ desc "datacenters", "Show all datacenters"
22
+ def datacenters( )
23
+ abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password)
24
+ link=AbiquoAPI::Link.new(:href => 'api/admin/datacenters' , :type => 'application/vnd.abiquo.datacenters+json')
25
+ dc=abq.list(link)
26
+ dc.each { |l|
27
+ puts "#{l.name} \t - #{l.id} \t - #{l.location}"
28
+ }
29
+ end
30
+
31
+ # Virtual Appliances
32
+ desc "virtualappliances", "Show all virtualappliances"
33
+ method_option :vdc, :type => :string
34
+ def virtualappliances( )
35
+ abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password)
36
+ # Get something on the screen
37
+ puts "VDC,Appliance ID,Appliance Name"
38
+ # If --vdc parameter passed
39
+ vdc=options[:vdc].to_s
40
+ if vdc.length != 0
41
+ link2=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + vdc + '/virtualappliances' , :type => 'application/vnd.abiquo.virtualappliances+json')
42
+ va=abq.list(link2)
43
+ va.each { |l|
44
+ puts "#{vdc},#{l.name},#{l.id}"
45
+ }
46
+ # If no --vdc parameter passwd
47
+ else
48
+ # Cycle through all virtualdatacenters
49
+ link=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters',
50
+ :type => 'application/vnd.abiquo.virtualdatacenters+json')
51
+ vdc=abq.list(link)
52
+ # Cycle through all virtual appliances in virtual datacenter
53
+ vdc.each { |l|
54
+ link2=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + l.id.to_s + '/virtualappliances' , :type => 'application/vnd.abiquo.virtualappliances+json')
55
+ dc=abq.list(link2)
56
+ dc.each { |m|
57
+ puts "#{l.id},#{m.id},#{m.name}"
58
+ }
59
+ }
60
+ end
61
+ end
62
+
63
+ # Users
64
+ desc "users", "Show all users within your account"
65
+ def users( )
66
+ command = "showing all users"
67
+ puts command
68
+ end
69
+
70
+ # Enterprise
71
+ desc "enterprise", "Show Enterprise details"
72
+ def enterprise( )
73
+ abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password)
74
+ link=AbiquoAPI::Link.new(:href => 'api/admin/enterprises',
75
+ :type => 'application/vnd.abiquo.enterprises+json')
76
+ dc=abq.list(link)
77
+ dc.each { |l|
78
+ puts "#{l.id} \t - #{l.name}"
79
+ }
80
+ end
81
+
82
+ # Resources
83
+ desc "resources", "Show resources usage details"
84
+ def resources( )
85
+ command = "showing resources details"
86
+ puts command
87
+ end
88
+
89
+ # Resource Limits
90
+ #
91
+ desc "limits", "Show limit details"
92
+ def limits( )
93
+ command = "showing limit details"
94
+ puts command
95
+ end
96
+
97
+ # Virtual Datacenters
98
+ desc "virtualdatacenters", "show configured Virtual Data Centers"
99
+ def virtualdatacenters( )
100
+ abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target,
101
+ :abiquo_username => Vcli::user,
102
+ :abiquo_password => Vcli::password)
103
+ link=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters',
104
+ :type => 'application/vnd.abiquo.virtualdatacenters+json')
105
+ vdc=abq.list(link)
106
+ vdc.each { |l|
107
+ puts "#{l.id} \t - #{l.name}"
108
+ }
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,3 @@
1
+ module Vcli
2
+ VERSION = "0.1.4"
3
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'vcli'
3
+
4
+ require 'minitest/autorun'
data/test/vcli_test.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class VcliTest < Minitest::Test
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::Vcli::VERSION
6
+ end
7
+
8
+ def test_it_does_something_useful
9
+ assert false
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vcli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Jay Fearn
8
+ autorequire:
9
+ bindir:
10
+ - bin
11
+ cert_chain: []
12
+ date: 2015-07-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.10'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '5'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '5'
56
+ - !ruby/object:Gem::Dependency
57
+ name: multi_xml
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '='
61
+ - !ruby/object:Gem::Version
62
+ version: 0.5.5
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.5.5
70
+ - !ruby/object:Gem::Dependency
71
+ name: thor
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: httparty
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: json
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '='
103
+ - !ruby/object:Gem::Version
104
+ version: 1.8.3
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '='
110
+ - !ruby/object:Gem::Version
111
+ version: 1.8.3
112
+ - !ruby/object:Gem::Dependency
113
+ name: abiquo-api
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Command Line Interface for the Abiquo API
127
+ email:
128
+ - jay@jayfearn.com
129
+ executables:
130
+ - setup
131
+ - vcli
132
+ - console
133
+ extensions: []
134
+ extra_rdoc_files: []
135
+ files:
136
+ - Rakefile
137
+ - bin/setup
138
+ - bin/vcli
139
+ - bin/console
140
+ - lib/vcli/cli/abiquo.rb
141
+ - lib/vcli/cli/show.rb
142
+ - lib/vcli/cli/resource.rb
143
+ - lib/vcli/version.rb
144
+ - lib/vcli/cli.rb
145
+ - lib/vcli.rb
146
+ - test/test_helper.rb
147
+ - test/vcli_test.rb
148
+ homepage: http://www.sittingonthe.net
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.0.14
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Command Line Interface for the Abiquo API
172
+ test_files: []