class Qtc::Cli::Platform::Vpn
Public Instance Methods
base_url()
click to toggle source
# File lib/qtc/cli/platform/vpn.rb, line 83 def base_url datacenters = inifile['datacenters'] || {} if !self.vpn_datacenter_id.nil? && datacenters.has_key?(self.vpn_datacenter_id) "#{datacenters[self.vpn_datacenter_id]}/v1" else raise ArgumentError.new('Unknown datacenter. Please run qtc-cli datacenters to get latest list of your datacenters') end end
client()
click to toggle source
@return [Qtc::Client]
# File lib/qtc/cli/platform/vpn.rb, line 75 def client if @client.nil? @client = Qtc::Client.new(base_url) end @client end
config()
click to toggle source
# File lib/qtc/cli/platform/vpn.rb, line 53 def config all = client.get('/vpn_containers', {}, {'Authorization' => "Bearer #{current_cloud_token}"}) if all['results'][0] vpn = all['results'][0] if vpn['state'] != 'running' puts 'Cannot get config because vpn is not running' exit 1 end vpn = client.get("/vpn_containers/#{vpn['id']}", {}, {'Authorization' => "Bearer #{current_cloud_token}"}) if vpn['vpn_config'] puts Base64.decode64(vpn['vpn_config']) end end end
create()
click to toggle source
# File lib/qtc/cli/platform/vpn.rb, line 8 def create self.datacenter_id = vpn_datacenter_id client.post('/vpn_containers', {name: 'default vpn'}, {}, {'Authorization' => "Bearer #{current_cloud_token}"}) end
destroy()
click to toggle source
# File lib/qtc/cli/platform/vpn.rb, line 45 def destroy result = client.get('/vpn_containers', {}, {'Authorization' => "Bearer #{current_cloud_token}"}) vpn = result['results'][0] if vpn client.delete("/vpn_containers/#{vpn['id']}", {}, {}, {'Authorization' => "Bearer #{current_cloud_token}"}) end end
show()
click to toggle source
# File lib/qtc/cli/platform/vpn.rb, line 13 def show result = client.get('/vpn_containers', {}, {'Authorization' => "Bearer #{current_cloud_token}"}) vpn = result['results'][0] if vpn puts "id: #{vpn['id']}" puts "name: #{vpn['name']}" puts "state: #{vpn['state']}" else puts 'vpn not found, you can create vpn service with: qtc-cli vpn:create' end end
start()
click to toggle source
# File lib/qtc/cli/platform/vpn.rb, line 25 def start result = client.get('/vpn_containers', {}, {'Authorization' => "Bearer #{current_cloud_token}"}) vpn = result['results'][0] if vpn client.post("/vpn_containers/#{vpn['id']}/start", {}, {}, {'Authorization' => "Bearer #{current_cloud_token}"}) else puts 'vpn not found, you can create vpn service with: qtc-cli vpn:create' end end
stop()
click to toggle source
# File lib/qtc/cli/platform/vpn.rb, line 35 def stop result = client.get('/vpn_containers', {}, {'Authorization' => "Bearer #{current_cloud_token}"}) vpn = result['results'][0] if vpn client.post("/vpn_containers/#{vpn['id']}/stop", {}, {}, {'Authorization' => "Bearer #{current_cloud_token}"}) else puts 'vpn not found, you can create vpn service with: qtc-cli mdb vpn:create' end end
vpn_datacenter_id()
click to toggle source
# File lib/qtc/cli/platform/vpn.rb, line 69 def vpn_datacenter_id "mdb-#{current_cloud_dc}" end