1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Move ssh private_key, public_key, username to Server model to reduce duplication

This commit is contained in:
Carlos Sanchez 2012-10-03 12:49:55 +02:00
parent e67eba360c
commit a25691ed23
16 changed files with 46 additions and 299 deletions

View file

@ -47,7 +47,6 @@ module Fog
attribute :vpc_id, :aliases => 'vpcId'
attr_accessor :password
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
attr_writer :iam_instance_profile_name, :iam_instance_profile_arn
@ -118,24 +117,6 @@ module Fog
self.key_name = new_keypair && new_keypair.name
end
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
def ready?
state == 'running'
end
@ -232,10 +213,6 @@ module Fog
true
end
def username
@username ||= 'root'
end
def volumes
requires :id
connection.volumes(:server => self)

View file

@ -1,10 +1,10 @@
require 'fog/core/model'
require 'fog/compute/models/server'
module Fog
module Compute
class AWS
class SpotRequest < Fog::Model
class SpotRequest < Fog::Compute::Server
identity :id, :aliases => 'spotInstanceRequestId'
@ -33,10 +33,6 @@ module Fog
attribute :fault, :squash => 'message'
attribute :user_data
attr_writer :private_key, :private_key_path, :public_key, :public_key_path
attr_writer :username
def initialize(attributes={})
self.groups ||= ["default"]
self.flavor_id ||= 't1.micro'
@ -74,24 +70,6 @@ module Fog
def key_pair=(new_keypair)
self.key_name = new_keypair && new_keypair.name
end
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
def ready?
state == 'active'

View file

@ -23,7 +23,6 @@ module Fog
attribute :template
attr_accessor :hostname, :password, :lb_applications, :lb_services, :lb_backends
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
def initialize(attributes={})
self.flavor_id ||= '94fd37a7-2606-47f7-84d5-9000deda52ae' # Block 1GB Virtual Server
@ -57,28 +56,10 @@ module Fog
nil
end
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
def public_ip_address
ips.first
end
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
def ready?
self.state == 'running'
end

View file

@ -1,19 +1,19 @@
require 'fog/core/model'
require 'fog/compute/models/server'
module Fog
module Compute
class Clodo
class Server < Fog::Model
class Server < Fog::Compute::Server
identity :id
attribute :addresses
attribute :name
attribute :image_id, :aliases => 'imageId'
attribute :type
attribute :type
attribute :state, :aliases => 'status'
attribute :type
attribute :type
attribute :vps_memory
attribute :vps_memory_max
attribute :vps_os_title
@ -40,8 +40,6 @@ module Fog
attribute :vps_user_pass
attribute :vps_vnc_pass
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
def initialize(attributes={})
self.image_id ||= attributes[:vps_os] ? attributes[:vps_os] : 666
super attributes
@ -62,15 +60,6 @@ module Fog
nil
end
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
def public_ip_address
pubaddrs = addresses && addresses['public'] ? addresses['public'].select {|ip| ip['primary_ip']} : nil
pubaddrs && !pubaddrs.empty? ? pubaddrs.first['ip'] : nil
@ -88,15 +77,6 @@ module Fog
connection.delete_ip_address(id, ip_address)
end
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
def ready?
self.state == 'is_running'
end
@ -129,28 +109,11 @@ module Fog
end
def ssh(commands)
requires :public_ip_address, :identity, :username
options = {}
options[:key_data] = [private_key] if private_key
options[:password] = password if password
Fog::SSH.new(public_ip_address, username, options).run(commands)
super(commands, password ? {:password => password} : {})
end
def scp(local_path, remote_path, upload_options = {})
requires :public_ip_address, :username
scp_options = {}
scp_options[:key_data] = [private_key] if private_key
Fog::SCP.new(public_ip_address, username, scp_options).upload(local_path, remote_path, upload_options)
end
def username
@username ||= 'root'
end
def password
vps_root_pass
def password
vps_root_pass
end
private

