mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[libvirt|compute] Updates reference to service
This commit is contained in:
parent
f6af5582b2
commit
43d1700ccb
12 changed files with 50 additions and 50 deletions
|
@ -15,7 +15,7 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def shutdown
|
def shutdown
|
||||||
connection.destroy_interface(mac)
|
service.destroy_interface(mac)
|
||||||
end
|
end
|
||||||
|
|
||||||
def active?
|
def active?
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Fog
|
||||||
model Fog::Compute::Libvirt::Interface
|
model Fog::Compute::Libvirt::Interface
|
||||||
|
|
||||||
def all(filter={})
|
def all(filter={})
|
||||||
load(connection.list_interfaces(filter))
|
load(service.list_interfaces(filter))
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(name)
|
def get(name)
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def shutdown
|
def shutdown
|
||||||
connection.destroy_network(uuid)
|
service.destroy_network(uuid)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Fog
|
||||||
model Fog::Compute::Libvirt::Network
|
model Fog::Compute::Libvirt::Network
|
||||||
|
|
||||||
def all(filter={})
|
def all(filter={})
|
||||||
load(connection.list_networks(filter))
|
load(service.list_networks(filter))
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(uuid)
|
def get(uuid)
|
||||||
|
|
|
@ -28,14 +28,14 @@ module Fog
|
||||||
def save
|
def save
|
||||||
raise Fog::Errors::Error.new('Creating a new nic is not yet implemented. Contributions welcome!')
|
raise Fog::Errors::Error.new('Creating a new nic is not yet implemented. Contributions welcome!')
|
||||||
#requires :server
|
#requires :server
|
||||||
#connection.attach_nic(domain , self)
|
#service.attach_nic(domain , self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
raise Fog::Errors::Error.new('Destroying an interface is not yet implemented. Contributions welcome!')
|
raise Fog::Errors::Error.new('Destroying an interface is not yet implemented. Contributions welcome!')
|
||||||
#requires :server
|
#requires :server
|
||||||
##detach the nic
|
##detach the nic
|
||||||
#connection.detach_nic(domain, mac)
|
#service.detach_nic(domain, mac)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Fog
|
||||||
model Fog::Compute::Libvirt::Node
|
model Fog::Compute::Libvirt::Node
|
||||||
|
|
||||||
def all(filter={ })
|
def all(filter={ })
|
||||||
load(connection.get_node_info)
|
load(service.get_node_info)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get
|
def get
|
||||||
|
|
|
@ -26,20 +26,20 @@ module Fog
|
||||||
|
|
||||||
def save
|
def save
|
||||||
raise Fog::Errors::Error.new('Creating a new pool requires proper xml') unless xml
|
raise Fog::Errors::Error.new('Creating a new pool requires proper xml') unless xml
|
||||||
self.uuid = (persistent ? connection.define_pool(xml) : connection.create_pool(xml)).uuid
|
self.uuid = (persistent ? service.define_pool(xml) : service.create_pool(xml)).uuid
|
||||||
reload
|
reload
|
||||||
end
|
end
|
||||||
|
|
||||||
# Start the pool = make it active
|
# Start the pool = make it active
|
||||||
# Performs a libvirt create (= start)
|
# Performs a libvirt create (= start)
|
||||||
def start
|
def start
|
||||||
connection.pool_action uuid, :create
|
service.pool_action uuid, :create
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stop the pool = make it non-active
|
# Stop the pool = make it non-active
|
||||||
# Performs a libvirt destroy (= stop)
|
# Performs a libvirt destroy (= stop)
|
||||||
def stop
|
def stop
|
||||||
connection.pool_action uuid, :destroy
|
service.pool_action uuid, :destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
# Shuts down the pool
|
# Shuts down the pool
|
||||||
|
@ -49,15 +49,15 @@ module Fog
|
||||||
|
|
||||||
# Build this storage pool
|
# Build this storage pool
|
||||||
def build
|
def build
|
||||||
connection.pool_action uuid, :build
|
service.pool_action uuid, :build
|
||||||
end
|
end
|
||||||
|
|
||||||
# Destroys the storage pool
|
# Destroys the storage pool
|
||||||
def destroy
|
def destroy
|
||||||
# Shutdown pool if active
|
# Shutdown pool if active
|
||||||
connection.pool_action uuid, :destroy if active?
|
service.pool_action uuid, :destroy if active?
|
||||||
# If this is a persistent domain we need to undefine it
|
# If this is a persistent domain we need to undefine it
|
||||||
connection.pool_action uuid, :undefine if persistent?
|
service.pool_action uuid, :undefine if persistent?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Is the pool active or not?
|
# Is the pool active or not?
|
||||||
|
@ -77,7 +77,7 @@ module Fog
|
||||||
|
|
||||||
# Retrieves the volumes of this pool
|
# Retrieves the volumes of this pool
|
||||||
def volumes
|
def volumes
|
||||||
connection.list_pool_volumes uuid
|
service.list_pool_volumes uuid
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Fog
|
||||||
model Fog::Compute::Libvirt::Pool
|
model Fog::Compute::Libvirt::Pool
|
||||||
|
|
||||||
def all(filter = {})
|
def all(filter = {})
|
||||||
load(connection.list_pools(filter))
|
load(service.list_pools(filter))
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(uuid)
|
def get(uuid)
|
||||||
|
|
|
@ -60,7 +60,7 @@ module Fog
|
||||||
raise Fog::Errors::Error.new('Saving an existing server may create a duplicate') unless new?
|
raise Fog::Errors::Error.new('Saving an existing server may create a duplicate') unless new?
|
||||||
create_or_clone_volume unless xml or @volumes
|
create_or_clone_volume unless xml or @volumes
|
||||||
@xml ||= to_xml
|
@xml ||= to_xml
|
||||||
self.id = (persistent ? connection.define_domain(xml) : connection.create_domain(xml)).uuid
|
self.id = (persistent ? service.define_domain(xml) : service.create_domain(xml)).uuid
|
||||||
reload
|
reload
|
||||||
rescue => e
|
rescue => e
|
||||||
raise Fog::Errors::Error.new("Error saving the server: #{e}")
|
raise Fog::Errors::Error.new("Error saving the server: #{e}")
|
||||||
|
@ -68,7 +68,7 @@ module Fog
|
||||||
|
|
||||||
def start
|
def start
|
||||||
return true if active?
|
return true if active?
|
||||||
connection.vm_action(uuid, :create)
|
service.vm_action(uuid, :create)
|
||||||
reload
|
reload
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -83,29 +83,29 @@ module Fog
|
||||||
|
|
||||||
def destroy(options={ :destroy_volumes => false})
|
def destroy(options={ :destroy_volumes => false})
|
||||||
poweroff unless stopped?
|
poweroff unless stopped?
|
||||||
connection.vm_action(uuid, :undefine)
|
service.vm_action(uuid, :undefine)
|
||||||
volumes.each { |vol| vol.destroy } if options[:destroy_volumes]
|
volumes.each { |vol| vol.destroy } if options[:destroy_volumes]
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def reboot
|
def reboot
|
||||||
connection.vm_action(uuid, :reboot)
|
service.vm_action(uuid, :reboot)
|
||||||
end
|
end
|
||||||
|
|
||||||
def poweroff
|
def poweroff
|
||||||
connection.vm_action(uuid, :destroy)
|
service.vm_action(uuid, :destroy)
|
||||||
end
|
end
|
||||||
|
|
||||||
def shutdown
|
def shutdown
|
||||||
connection.vm_action(uuid, :shutdown)
|
service.vm_action(uuid, :shutdown)
|
||||||
end
|
end
|
||||||
|
|
||||||
def resume
|
def resume
|
||||||
connection.vm_action(uuid, :resume)
|
service.vm_action(uuid, :resume)
|
||||||
end
|
end
|
||||||
|
|
||||||
def suspend
|
def suspend
|
||||||
connection.vm_action(uuid, :suspend)
|
service.vm_action(uuid, :suspend)
|
||||||
end
|
end
|
||||||
|
|
||||||
def stopped?
|
def stopped?
|
||||||
|
@ -123,7 +123,7 @@ module Fog
|
||||||
|
|
||||||
def volumes
|
def volumes
|
||||||
# lazy loading of volumes
|
# lazy loading of volumes
|
||||||
@volumes ||= (@volumes_path || []).map{|path| connection.volumes.all(:path => path).first }
|
@volumes ||= (@volumes_path || []).map{|path| service.volumes.all(:path => path).first }
|
||||||
end
|
end
|
||||||
|
|
||||||
def private_ip_address
|
def private_ip_address
|
||||||
|
@ -147,8 +147,8 @@ module Fog
|
||||||
def ssh_proxy
|
def ssh_proxy
|
||||||
# if this is a direct connection, we don't need a proxy to be set.
|
# if this is a direct connection, we don't need a proxy to be set.
|
||||||
return nil unless connection.uri.ssh_enabled?
|
return nil unless connection.uri.ssh_enabled?
|
||||||
user_string= connection.uri.user ? "-l #{connection.uri.user}" : ""
|
user_string= service.uri.user ? "-l #{service.uri.user}" : ""
|
||||||
Net::SSH::Proxy::Command.new("ssh #{user_string} #{connection.uri.host} nc %h %p")
|
Net::SSH::Proxy::Command.new("ssh #{user_string} #{service.uri.host} nc %h %p")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Transfers a file
|
# Transfers a file
|
||||||
|
@ -197,7 +197,7 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_display attrs = {}
|
def update_display attrs = {}
|
||||||
connection.update_display attrs.merge(:uuid => uuid)
|
service.update_display attrs.merge(:uuid => uuid)
|
||||||
reload
|
reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -214,32 +214,32 @@ module Fog
|
||||||
# It returns an array of public and private ip addresses
|
# It returns an array of public and private ip addresses
|
||||||
# Currently only one ip address is returned, but in the future this could be multiple
|
# Currently only one ip address is returned, but in the future this could be multiple
|
||||||
# if the server has multiple network interface
|
# if the server has multiple network interface
|
||||||
def addresses(connection=connection, options={})
|
def addresses(service=service, options={})
|
||||||
mac=self.mac
|
mac=self.mac
|
||||||
|
|
||||||
# Aug 24 17:34:41 juno arpwatch: new station 10.247.4.137 52:54:00:88:5a:0a eth0.4
|
# Aug 24 17:34:41 juno arpwatch: new station 10.247.4.137 52:54:00:88:5a:0a eth0.4
|
||||||
# Aug 24 17:37:19 juno arpwatch: changed ethernet address 10.247.4.137 52:54:00:27:33:00 (52:54:00:88:5a:0a) eth0.4
|
# Aug 24 17:37:19 juno arpwatch: changed ethernet address 10.247.4.137 52:54:00:27:33:00 (52:54:00:88:5a:0a) eth0.4
|
||||||
# Check if another ip_command string was provided
|
# Check if another ip_command string was provided
|
||||||
ip_command_global=connection.ip_command.nil? ? 'grep $mac /var/log/arpwatch.log|sed -e "s/new station//"|sed -e "s/changed ethernet address//g" |sed -e "s/reused old ethernet //" |tail -1 |cut -d ":" -f 4-| cut -d " " -f 3' : connection.ip_command
|
ip_command_global=service.ip_command.nil? ? 'grep $mac /var/log/arpwatch.log|sed -e "s/new station//"|sed -e "s/changed ethernet address//g" |sed -e "s/reused old ethernet //" |tail -1 |cut -d ":" -f 4-| cut -d " " -f 3' : service.ip_command
|
||||||
ip_command_local=options[:ip_command].nil? ? ip_command_global : options[:ip_command]
|
ip_command_local=options[:ip_command].nil? ? ip_command_global : options[:ip_command]
|
||||||
|
|
||||||
ip_command="mac=#{mac}; server_name=#{name}; "+ip_command_local
|
ip_command="mac=#{mac}; server_name=#{name}; "+ip_command_local
|
||||||
|
|
||||||
ip_address=nil
|
ip_address=nil
|
||||||
|
|
||||||
if connection.uri.ssh_enabled?
|
if service.uri.ssh_enabled?
|
||||||
|
|
||||||
# Retrieve the parts we need from the connection to setup our ssh options
|
# Retrieve the parts we need from the service to setup our ssh options
|
||||||
user=connection.uri.user #could be nil
|
user=service.uri.user #could be nil
|
||||||
host=connection.uri.host
|
host=service.uri.host
|
||||||
keyfile=connection.uri.keyfile
|
keyfile=service.uri.keyfile
|
||||||
port=connection.uri.port
|
port=service.uri.port
|
||||||
|
|
||||||
# Setup the options
|
# Setup the options
|
||||||
ssh_options={}
|
ssh_options={}
|
||||||
ssh_options[:keys]=[ keyfile ] unless keyfile.nil?
|
ssh_options[:keys]=[ keyfile ] unless keyfile.nil?
|
||||||
ssh_options[:port]=port unless keyfile.nil?
|
ssh_options[:port]=port unless keyfile.nil?
|
||||||
ssh_options[:paranoid]=true if connection.uri.no_verify?
|
ssh_options[:paranoid]=true if service.uri.no_verify?
|
||||||
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -261,7 +261,7 @@ module Fog
|
||||||
|
|
||||||
else
|
else
|
||||||
# It's not ssh enabled, so we assume it is
|
# It's not ssh enabled, so we assume it is
|
||||||
if connection.uri.transport=="tls"
|
if service.uri.transport=="tls"
|
||||||
raise Fog::Errors::Error.new("TlS remote transport is not currently supported, only ssh")
|
raise Fog::Errors::Error.new("TlS remote transport is not currently supported, only ssh")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -310,15 +310,15 @@ module Fog
|
||||||
|
|
||||||
def initialize_nics
|
def initialize_nics
|
||||||
if nics
|
if nics
|
||||||
nics.map! { |nic| nic.is_a?(Hash) ? connection.nics.new(nic) : nic }
|
nics.map! { |nic| nic.is_a?(Hash) ? service.nics.new(nic) : nic }
|
||||||
else
|
else
|
||||||
self.nics = [connection.nics.new({:type => network_interface_type, :bridge => network_bridge_name, :network => network_nat_network})]
|
self.nics = [service.nics.new({:type => network_interface_type, :bridge => network_bridge_name, :network => network_nat_network})]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize_volumes
|
def initialize_volumes
|
||||||
if attributes[:volumes] && !attributes[:volumes].empty?
|
if attributes[:volumes] && !attributes[:volumes].empty?
|
||||||
@volumes = attributes[:volumes].map { |vol| vol.is_a?(Hash) ? connection.volumes.new(vol) : vol }
|
@volumes = attributes[:volumes].map { |vol| vol.is_a?(Hash) ? service.volumes.new(vol) : vol }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ module Fog
|
||||||
options = {:name => volume_name || default_volume_name}
|
options = {:name => volume_name || default_volume_name}
|
||||||
# Check if a disk template was specified
|
# Check if a disk template was specified
|
||||||
if volume_template_name
|
if volume_template_name
|
||||||
template_volume = connection.volumes.all(:name => volume_template_name).first
|
template_volume = service.volumes.all(:name => volume_template_name).first
|
||||||
raise Fog::Errors::Error.new("Template #{volume_template_name} not found") unless template_volume
|
raise Fog::Errors::Error.new("Template #{volume_template_name} not found") unless template_volume
|
||||||
begin
|
begin
|
||||||
volume = template_volume.clone("#{options[:name]}")
|
volume = template_volume.clone("#{options[:name]}")
|
||||||
|
@ -341,7 +341,7 @@ module Fog
|
||||||
options[:allocation] = volume_allocation if volume_allocation
|
options[:allocation] = volume_allocation if volume_allocation
|
||||||
|
|
||||||
begin
|
begin
|
||||||
volume = connection.volumes.create(options)
|
volume = service.volumes.create(options)
|
||||||
rescue => e
|
rescue => e
|
||||||
raise Fog::Errors::Error.new("Error creating the volume : #{e}")
|
raise Fog::Errors::Error.new("Error creating the volume : #{e}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,11 +10,11 @@ module Fog
|
||||||
model Fog::Compute::Libvirt::Server
|
model Fog::Compute::Libvirt::Server
|
||||||
|
|
||||||
def all(filter={})
|
def all(filter={})
|
||||||
load(connection.list_domains(filter))
|
load(service.list_domains(filter))
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(uuid)
|
def get(uuid)
|
||||||
data = connection.list_domains(:uuid => uuid)
|
data = service.list_domains(:uuid => uuid)
|
||||||
new data.first if data
|
new data.first if data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,17 +38,17 @@ module Fog
|
||||||
|
|
||||||
raise Fog::Errors::Error.new('Reserving an existing volume may create a duplicate') if key
|
raise Fog::Errors::Error.new('Reserving an existing volume may create a duplicate') if key
|
||||||
@xml ||= to_xml
|
@xml ||= to_xml
|
||||||
self.path = connection.create_volume(pool_name, xml).path
|
self.path = service.create_volume(pool_name, xml).path
|
||||||
end
|
end
|
||||||
|
|
||||||
# Destroy a volume
|
# Destroy a volume
|
||||||
def destroy
|
def destroy
|
||||||
connection.volume_action key, :delete
|
service.volume_action key, :delete
|
||||||
end
|
end
|
||||||
|
|
||||||
# Wipes a volume , zeroes disk
|
# Wipes a volume , zeroes disk
|
||||||
def wipe
|
def wipe
|
||||||
connection.volume_action key, :wipe
|
service.volume_action key, :wipe
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clones this volume to the name provided
|
# Clones this volume to the name provided
|
||||||
|
@ -75,10 +75,10 @@ module Fog
|
||||||
# Try to guess the default/first pool of no pool_name was specified
|
# Try to guess the default/first pool of no pool_name was specified
|
||||||
def default_pool_name
|
def default_pool_name
|
||||||
name = "default"
|
name = "default"
|
||||||
return name unless (connection.pools.all(:name => name)).empty?
|
return name unless (service.pools.all(:name => name)).empty?
|
||||||
|
|
||||||
# we default to the first pool we find.
|
# we default to the first pool we find.
|
||||||
first_pool = connection.pools.first
|
first_pool = service.pools.first
|
||||||
|
|
||||||
raise Fog::Errors::Error.new('No storage pools are defined') unless first_pool
|
raise Fog::Errors::Error.new('No storage pools are defined') unless first_pool
|
||||||
first_pool.name
|
first_pool.name
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Fog
|
||||||
model Fog::Compute::Libvirt::Volume
|
model Fog::Compute::Libvirt::Volume
|
||||||
|
|
||||||
def all(filter = {})
|
def all(filter = {})
|
||||||
load(connection.list_volumes(filter))
|
load(service.list_volumes(filter))
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(key)
|
def get(key)
|
||||||
|
|
Loading…
Reference in a new issue