lib/chef/knife/google_server_create.rb in knife-google-2.1.0 vs lib/chef/knife/google_server_create.rb in knife-google-2.2.0
- old
+ new
@@ -83,10 +83,16 @@
long: "--[no-]gce-auto-server-migrate",
description: "GCE can migrate your server to other hardware without downtime prior to periodic infrastructure maintenance, otherwise the server is terminated; enabled by default.",
boolean: true,
default: true
+ option :preemptible,
+ long: "--[no-]gce-preemptible",
+ description: "Create the instance as a preemptible instance, allowing GCE to shut it down at any time. Defaults to false.",
+ boolean: true,
+ default: false
+
option :can_ip_forward,
long: "--[no-]gce-can-ip-forward",
description: "Allow server network forwarding",
boolean: true,
default: false
@@ -94,10 +100,14 @@
option :network,
long: "--gce-network NETWORK",
description: "The network for this server; default is 'default'",
default: "default"
+ option :subnet,
+ long: "--gce-subnet SUBNET",
+ description: "The name of the subnet in the network on which to deploy the instance"
+
option :tags,
short: "-T TAG1,TAG2,TAG3",
long: "--gce-tags TAG1,TAG2,TAG3",
description: "Tags for this server",
proc: Proc.new { |tags| tags.split(",") },
@@ -145,13 +155,15 @@
@create_options = {
name: instance_name,
image: locate_config_value(:image),
image_project: locate_config_value(:image_project),
network: locate_config_value(:network),
+ subnet: locate_config_value(:subnet),
public_ip: locate_config_value(:public_ip),
- auto_migrate: locate_config_value(:auto_migrate),
- auto_restart: locate_config_value(:auto_restart),
+ auto_migrate: auto_migrate?,
+ auto_restart: auto_restart?,
+ preemptible: preemptible?,
boot_disk_autodelete: locate_config_value(:boot_disk_autodelete),
boot_disk_name: locate_config_value(:boot_disk_name),
boot_disk_size: boot_disk_size,
boot_disk_ssd: locate_config_value(:boot_disk_ssd),
additional_disks: locate_config_value(:additional_disks),
@@ -175,10 +187,12 @@
raise "You must supply an instance name." if @name_args.first.nil?
raise "Boot disk size must be between 10 and 10,000" unless valid_disk_size?(boot_disk_size)
raise "Please provide your Google Cloud console email address via --gce-email. " \
"It is required when resetting passwords on Windows hosts." if locate_config_value(:bootstrap_protocol) == "winrm" && locate_config_value(:gce_email).nil?
+ ui.warn("Auto-migrate disabled for preemptible instance") if preemptible? && locate_config_value(:auto_migrate)
+ ui.warn("Auto-restart disabled for preemptible instance") if preemptible? && locate_config_value(:auto_restart)
super
end
def before_bootstrap
super
@@ -210,9 +224,21 @@
locate_config_value(:gce_zone)
end
def email
locate_config_value(:gce_email)
+ end
+
+ def preemptible?
+ locate_config_value(:preemptible)
+ end
+
+ def auto_migrate?
+ preemptible? ? false : locate_config_value(:auto_migrate)
+ end
+
+ def auto_restart?
+ preemptible? ? false : locate_config_value(:auto_restart)
end
def ip_address_for_bootstrap
ip = locate_config_value(:use_private_ip) ? private_ip_for(server) : public_ip_for(server)