Class: Dcmgr::Cli::Image::AddOperation

Inherits:
Base
  • Object
show all
Defined in:
lib/dcmgr/cli/image.rb

Instance Method Summary collapse

Instance Method Details

#local(location) ⇒ Object

method_option :state, :type => :string, :default => “init”, :desc => “The state for the new machine image”



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dcmgr/cli/image.rb', line 20

def local(location)
  UnknownUUIDError.raise(options[:account_id]) if M::Account[options[:account_id]].nil?
  UnsupportedArchError.raise(options[:arch]) unless M::HostNode::SUPPORTED_ARCH.member?(options[:arch])
  
  full_path = File.expand_path(location)
  File.exists?(full_path) || Error.raise("File not found: #{full_path}",100)
  
  #TODO: Check if :state is a valid state
  fields = options.dup
  fields[:boot_dev_type]=M::Image::BOOT_DEV_LOCAL
  fields[:source] = {
    :uri => "file://#{full_path}",
  }
  puts add(M::Image, fields)
end

#volume(snapshot_id) ⇒ Object

method_option :state, :type => :string, :default => “init”, :desc => “The state for the new machine image”



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dcmgr/cli/image.rb', line 44

def volume(snapshot_id)
  UnknownUUIDError.raise(options[:account_id]) if M::Account[options[:account_id]].nil?
  UnsupportedArchError.raise(options[:arch]) unless M::HostNode::SUPPORTED_ARCH.member?(options[:arch])
  UnknownUUIDError.raise(snapshot_id) if M::VolumeSnapshot[snapshot_id].nil?
  #TODO: Check if :state is a valid state
  fields = options.dup
  fields[:boot_dev_type]=M::Image::BOOT_DEV_SAN
  fields[:source] = {
    :snapshot_id => snapshot_id,
  }
  puts add(M::Image, fields)
end