View file

@ -4,10 +4,31 @@ module Fog
module Compute
class Server < Fog::Model
def private_key=(key_data)
@private_key = key_data
attr_writer :username, :private_key, :private_key_path, :public_key, :public_key_path
def username
@username ||= 'root'
end
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
def scp(local_path, remote_path, upload_options = {})
require 'net/scp'
requires :public_ip_address, :username

View file

@ -84,10 +84,6 @@ module Fog
retry
end
def username
@username ||= 'root'
end
private
def adminPass=(new_admin_pass)

View file

@ -31,7 +31,7 @@ module Fog
attribute :public_ip_address
attr_reader :password
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username, :image_id, :flavor_id
attr_writer :image_id, :flavor_id
def initialize(attributes = {})
# assign these attributes first to prevent race condition with new_record?
@ -67,15 +67,6 @@ module Fog
addr["addr"] if addr
end
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
def public_ip_address
# FIX: Both the private and public ips are bundled under "private" network name
# So hack to get to the public ip address
@ -92,15 +83,6 @@ module Fog
end
end
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
def image_id
@image_id ||= (image.nil? ? nil : image["id"])
end
@ -211,10 +193,6 @@ module Fog
retry
end
def username
@username ||= 'root'
end
private
def adminPass=(new_admin_pass)

View file

@ -18,6 +18,10 @@ module Fog
attribute :created, :type => :time
attribute :updated, :type => :time
def public_ip_address
ips.empty? ? nil : ips.first
end
def ready?
self.state == 'running'
end

View file

@ -38,7 +38,6 @@ module Fog
attr_accessor :network_interface_type ,:network_nat_network, :network_bridge_name
attr_accessor :volume_format_type, :volume_allocation,:volume_capacity, :volume_name, :volume_pool_name, :volume_template_name, :volume_path
attr_accessor :password
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
# Can be created by passing in :xml => "<xml to create domain/server>"
# or by providing :template_options => {
@ -67,10 +66,6 @@ module Fog
raise Fog::Errors::Error.new("Error saving the server: #{e}")
end
def username
@username ||= 'root'
end
def start
return true if active?
connection.vm_action(uuid, :create)
@ -139,35 +134,14 @@ module Fog
ip_address(:public)
end
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
def ssh(commands)
requires :public_ip_address, :username
#requires :password, :private_key
ssh_options={}
ssh_options[:password] = password unless password.nil?
ssh_options[:key_data] = [private_key] if private_key
ssh_options[:proxy]= ssh_proxy unless ssh_proxy.nil?
Fog::SSH.new(public_ip_address, @username, ssh_options).run(commands)
super(commands, ssh_options)
end
def ssh_proxy

View file

@ -5,7 +5,6 @@ module Fog
class Linode
class Server < Fog::Compute::Server
attr_reader :stack_script
attr_accessor :private_key, :username
identity :id
attribute :name
attribute :status

View file

@ -40,7 +40,7 @@ module Fog
attribute :os_ext_sts_vm_state, :aliases => 'OS-EXT-STS:vm_state'
attr_reader :password
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username, :image_ref, :flavor_ref, :os_scheduler_hints
attr_writer :image_ref, :flavor_ref, :os_scheduler_hints
def initialize(attributes={})
@ -95,15 +95,6 @@ module Fog
end
end
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
def public_ip_address
if addresses['public']
#assume last is either original or assigned from floating IPs
@ -114,15 +105,6 @@ module Fog
end
end
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
def image_ref
@image_ref
end
@ -264,10 +246,6 @@ module Fog
retry
end
def username
@username ||= 'root'
end
private
def adminPass=(new_admin_pass)

View file

