68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/secured-cloud-vagrant/actions/assign_public_ips.rb', line 68
def assign_public_ip(private_ip, public_ip, env)
begin
response = SecuredCloudRestClient::assignPublicIpToVM(@sc_connection, @machine.id, public_ip, private_ip)
if (response[0] == "202")
taskResource = response[1]
taskStatus = SecuredCloudRestClient::getTaskStatus(@sc_connection, taskResource)
@logger.info("Task Status:\n#{taskStatus.get_details()}")
while ((taskStatus.instance_variable_get(:@requestStateEnum) == nil) || (taskStatus.instance_variable_get(:@requestStateEnum) == "OPEN")) do
sleep(20)
taskStatus = SecuredCloudRestClient.getTaskStatus(@sc_connection, taskResource)
env[:ui].info(I18n.t('secured_cloud_vagrant.info.task_status', :percentage => taskStatus.get_percentage_completed,
:task_desc => taskStatus.get_latest_task_description))
@logger.info("Task Status:\n#{taskStatus.get_details()}")
end
if(taskStatus.get_result.nil?)
@logger.debug("Public IP assignment failed with the following error:\n#{taskStatus.get_error_code}: #{taskStatus.get_error_message}")
error_code = (taskStatus.get_error_code.nil?) ? "" : "#{taskStatus.get_error_code} "
error_message = (taskStatus.get_error_message.nil?) ? I18n.t('secured_cloud_vagrant.errors.internal_server_error') :
error_code + taskStatus.get_error_message
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.assigning_public_ip", :vm_name => env[:vm_name], :error_message => error_message))
else
if(public_ip.nil?)
@logger.debug("VM #{env[:vm_name]} has been assigned a public IP from the global pool")
env[:ui].info(I18n.t("secured_cloud_vagrant.info.success.assign_public_ip.global_pool", :vm_name => env[:vm_name]))
else
@logger.debug("VM #{env[:vm_name]} has been assigned public IP '#{public_ip}' from the reserve pool")
env[:ui].info(I18n.t("secured_cloud_vagrant.info.success.assign_public_ip.reserve_pool", :vm_name => env[:vm_name],
:public_ip => public_ip))
end
end
else
@logger.debug("Public IP assignment failed with the following error:\n#{response}")
error_message = (response[2].nil?) ? I18n.t('secured_cloud_vagrant.errors.internal_server_error') : response[2]
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.assigning_public_ip", :vm_name => env[:vm_name],
:error_message => error_message))
end
rescue Errno::ETIMEDOUT
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.request_timed_out", :request => "assign a public IP"))
rescue Exception => e
env[:ui].error(I18n.t("secured_cloud_vagrant.errors.generic_error", :error_message => e.message))
end
end
|