secured-cloud-vagrant 1.0.0
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 +7 -0
- data/.gitignore +19 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +9 -0
- data/README.md +340 -0
- data/README.txt +358 -0
- data/Rakefile +22 -0
- data/Vagrantfile_multipleVMs +124 -0
- data/Vagrantfile_singleVM +43 -0
- data/dummy.box +0 -0
- data/example_box/README.md +13 -0
- data/example_box/metadata.json +3 -0
- data/lib/secured-cloud-vagrant.rb +22 -0
- data/lib/secured-cloud-vagrant/action.rb +259 -0
- data/lib/secured-cloud-vagrant/actions/assign_public_ips.rb +142 -0
- data/lib/secured-cloud-vagrant/actions/check_state.rb +64 -0
- data/lib/secured-cloud-vagrant/actions/create.rb +112 -0
- data/lib/secured-cloud-vagrant/actions/delete.rb +105 -0
- data/lib/secured-cloud-vagrant/actions/has_public_ips.rb +53 -0
- data/lib/secured-cloud-vagrant/actions/power_off.rb +22 -0
- data/lib/secured-cloud-vagrant/actions/power_on.rb +22 -0
- data/lib/secured-cloud-vagrant/actions/power_vm.rb +100 -0
- data/lib/secured-cloud-vagrant/actions/read_ssh_info.rb +148 -0
- data/lib/secured-cloud-vagrant/actions/reboot.rb +98 -0
- data/lib/secured-cloud-vagrant/actions/release_ips_confirm.rb +25 -0
- data/lib/secured-cloud-vagrant/actions/wait_for_state.rb +54 -0
- data/lib/secured-cloud-vagrant/actions/warn_networks.rb +32 -0
- data/lib/secured-cloud-vagrant/actions/warn_provision.rb +32 -0
- data/lib/secured-cloud-vagrant/commands/list.rb +149 -0
- data/lib/secured-cloud-vagrant/commands/ssh_config.rb +43 -0
- data/lib/secured-cloud-vagrant/configs/authentication_info.rb +49 -0
- data/lib/secured-cloud-vagrant/configs/config.rb +87 -0
- data/lib/secured-cloud-vagrant/configs/ip_mapping.rb +71 -0
- data/lib/secured-cloud-vagrant/configs/virtual_machine.rb +136 -0
- data/lib/secured-cloud-vagrant/plugin.rb +77 -0
- data/lib/secured-cloud-vagrant/provider.rb +73 -0
- data/lib/secured-cloud-vagrant/version.rb +5 -0
- data/locales/en.yml +91 -0
- data/secured-cloud-vagrant.gemspec +59 -0
- data/templates/os_templates.erb +12 -0
- metadata +160 -0
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
require 'secured_cloud_api_client'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module SecuredCloud
|
6
|
+
module Action
|
7
|
+
class AssignPublicIps
|
8
|
+
def initialize(app, env)
|
9
|
+
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@logger = Log4r::Logger.new('vagrant::secured_cloud::action::assign_public_ips')
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
|
18
|
+
@logger.debug("Assigning public IPs to VM with name #{@machine.provider_config.vm.name}")
|
19
|
+
|
20
|
+
if @machine.id.nil? || @machine.id.empty?
|
21
|
+
@logger.debug("The VM has not been created")
|
22
|
+
return
|
23
|
+
end
|
24
|
+
|
25
|
+
ipMappings = @machine.provider_config.vm.ipMappings
|
26
|
+
|
27
|
+
if ipMappings.nil? || ipMappings.empty?
|
28
|
+
@logger.debug("The VM has not been assigned any public IPs")
|
29
|
+
else
|
30
|
+
|
31
|
+
env[:ui].info(I18n.t("secured_cloud_vagrant.info.assigning_public_ips"))
|
32
|
+
|
33
|
+
# Create a Secured Cloud Connection instance to connect tot he SecuredCloud API
|
34
|
+
authInfo = @machine.provider_config.auth
|
35
|
+
@sc_connection = SecuredCloudConnection.new(authInfo.url, authInfo.applicationKey, authInfo.sharedSecret)
|
36
|
+
|
37
|
+
ipMappings.each do |ipMapping|
|
38
|
+
|
39
|
+
# Extract the parameters to pass to the assign public IP method
|
40
|
+
privateIp = ipMapping.privateIp
|
41
|
+
publicIpCount = ipMapping.newPublicIpCount
|
42
|
+
publicIpsFromReserved = ipMapping.publicIpsFromReserved
|
43
|
+
|
44
|
+
# Process the public IPs from global pool
|
45
|
+
publicIpCount.times do |n|
|
46
|
+
@logger.debug("Assigning public IP from global pool to private IP #{privateIp}")
|
47
|
+
assign_public_ip(privateIp, nil, env)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Process the public IPs from reserve pool
|
51
|
+
if !publicIpsFromReserved.nil? && !publicIpsFromReserved.empty?
|
52
|
+
|
53
|
+
publicIpsFromReserved.each do |reservedIp|
|
54
|
+
@logger.debug("Assigning public IP from reserve pool '#{reservedIp}' to private IP #{privateIp}")
|
55
|
+
assign_public_ip(privateIp, reservedIp, env)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
@app.call(env)
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def assign_public_ip(private_ip, public_ip, env)
|
69
|
+
|
70
|
+
begin
|
71
|
+
|
72
|
+
# Call Rest Client to assign a public IP
|
73
|
+
response = SecuredCloudRestClient::assignPublicIpToVM(@sc_connection, @machine.id, public_ip, private_ip)
|
74
|
+
|
75
|
+
# Monitor the transaction.
|
76
|
+
if (response[0] == "202")
|
77
|
+
|
78
|
+
# Task successful.
|
79
|
+
taskResource = response[1]
|
80
|
+
taskStatus = SecuredCloudRestClient::getTaskStatus(@sc_connection, taskResource)
|
81
|
+
|
82
|
+
@logger.info("Task Status:\n#{taskStatus.get_details()}")
|
83
|
+
|
84
|
+
while ((taskStatus.instance_variable_get(:@requestStateEnum) == nil) || (taskStatus.instance_variable_get(:@requestStateEnum) == "OPEN")) do
|
85
|
+
sleep(20)
|
86
|
+
taskStatus = SecuredCloudRestClient.getTaskStatus(@sc_connection, taskResource)
|
87
|
+
env[:ui].info(I18n.t('secured_cloud_vagrant.info.task_status', :percentage => taskStatus.get_percentage_completed,
|
88
|
+
:task_desc => taskStatus.get_latest_task_description))
|
89
|
+
@logger.info("Task Status:\n#{taskStatus.get_details()}")
|
90
|
+
end
|
91
|
+
|
92
|
+
if(taskStatus.get_result.nil?)
|
93
|
+
|
94
|
+
#Task unsuccessful.
|
95
|
+
@logger.debug("Public IP assignment failed with the following error:\n#{taskStatus.get_error_code}: #{taskStatus.get_error_message}")
|
96
|
+
|
97
|
+
error_code = (taskStatus.get_error_code.nil?) ? "" : "#{taskStatus.get_error_code} "
|
98
|
+
error_message = (taskStatus.get_error_message.nil?) ? I18n.t('secured_cloud_vagrant.errors.internal_server_error') :
|
99
|
+
error_code + taskStatus.get_error_message
|
100
|
+
|
101
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.assigning_public_ip", :vm_name => env[:vm_name], :error_message => error_message))
|
102
|
+
|
103
|
+
else
|
104
|
+
|
105
|
+
# Task successful
|
106
|
+
if(public_ip.nil?)
|
107
|
+
|
108
|
+
@logger.debug("VM #{env[:vm_name]} has been assigned a public IP from the global pool")
|
109
|
+
env[:ui].info(I18n.t("secured_cloud_vagrant.info.success.assign_public_ip.global_pool", :vm_name => env[:vm_name]))
|
110
|
+
|
111
|
+
else
|
112
|
+
|
113
|
+
@logger.debug("VM #{env[:vm_name]} has been assigned public IP '#{public_ip}' from the reserve pool")
|
114
|
+
env[:ui].info(I18n.t("secured_cloud_vagrant.info.success.assign_public_ip.reserve_pool", :vm_name => env[:vm_name],
|
115
|
+
:public_ip => public_ip))
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
else
|
121
|
+
|
122
|
+
# Task unsuccessful.
|
123
|
+
@logger.debug("Public IP assignment failed with the following error:\n#{response}")
|
124
|
+
|
125
|
+
error_message = (response[2].nil?) ? I18n.t('secured_cloud_vagrant.errors.internal_server_error') : response[2]
|
126
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.assigning_public_ip", :vm_name => env[:vm_name],
|
127
|
+
:error_message => error_message))
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
rescue Errno::ETIMEDOUT
|
132
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.request_timed_out", :request => "assign a public IP"))
|
133
|
+
rescue Exception => e
|
134
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.generic_error", :error_message => e.message))
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "secured_cloud_api_client"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module SecuredCloud
|
6
|
+
module Action
|
7
|
+
|
8
|
+
# This can be used with "Call" built-in to check if the machine
|
9
|
+
# is created and branch in the middleware.
|
10
|
+
class CheckState
|
11
|
+
|
12
|
+
def initialize(app, env)
|
13
|
+
@app = app
|
14
|
+
@machine = env[:machine]
|
15
|
+
@logger = Log4r::Logger.new('vagrant::secured_cloud::action::check_state')
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
|
20
|
+
@logger.debug("Checking VM state ...")
|
21
|
+
|
22
|
+
vm_resource_url = @machine.id
|
23
|
+
|
24
|
+
if vm_resource_url.nil? || vm_resource_url.empty?
|
25
|
+
env[:machine_state] = :not_created
|
26
|
+
else
|
27
|
+
|
28
|
+
begin
|
29
|
+
|
30
|
+
# Create a Secured Cloud Connection instance to connect tot he SecuredCloud API
|
31
|
+
authInfo = @machine.provider_config.auth
|
32
|
+
sc_connection = SecuredCloudConnection.new(authInfo.url, authInfo.applicationKey, authInfo.sharedSecret)
|
33
|
+
|
34
|
+
# Get the VM details
|
35
|
+
virtualMachine = SecuredCloudRestClient.getVMDetails(sc_connection, vm_resource_url)
|
36
|
+
|
37
|
+
# Set the VM name
|
38
|
+
env[:vm_name] = virtualMachine.get_name
|
39
|
+
@logger.debug("VM Name: '#{env[:vm_name]}'")
|
40
|
+
|
41
|
+
# Get the VM power status
|
42
|
+
if (virtualMachine.get_power_status == "POWERED_OFF")
|
43
|
+
env[:machine_state] = :stopped
|
44
|
+
elsif (virtualMachine.get_power_status == "POWERED_ON")
|
45
|
+
env[:machine_state] = :active
|
46
|
+
end
|
47
|
+
|
48
|
+
@logger.debug("State for VM #{vm_resource_url} is #{env[:machine_state]}")
|
49
|
+
|
50
|
+
rescue Errno::ETIMEDOUT
|
51
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.request_timed_out", :request => "get the VM details"))
|
52
|
+
rescue Exception => e
|
53
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.generic_error", :error_message => e.message))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
@app.call(env)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
require 'secured_cloud_api_client'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module SecuredCloud
|
6
|
+
module Action
|
7
|
+
|
8
|
+
class Create
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
|
12
|
+
@app = app
|
13
|
+
@machine = env[:machine]
|
14
|
+
@logger = Log4r::Logger.new('vagrant::secured_cloud::action::create')
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
|
21
|
+
@logger.debug("Creating VM with name #{@machine.provider_config.vm.name}")
|
22
|
+
env[:ui].info(I18n.t("secured_cloud_vagrant.info.creating"))
|
23
|
+
|
24
|
+
# Create a Secured Cloud Connection instance to connect tot he SecuredCloud API
|
25
|
+
authInfo = @machine.provider_config.auth
|
26
|
+
sc_connection = SecuredCloudConnection.new(authInfo.url, authInfo.applicationKey, authInfo.sharedSecret)
|
27
|
+
|
28
|
+
# Extract the parameters to pass to the createVM method
|
29
|
+
vmName = @machine.provider_config.vm.name
|
30
|
+
vmDescription = @machine.provider_config.vm.description
|
31
|
+
vmStorageGB = @machine.provider_config.vm.storageGB
|
32
|
+
vmMemoryMB = @machine.provider_config.vm.memoryMB
|
33
|
+
vmVcpus = @machine.provider_config.vm.vcpus
|
34
|
+
vmPowerStatus = "POWERED_ON"
|
35
|
+
vmOsPassword = @machine.provider_config.vm.newOsPassword
|
36
|
+
|
37
|
+
orgResource = @machine.provider_config.vm.orgResourceUrl
|
38
|
+
nodeResource = @machine.provider_config.vm.nodeResourceUrl
|
39
|
+
osTemplateResource = @machine.provider_config.vm.osTemplateUrl
|
40
|
+
imageResource = @machine.provider_config.vm.imageResourceUrl
|
41
|
+
|
42
|
+
begin
|
43
|
+
|
44
|
+
# Call Rest Client to create a VM
|
45
|
+
response = SecuredCloudRestClient::createVM(sc_connection, orgResource, nodeResource, vmName, vmDescription, vmStorageGB, vmMemoryMB, vmVcpus, vmPowerStatus, imageResource, osTemplateResource, vmOsPassword)
|
46
|
+
|
47
|
+
#Monitor the transaction.
|
48
|
+
if (response[0] == "202")
|
49
|
+
|
50
|
+
#Task successful.
|
51
|
+
taskResource = response[1]
|
52
|
+
taskStatus = SecuredCloudRestClient::getTaskStatus(sc_connection, taskResource)
|
53
|
+
|
54
|
+
@logger.info("Task Status:\n#{taskStatus.get_details()}")
|
55
|
+
|
56
|
+
while ((taskStatus.instance_variable_get(:@requestStateEnum) == nil) || (taskStatus.instance_variable_get(:@requestStateEnum) == "OPEN")) do
|
57
|
+
sleep(20)
|
58
|
+
taskStatus = SecuredCloudRestClient.getTaskStatus(sc_connection, taskResource)
|
59
|
+
env[:ui].info(I18n.t("secured_cloud_vagrant.info.task_status", :percentage => taskStatus.get_percentage_completed,
|
60
|
+
:task_desc => taskStatus.get_latest_task_description))
|
61
|
+
@logger.info("Task Status:\n#{taskStatus.get_details()}")
|
62
|
+
end
|
63
|
+
|
64
|
+
if(taskStatus.get_result.nil?)
|
65
|
+
|
66
|
+
#Task unsuccessful.
|
67
|
+
@logger.debug("VM Creation failed with the following error:\n#{taskStatus.get_error_code}: #{taskStatus.get_error_message}")
|
68
|
+
|
69
|
+
error_code = (taskStatus.get_error_code.nil?) ? "" : "#{taskStatus.get_error_code} "
|
70
|
+
error_message = (taskStatus.get_error_message.nil?) ? I18n.t('secured_cloud_vagrant.errors.internal_server_error') :
|
71
|
+
error_code + taskStatus.get_error_message
|
72
|
+
|
73
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.creating_vm", :vm_name => @machine.provider_config.vm.name,
|
74
|
+
:error_message => error_message))
|
75
|
+
|
76
|
+
else
|
77
|
+
|
78
|
+
# Put the resource URL of the newly created VM in the environment
|
79
|
+
env[:machine].id = taskStatus.get_result
|
80
|
+
env[:vm_name] = vmName
|
81
|
+
|
82
|
+
@logger.debug("VM #{@machine.provider_config.vm.name} has been created with resource URL: #{env[:machine].id}")
|
83
|
+
env[:ui].info(I18n.t("secured_cloud_vagrant.info.success.create_vm", :vm_name => @machine.provider_config.vm.name,
|
84
|
+
:resource_url => env[:machine].id))
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
else
|
90
|
+
|
91
|
+
#Task unsuccessful.
|
92
|
+
@logger.debug("VM Creation failed with the following error:\n#{response}")
|
93
|
+
|
94
|
+
error_message = (response[2].nil?) ? I18n.t('secured_cloud_vagrant.errors.internal_server_error') : response[2]
|
95
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.creating_vm", :vm_name => @machine.provider_config.vm.name,
|
96
|
+
:error_message => error_message))
|
97
|
+
end
|
98
|
+
|
99
|
+
rescue Errno::ETIMEDOUT
|
100
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.request_timed_out", :request => "create VM '#{vmName}'"))
|
101
|
+
rescue Exception => e
|
102
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.generic_error", :error_message => e.message))
|
103
|
+
end
|
104
|
+
|
105
|
+
@app.call(env)
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "secured_cloud_api_client"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module SecuredCloud
|
6
|
+
module Action
|
7
|
+
# This can be used with "Call" built-in to check if the machine
|
8
|
+
# is created and branch in the middleware.
|
9
|
+
class Delete
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@machine = env[:machine]
|
13
|
+
@logger = Log4r::Logger.new('vagrant::secured_cloud::action::delete')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
|
18
|
+
@logger.debug("Deleting VM ...")
|
19
|
+
|
20
|
+
vm_resource_url = @machine.id
|
21
|
+
|
22
|
+
if !vm_resource_url.nil? & !vm_resource_url.empty?
|
23
|
+
|
24
|
+
env[:ui].info(I18n.t("secured_cloud_vagrant.info.destroying"))
|
25
|
+
|
26
|
+
# Create a Secured Cloud Connection instance to connect tot he SecuredCloud API
|
27
|
+
authInfo = @machine.provider_config.auth
|
28
|
+
sc_connection = SecuredCloudConnection.new(authInfo.url, authInfo.applicationKey, authInfo.sharedSecret)
|
29
|
+
|
30
|
+
releasePublicIps = (env[:result].nil?) ? true : env[:result]
|
31
|
+
|
32
|
+
@logger.debug("Release public IPs: #{releasePublicIps}")
|
33
|
+
|
34
|
+
begin
|
35
|
+
|
36
|
+
# Send request to delete VM
|
37
|
+
response = SecuredCloudRestClient.deleteVM(sc_connection, vm_resource_url, releasePublicIps)
|
38
|
+
|
39
|
+
# Monitor the transaction.
|
40
|
+
if (response[0] == "202")
|
41
|
+
|
42
|
+
#Task successful.
|
43
|
+
taskResource = response[1]
|
44
|
+
taskStatus = SecuredCloudRestClient::getTaskStatus(sc_connection, taskResource)
|
45
|
+
|
46
|
+
@logger.info("Task Status:\n#{taskStatus.get_details()}")
|
47
|
+
|
48
|
+
while ((taskStatus.instance_variable_get(:@requestStateEnum) == nil) || (taskStatus.instance_variable_get(:@requestStateEnum) == "OPEN")) do
|
49
|
+
sleep(20)
|
50
|
+
taskStatus = SecuredCloudRestClient.getTaskStatus(sc_connection, taskResource)
|
51
|
+
env[:ui].info(I18n.t('secured_cloud_vagrant.info.task_status', :percentage => taskStatus.get_percentage_completed,
|
52
|
+
:task_desc => taskStatus.get_latest_task_description))
|
53
|
+
@logger.info("Task Status:\n#{taskStatus.get_details()}")
|
54
|
+
end
|
55
|
+
|
56
|
+
if(taskStatus.get_result.nil?)
|
57
|
+
|
58
|
+
#Task unsuccessful.
|
59
|
+
@logger.debug("VM Deletion failed with the following error:\n#{taskStatus.get_error_code}: #{taskStatus.get_error_message}")
|
60
|
+
|
61
|
+
error_code = (taskStatus.get_error_code.nil?) ? "" : "#{taskStatus.get_error_code} "
|
62
|
+
error_message = (taskStatus.get_error_message.nil?) ? I18n.t('secured_cloud_vagrant.errors.internal_server_error') :
|
63
|
+
error_code + taskStatus.get_error_message
|
64
|
+
|
65
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.deleting_vm", :vm_name => env[:vm_name], :error_message => error_message))
|
66
|
+
|
67
|
+
else
|
68
|
+
|
69
|
+
# Set the resource URL of the delete VM to null in the environment
|
70
|
+
@logger.debug("VM '#{env[:machine].id}' has been deleted")
|
71
|
+
env[:ui].info(I18n.t("secured_cloud_vagrant.info.success.delete_vm", :vm_name => env[:vm_name]))
|
72
|
+
|
73
|
+
env[:machine].id = nil
|
74
|
+
env[:vm_name] = nil
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
else
|
79
|
+
|
80
|
+
#Task unsuccessful.
|
81
|
+
@logger.debug("VM Deletion failed with the following error:\n#{response}")
|
82
|
+
|
83
|
+
error_message = (response[2].nil?) ? I18n.t('secured_cloud_vagrant.errors.internal_server_error') : response[2]
|
84
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.deleting_vm", :vm_name => env[:vm_name], :error_message => error_message))
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
rescue Errno::ETIMEDOUT
|
89
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.request_timed_out", :request => "delete VM '#{@machine.provider_config.vm.name}'"))
|
90
|
+
rescue Exception => e
|
91
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.generic_error", :error_message => e.message))
|
92
|
+
end
|
93
|
+
|
94
|
+
else
|
95
|
+
@logger.debug("No VM found to be deleted")
|
96
|
+
end
|
97
|
+
|
98
|
+
@app.call(env)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "secured_cloud_api_client"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module SecuredCloud
|
6
|
+
module Action
|
7
|
+
|
8
|
+
# This can be used with "Call" built-in to check if the machine
|
9
|
+
# is created and branch in the middleware.
|
10
|
+
class HasPublicIps
|
11
|
+
|
12
|
+
|
13
|
+
def initialize(app, env)
|
14
|
+
@app = app
|
15
|
+
@machine = env[:machine]
|
16
|
+
@logger = Log4r::Logger.new('vagrant::secured_cloud::action::has_public_ips')
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
|
21
|
+
@logger.debug("Checking whether VM has public IPs ...")
|
22
|
+
|
23
|
+
vm_resource_url = @machine.id
|
24
|
+
|
25
|
+
if !vm_resource_url.nil? && !vm_resource_url.empty?
|
26
|
+
|
27
|
+
begin
|
28
|
+
|
29
|
+
# Create a Secured Cloud Connection instance to connect to the SecuredCloud API
|
30
|
+
authInfo = @machine.provider_config.auth
|
31
|
+
sc_connection = SecuredCloudConnection.new(authInfo.url, authInfo.applicationKey, authInfo.sharedSecret)
|
32
|
+
|
33
|
+
# Get the public IPs of the VM
|
34
|
+
publicIps = SecuredCloudRestClient.getVMPublicIPs(sc_connection, vm_resource_url)
|
35
|
+
env[:has_public_ips] = (!publicIps.nil? && !publicIps.empty?)
|
36
|
+
@logger.debug("Has public IPs: #{env[:has_public_ips]}")
|
37
|
+
|
38
|
+
rescue Errno::ETIMEDOUT
|
39
|
+
env[:ui].error(I18n.t('secured_cloud_vagrant.errors.request_timed_out', :request => "get the public IPs for VM #{env[:vm_name]}"))
|
40
|
+
rescue Exception => e
|
41
|
+
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.generic_error", :error_message => e.message))
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
@app.call(env)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|