@ -19,7 +19,6 @@ module Fog
attribute :state, :aliases => 'status'
attr_reader :password
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
def initialize(attributes={})
self.flavor_id ||= 1 # 256 server
@ -52,28 +51,10 @@ module Fog
nil
end
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
def public_ip_address
addresses['public'].first
end
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
def ready?
self.state == 'ACTIVE'
end
@ -112,10 +93,6 @@ module Fog
retry
end
def username
@username ||= 'root'
end
private
def adminPass=(new_admin_pass)

View file

@ -26,7 +26,7 @@ module Fog
attribute :zone
attribute :active
attr_writer :password, :username
attr_writer :password
def initialize(attributes={})
super
@ -53,10 +53,6 @@ module Fog
true
end
def username
@username ||= 'root'
end
def clone(options)
requires :identity
connection.clone_server({:uniq_id => identity}.merge!(options))

View file

@ -1,10 +1,10 @@
require 'fog/core/model'
require 'fog/compute/models/server'
module Fog
module Compute
class VirtualBox
class Server < Fog::Model
class Server < Fog::Compute::Server
identity :id
@ -69,8 +69,6 @@ module Fog
# property :usb_controller, :USBController, :readonly => true
# property :vrde_server, :VRDEServer, :readonly => true
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
def initialize(attributes={})
self.memory_size = 256
self.rtc_use_utc = true
@ -102,28 +100,10 @@ module Fog
nil
end
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
def public_ip_address
nil
end
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
def ready?
status == :running
end
@ -151,15 +131,6 @@ module Fog
end
end
def scp(local_path, remote_path, upload_options = {})
raise 'Not Implemented'
# requires :addresses, :username
#
# options = {}
# options[:key_data] = [private_key] if private_key
# Fog::SCP.new(addresses['public'].first, username, options).upload(local_path, remote_path, scp_options)
end
def setup(credentials = {})
raise 'Not Implemented'
# requires :addresses, :identity, :public_key, :username
@ -175,15 +146,6 @@ module Fog
# retry
end
def ssh(commands)
raise 'Not Implemented'
# requires :addresses, :identity, :username
#
# options = {}
# options[:key_data] = [private_key] if private_key
# Fog::SSH.new(addresses['public'].first, username, options).run(commands)
end
def start(type = 'headless')
requires :raw
# session, type in ['gui', 'headless'], key[=value]\n env variables
@ -204,10 +166,6 @@ module Fog
)
end
def username
@username ||= 'root'
end
private
def raw

View file

@ -1,10 +1,10 @@
require 'fog/core/model'
require 'fog/compute/models/server'
module Fog
module Compute
class Vmfusion
class Server < Fog::Model
class Server < Fog::Compute::Server
identity :name
@ -14,7 +14,6 @@ module Fog
attribute :path
attr_accessor :password
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
# There is currently no documented model of creating VMs from scratch
# sans Fusion's wizard.
@ -179,21 +178,9 @@ module Fog
# Sets up a conveinent way to SSH into a Fusion VM using credentials
# stored in your .fog file.
def username
@username ||= 'root'
end
# Simply spawn an SSH session.
def ssh(commands)
requires :ipaddress, :username
#requires :password, :private_key
ssh_options={}
ssh_options[:password] = password unless password.nil?
ssh_options[:key_data] = [private_key] if private_key
Fog::SSH.new(ipaddress, @username, ssh_options).run(commands)
super(commands, password ? {:password => password} : {})
end
# SCP something to our VM.
@ -238,26 +225,6 @@ module Fog
Fog::SSH.new(ipaddress, username, credentials).run(commands)
end
# Just setting local versions of some variables that were going to use
# for SSH operations.
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
private
def ip(fission)
first_int = fission.network_info.data.keys.first

View file

@ -24,7 +24,7 @@ module Fog
attribute :instance_uuid
attribute :hostname
attribute :operatingsystem
attribute :ipaddress
attribute :ipaddress, :aliases => 'public_ip_address'
attribute :power_state, :aliases => 'power'
attribute :tools_state, :aliases => 'tools'
attribute :tools_version