Class: DownloadSnapshot

Inherits:
Ec2Script show all
Defined in:
lib/scripts/ec2/download_snapshot.rb

Overview

Script to download a specific snapshot as ZIP

  • create a specific instance (with Apache Server),

  • create a volume based on the snapshot

  • attach the volume

  • create a XSF-file-system

  • freeze the file-system

  • zip the file-system and copy it to the apache folder

  • wait 5 minutes (now the zip-file can be downloaded)

    • alternatively: copy it to S3 and make it downloadable

    • alternatively: copy it to an FTP server

Defined Under Namespace

Classes: DownloadSnapshotState, DownloadStoppedState, FileSystemsReady, InitialState, InstanceLaunchedState, InstanceShutDown, VolumeZippedAndDownloadableState, VolumesAttached, VolumesCreated

Instance Method Summary collapse

Methods inherited from Ec2Script

#get_execution_result, #post_message, #register_progress_message_listener, #register_state_change_listener, #start_script

Constructor Details

#initialize(input_params) ⇒ DownloadSnapshot

context information needed

  • the EC2 credentials (see #Ec2Script)

  • ami_id: the ID of the AMI to be started to perform the operations and to run the web-server for download

  • security_group_name => name of the security group used to start the AMI (should open ports for SSH and HTTP)

  • key_name => Name of the key to be used to access the instance providing the download

  • ssh_username => name of the ssh-user (default = root)

  • ssh_key_data => Key information for the security group that starts the AMI [if not set, use ssh_key_files]

  • ssh_key_files => Key information for the security group that starts the AMI

  • snapshot_id => The ID of the snapshot to be downloaded

  • wait_time (optional, default = 300) => time in sec during which the zipped snapshot is downloadable

  • zip_file_dest (optional, default = ‘/var/www/html’) => path of directory where the zipped volume is copied to

  • zip_file_name (option, default = ‘download’) => name of the zip-file to download



32
33
34
# File 'lib/scripts/ec2/download_snapshot.rb', line 32

def initialize(input_params)
  super(input_params)
end

Instance Method Details

#check_input_parametersObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/scripts/ec2/download_snapshot.rb', line 36

def check_input_parameters()
  if @input_params[:security_group_name] == nil
    @input_params[:security_group_name] = "default"
  end
  ec2_helper = Ec2Helper.new(@input_params[:ec2_api_handler])
  if !ec2_helper.check_open_port(@input_params[:security_group_name], 22)
    raise Exception.new("Port 22 must be opened for security group #{@input_params[:security_group_name]} to connect via SSH")
  end
  if @input_params[:source_device] == nil
    @input_params[:source_device] = "/dev/sdj1"
  end
  if @input_params[:dest_device] == nil
    @input_params[:dest_device] = "/dev/sdj2"
  end
  if @input_params[:zip_file_dest] == nil
    @input_params[:zip_file_dest] = "/var/www/html"
  end
  if @input_params[:zip_file_name] == nil
    @input_params[:zip_file_name] = "download"
  end
  if @input_params[:wait_time] == nil
    @input_params[:wait_time] = 300
  end
  if @input_params[:ssh_username] == nil
    @input_params[:ssh_username] = "root"
  end
end

#load_initial_stateObject

Load the initial state for the script. Abstract method to be implemented by extending classes.



66
67
68
# File 'lib/scripts/ec2/download_snapshot.rb', line 66

def load_initial_state()
  DownloadSnapshotState.load_state(@input_params)
end