Permalink
Browse files

Support for gcutils-1.3.4

  • Loading branch information...
1 parent 6c8c5db commit ab5bafbd59623ee3dd21a7a1cf9855eef316ceb3 @chirag-jog chirag-jog committed Oct 29, 2012
View
12 README.rdoc
@@ -26,11 +26,11 @@ Be sure you are running the latest version Chef. Versions earlier than 0.10.0 do
Follow these instructions to install Chef-Workstation on Windows: http://wiki.opscode.com/display/chef/Workstation+Setup+for+Windows
-The gcutil tool can be installed on Windows, via Cygwin.
+The gcutil tool can be installed on Windows, via Cygwin.
Install Cygwin with Python Environment: https://developers.google.com/compute/docs/gcutil_setup
-In Windows, set CYGWINPATH environment variable to point the Cygwin Installation and add %CYGWINPATH%\\bin to the PATH environment variable
+In Windows, set CYGWINPATH environment variable to point the Cygwin Installation and add %CYGWINPATH%\\bin to the PATH environment variable
set CYGWINPATH=<CYGWIN INSTALLATION PATH>
set PATH=%CYGWINPATH%\\bin;%PATH%
@@ -42,20 +42,20 @@ Use the rake utility to install gcutil CLI utility and the knife plugin
= CONFIGURATION:
Run gcutil auth to request a token. This command prints a URL where you can acquire an OAuth 2.0 refresh token for Google Compute.
- gcutil auth --project_id=<your_project_id>
+ gcutil auth --project=<your_project_id>
Go to the following link in your browser:
<link>
Enter verification code:
# provision a new 2 Core 1GB Ubuntu 10.04 webserver
- knife google server create --server-name <server-name> -i <SSH Identity Key> -k <SSH Public Key>
- --project_id <project-name> --flavor n1-standard-2 --distro chef-full
+ knife google server create --server-name <server-name> -i <SSH Identity Key> -k <SSH Public Key>
+ --project <project-name> --flavor n1-standard-2 --distro chef-full
--google-image projects/google/images/ubuntu-10-04-v20120912
-r role[<your role>] -E <your environment>
-
+
Additionally the following options may be set in your `knife.rb`:
* flavor
View
26 Rakefile
@@ -20,8 +20,10 @@ require 'rake/rdoctask'
require 'mixlib/shellout'
GEM_NAME = "knife-google"
-GCOMPUTE_PACKAGE="gcutil.tar.gz"
+GCOMPUTE_VERSION="1.3.4"
+GCOMPUTE_PACKAGE="gcutil-#{GCOMPUTE_VERSION}"
GCOMPUTE_PACKAGE_LOCATION="external"
+GCOMPUTE_DEST_DIR="/usr/local/share"
spec = eval(File.read("knife-google.gemspec"))
@@ -47,12 +49,6 @@ end
task :install => :package do
- def is_python_pip_installed?
- shell_cmd = Mixlib::ShellOut.new("which pip")
- shell_cmd.run_command
- return shell_cmd.status.exitstatus == 0
- end
-
def is_platform_windows?
return RUBY_PLATFORM.scan('w32').size > 0
end
@@ -64,17 +60,15 @@ task :install => :package do
if is_platform_windows?
if is_cygwin_installed?
cygwin_path = ENV['CYGWINPATH'].chomp('\'').reverse.chomp('\'').reverse
- cmd = "#{cygwin_path}\\bin\\python2.6.exe #{cygwin_path}\\bin\\pip install #{GCOMPUTE_PACKAGE_LOCATION}//#{GCOMPUTE_PACKAGE}"
+ cmd = "tar -xf #{GCOMPUTE_PACKAGE_LOCATION}\\#{GCOMPUTE_PACKAGE}.tar.gz -C #{cygwin_path}\\bin\\ &" +
+ "#{cygwin_path}\\bin\\ln.exe -sf /bin/#{GCOMPUTE_PACKAGE}/gcutil /bin/gcutil"
else
puts "Cannot Find Cygwin Installation !!! Please set environment variables CYGWINPATH to point the Cygwin Installation"
exit 1
end
else #Platform is Linux/OSX
- cmd = "pip install #{GCOMPUTE_PACKAGE_LOCATION}/#{GCOMPUTE_PACKAGE}"
- end
- if not is_python_pip_installed?
- puts ("gcompute is a python package. Pip - the installer for Python packages is not installed. Please Install it")
- exit 1
+ cmd = "sudo tar -xf #{GCOMPUTE_PACKAGE_LOCATION}/#{GCOMPUTE_PACKAGE}.tar.gz -C #{GCOMPUTE_DEST_DIR};" +
+ "sudo ln -sf #{GCOMPUTE_DEST_DIR}/#{GCOMPUTE_PACKAGE}/gcutil /usr/local/bin/gcutil"
end
#Install the gcompute library on which the knife plugin depends on
@@ -83,10 +77,10 @@ task :install => :package do
puts shell_cmd.stdout
err = shell_cmd.stderr
if err.size > 0
- puts ("Failed to install gcompute. Error: #{err}")
- exit 1
+ STDERR.puts "Failed to install gcompute. Error: #{err}"
+ #Continue Anyways
end
-
+
sh %{gem install pkg/#{GEM_NAME}-#{KnifeGoogle::VERSION} --no-rdoc --no-ri}
end
View
BIN external/gcompute.tar.gz
Binary file not shown.
View
BIN external/gcutil-1.3.4.tar.gz
Binary file not shown.
View
BIN external/gcutil.tar.gz
Binary file not shown.
View
14 lib/chef/knife/google_base.rb
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -42,7 +42,7 @@ def gcompute
if is_cygwin_installed?
#Remove extra quotes
@cygwin_path = ENV['CYGWINPATH'].chomp('\'').reverse.chomp('\'').reverse
- #FIXME Generalize the python binary
+ #FIXME Generalize the python binary
@gcompute="#{@cygwin_path}\\bin\\python2.6.exe #{@cygwin_path}\\bin\\#{$CLI_PREFIX}"
else
puts "Cannot Find Cygwin Installation !!! Please set CYGWINPATH to point to the Cygwin installation"
@@ -59,7 +59,7 @@ def parser
@parser = Yajl::Parser.new
end
end
-
+
def to_json(data)
data_s = StringIO::new(data.strip)
parser.parse(data_s) {|obj| return obj}
@@ -69,7 +69,7 @@ def exec_shell_cmd(cmd)
if is_platform_windows? and is_cygwin_installed?
#Change the HOME PATH From Windows to Cygwin
cygwin_home = "#{@cygwin_path}\\home\\#{ENV['USER']}"
-
+
#Auth token should exist in either ENV['HOME'] or cygwin_home
#XXX Find a way to remove the hard-coded file name
if not File.file?("#{ENV['HOME']}\\.#{$CLI_PREFIX}_auth")
@@ -81,14 +81,14 @@ def exec_shell_cmd(cmd)
end
def validate_project(project_id)
- cmd = "#{gcompute} getproject --project_id=#{project_id}"
+ cmd = "#{gcompute} getproject --project=#{project_id}"
Chef::Log.debug 'Executing ' + cmd
getprj = exec_shell_cmd(cmd)
if getprj.status.exitstatus > 0
if not getprj.stdout.scan("Enter verification code").empty?
ui.error("Failed to authenticate the account")
ui.error("If not authenticated, please Authenticate gcompute to access the Google Compute Cloud")
- ui.error("Authenticate by executing gcutil auth --project_id=<project_id>")
+ ui.error("Authenticate by executing gcutil auth --project=<project_id>")
exit 1
end
ui.error("#{getprj.stderr}")
View
34 lib/chef/knife/google_server_create.rb
@@ -5,9 +5,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,6 +21,8 @@
require 'chef/knife'
require 'chef/knife/google_base'
+require 'chef/knife/bootstrap'
+
class Chef
class Knife
@@ -48,7 +50,7 @@ class GoogleServerCreate < Knife
:short => "-Z ZONE",
:long => "--availability-zone ZONE",
:description => "The Availability Zone",
- :default => "us-east1-a",
+ :default => "us-east-a",
:proc => Proc.new { |key| Chef::Config[:knife][:availability_zone] = key }
option :distro,
@@ -80,7 +82,7 @@ class GoogleServerCreate < Knife
:short => "-s NAME",
:long => "--server-name NAME",
:description => "The server name",
- :proc => Proc.new { |server_name| Chef::Config[:knife][:server_name] = server_name }
+ :proc => Proc.new { |server_name| Chef::Config[:knife][:server_name] = server_name }
option :flavor,
:short => "-f FLAVOR",
@@ -94,19 +96,19 @@ class GoogleServerCreate < Knife
:long => "--google-image IMAGE",
:description => "Your google Image resource name",
:proc => Proc.new { |template| Chef::Config[:knife][:image] = template }
-
+
option :private_key_file,
:short => "-i PRIVATE_KEY_FILE",
:long => "--private-key-file PRIVATE_KEY_FILE",
:description => "The SSH private key file used for authentication",
- :proc => Proc.new { |identity| Chef::Config[:knife][:private_key_file] = identity }
-
+ :proc => Proc.new { |identity| Chef::Config[:knife][:private_key_file] = identity }
+
option :public_key_file,
:short => "-k PUBLIC_KEY_FILE",
:long => "--public-key-file PUBLIC_KEY_FILE",
:description => "The SSH public key file used for authentication",
- :proc => Proc.new { |identity| Chef::Config[:knife][:public_key_file] = identity }
-
+ :proc => Proc.new { |identity| Chef::Config[:knife][:public_key_file] = identity }
+
option :network,
:short => "-n NETWORKNAME",
:long => "--network NETWORKNAME",
@@ -129,14 +131,14 @@ class GoogleServerCreate < Knife
option :project,
:short => "-p PROJECT",
- :long => "--project_id PROJECT",
+ :long => "--project PROJECT",
:description => "Google Compute Project",
:proc => Proc.new { |project| Chef::Config[:knife][:google_project] = project}
def h
@highline ||= HighLine.new
end
-
+
def locate_config_value(key)
key = key.to_sym
config[key] || Chef::Config[:knife][key]
@@ -198,10 +200,10 @@ def run
internal_ip_address = locate_config_value(:internal_ip_address) || nil
puts "\n#{ui.color("Waiting for the server to be Instantiated", :magenta)}"
cmd_add_instance = "#{@gcompute} addinstance #{server_name} --machine_type #{flavor} " +
- "--zone #{zone} --project_id #{project_id} --tags #{server_name} " +
+ "--zone #{zone} --project #{project_id} --tags #{server_name} " +
"--authorized_ssh_keys #{user}:#{key_file} --network #{network} " +
"--external_ip_address #{external_ip_address} --print_json"
- cmd_add_instance << " --internal_ip_address #{internal_ip_address}" if internal_ip_address
+ cmd_add_instance << " --internal_ip_address #{internal_ip_address}" if internal_ip_address
cmd_add_instance << " --image=#{image}" if image
Chef::Log.debug 'Executing ' + cmd_add_instance
@@ -220,9 +222,9 @@ def run
ui.error("\nFailed to create server: #{output}")
exit 1
end
-
+
#Fetch server information
- cmd_get_instance = "#{@gcompute} getinstance #{server_name} --project_id #{project_id} --print_json "
+ cmd_get_instance = "#{@gcompute} getinstance #{server_name} --project #{project_id} --print_json "
Chef::Log.debug 'Executing ' + cmd_get_instance
get_instance = exec_shell_cmd(cmd_get_instance)
@@ -234,7 +236,7 @@ def run
server = to_json(get_instance.stdout)
private_ip = []
public_ip = []
- server["networkInterfaces"].each do |interface|
+ server["networkInterfaces"].each do |interface|
private_ip << interface["networkIP"]
interface["accessConfigs"].select { |cfg| public_ip << cfg["natIP"] }
end
View
18 lib/chef/knife/google_server_delete.rb
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,25 +30,25 @@ class GoogleServerDelete < Knife
option :project_id,
:short => "-p PROJECTNAME",
- :long => "--project_id PROJECTNAME",
+ :long => "--project PROJECTNAME",
:description => "Your Google Compute Project Name",
- :proc => Proc.new { |project| Chef::Config[:knife][:google_project] = project }
+ :proc => Proc.new { |project| Chef::Config[:knife][:google_project] = project }
- def run
+ def run
unless Chef::Config[:knife][:google_project]
ui.error("Project ID is a compulsory parameter")
exit 1
end
$stdout.sync = true
project_id = Chef::Config[:knife][:google_project]
- validate_project(project_id)
+ validate_project(project_id)
- @name_args.each do |server|
+ @name_args.each do |server|
confirm("Do you really want to delete the server - #{server} ?")
- del_instance = exec_shell_cmd("#{@gcompute} deleteinstance #{server} --print_json --project_id=#{project_id} -f")
+ del_instance = exec_shell_cmd("#{@gcompute} deleteinstance #{server} --print_json --project=#{project_id} -f")
Chef::Log.debug 'Executing ' + del_instance.command
-
+
if not del_instance.stderr.downcase.scan("error").empty?
ui.error("Failed to delete server. Error: #{error}")
exit 1
View
20 lib/chef/knife/google_server_list.rb
@@ -5,14 +5,15 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+require 'highline'
require 'stringio'
require 'yajl'
@@ -27,6 +28,11 @@ class Chef
class Knife
class GoogleServerList < Knife
+ deps do
+ require 'chef/knife/google_base'
+ Chef::Knife.load_deps
+ end
+
include Knife::GoogleBase
banner "knife google server list PROJECT_ID (options)"
@@ -35,7 +41,7 @@ class GoogleServerList < Knife
:short => "-p PROJECT_ID",
:long => "--project_id PROJECT_ID",
:description => "The Google Compute Engine project identifier",
- :proc => Proc.new { |project| Chef::Config[:knife][:google_project] = project }
+ :proc => Proc.new { |project| Chef::Config[:knife][:google_project] = project }
def h
@highline ||= HighLine.new
@@ -50,7 +56,7 @@ def run
project_id = Chef::Config[:knife][:google_project]
validate_project(project_id)
- list_instances = exec_shell_cmd("#{@gcompute} listinstances --print_json --project_id=#{project_id}")
+ list_instances = exec_shell_cmd("#{@gcompute} listinstances --print_json --project=#{project_id}")
Chef::Log.debug 'Executing ' + list_instances.command
list_instances.run_command
@@ -61,12 +67,12 @@ def run
instances_json = to_json(list_instances.stdout)
server_list = [
- h.color('ID', :bold),
+ h.color('ID', :bold),
h.color('Name', :bold),
h.color('PublicIP', :bold),
h.color('PrivateIP', :bold),
h.color('OperatingSystem', :bold)
-
+
]
if not instances_json.has_key?("items")
@@ -78,7 +84,7 @@ def run
server_list << item["name"].split("/").last
private_ip = []
public_ip = []
- item["networkInterfaces"].each do |interface|
+ item["networkInterfaces"].each do |interface|
private_ip << interface["networkIP"]
interface["accessConfigs"].select { |cfg| public_ip << cfg["natIP"] }
end

0 comments on commit ab5bafb

Please sign in to comment.