class Kitchen::Driver::Centurylink
Centurylink
driver for Kitchen
.
@author Anthony Howell
Public Instance Methods
assign_public_ip(state)
click to toggle source
# File lib/kitchen/driver/centurylink.rb, line 112 def assign_public_ip(state) response = @@client.addPublicIpAddress(config[:accountAlias], state[:server_id], { :ports => [ {:protocol => 'TCP', :port => 80}, {:protocol => 'TCP', :port => 8080}, {:protocol => 'TCP', :port => 443}, {:protocol => 'TCP', :port => 22}, ]}) puts response statusId = response['id'] status = @@client.getQueueStatus(config[:accountAlias], statusId) while status['status'] != 'succeeded' do info "Waiting for public IP job to complete. Status is #{status["status"]}" sleep 20 status = @@client.getQueueStatus(config[:accountAlias], statusId) end serverInfo = @@client.getServerDetails(config[:accountAlias], state[:server_id]) state[:hostname] = serverInfo['details']['ipAddresses'].find {|ipSet| ipSet['public'] }['public'] info "Assigned public IP of: #{state[:hostname]}" end
create(state)
click to toggle source
# File lib/kitchen/driver/centurylink.rb, line 42 def create(state) if !config[:token] && !state[:token] puts 'No CLC API token was found. Please enter your credentials to have one generated.' generateToken(state) end if !config[:groupId] puts 'No groupId was set. Please set groupId in .kitchen.yml and try again' puts 'See --> http://www.centurylinkcloud.com/api-docs/v2/#servers-create-server#request' raise 'Incorrect config' end @@client.setToken(config[:token] || state[:token]) queueId = create_server serverInfo = @@client.getServerDetails(config[:accountAlias], queueId + '?uuid=True') info 'Checking server status before continuing' while serverInfo['status'] != 'active' do info "Server not up. Server status is: #{serverInfo['status']}." serverInfo = @@client.getServerDetails(config[:accountAlias], queueId + '?uuid=True') sleep 20 end info serverInfo state[:server_id] = serverInfo["id"] info "Created server with id #{state[:server_id]}" if config[:assign_public_ip] info 'Assigning public IP' assign_public_ip(state) else state[:hostname] = serverInfo['details']['ipAddresses'][0]['internal'] end end
create_server()
click to toggle source
# File lib/kitchen/driver/centurylink.rb, line 92 def create_server info 'Sending create server request' response = @@client.createServer(config[:accountAlias], { :name => config[:server_name], :groupId => config[:groupId], :cpu => config[:cpu], :memoryGB => config[:memoryGB], :sourceServerId => config[:serverTemplate], :type => config[:type], :password => config[:password], }) debug response serverId = response['links'].select {|x| x['rel']=="self"}[0]['id'] puts "Server request accepted, with request id #{serverId}" serverId end
destroy(state)
click to toggle source
# File lib/kitchen/driver/centurylink.rb, line 80 def destroy(state) info "Sending delete request for server #{state[:server_id]}" @@client.setToken(config[:token] || state[:token]) response = @@client.deleteServer(config[:accountAlias], state[:server_id]) if response['isQueued'] == true info 'Delete request is queued up' state.delete(:server_id) state.delete(:hostname) end end
generateToken(state)
click to toggle source
# File lib/kitchen/driver/centurylink.rb, line 134 def generateToken(state) if !config[:clc_username] username = ask 'Username:' end password = ask ('Password:') { |q| q.echo = false } token = @@client.login username, password info 'Generated new token:' info token info "Save this to your project's .kitchen.yml file to use for future logins" state[:token] = token end