Class: Iravat::IrEC2InstanceInitializer
- Inherits:
-
Object
- Object
- Iravat::IrEC2InstanceInitializer
- Defined in:
- lib/ec2/ir_ec2_instance_initializer.rb
Overview
require ‘./ir_module’
Instance Method Summary collapse
-
#error_ec2(err) ⇒ Object
common error handler for RightScale Lib.
- #initializationSetupOnEC2(userName, password, s3UserStorageName) ⇒ Object
-
#initialize(instanceIDToCheck) ⇒ IrEC2InstanceInitializer
constructor
A new instance of IrEC2InstanceInitializer.
- #waitForEC2InstanceToGetRunning ⇒ Object
Constructor Details
#initialize(instanceIDToCheck) ⇒ IrEC2InstanceInitializer
Returns a new instance of IrEC2InstanceInitializer.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ec2/ir_ec2_instance_initializer.rb', line 7 def initialize(instanceIDToCheck) @logger = IrLogger.new(self.class.name).getLog4rLogger() awsConfig=IrAwsConfigManager.new(IRAVAT_AWS_CONFIG_XML_PATH) awsConfig.loadConfigurationFile() @awsKeyID=awsConfig.getPathFromXML("/ChipMonkAWSConfigs/AWSAccessKey/AWSAccessKey") @awsSecretKey=awsConfig.getPathFromXML("/ChipMonkAWSConfigs/AWSAccessKey/AWSAccessSecretKey") @maxRetries=Integer(awsConfig.getPathFromXML("/ChipMonkAWSConfigs/EC2/MaxRetriesToCheckRunning")) @minRetryInterval=Integer(awsConfig.getPathFromXML("/ChipMonkAWSConfigs/EC2/MaxRetriesToCheckRunning")) @sshKeyPath=awsConfig.getPathFromXML("/ChipMonkAWSConfigs/EC2/SSHKeyPathToLogin") @dirCopyPath=awsConfig.getPathFromXML("/ChipMonkAWSConfigs/EC2/BundlePathToCopy") @scriptToExecute=awsConfig.getPathFromXML("/ChipMonkAWSConfigs/EC2/BundleInitScriptToExecute") @s3ToolMountS3=awsConfig.getPathFromXML("/ChipMonkAWSConfigs/EC2/S3ToolInstanceName") @instanceID=instanceIDToCheck @logger.info("Checking for instance id" + instanceIDToCheck) end |
Instance Method Details
#error_ec2(err) ⇒ Object
common error handler for RightScale Lib
24 25 26 27 28 |
# File 'lib/ec2/ir_ec2_instance_initializer.rb', line 24 def error_ec2 (err) err.errors.each do |e| @logger.error(err.errors) end end |
#initializationSetupOnEC2(userName, password, s3UserStorageName) ⇒ Object
77 78 |
# File 'lib/ec2/ir_ec2_instance_initializer.rb', line 77 def initializationSetupOnEC2(userName, password, s3ToolStorageName) end |
#waitForEC2InstanceToGetRunning ⇒ Object
30 31 32 33 34 35 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 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ec2/ir_ec2_instance_initializer.rb', line 30 def waitForEC2InstanceToGetRunning() #return true when successful #return false when unsuccessful and log the error #errors can be # No instance found for the instance ID # Unable to connect to Amazon with the mentioned accesskey # Able to connect to AWS but instance state is not running begin ec2 = RightAws::Ec2.new(@awsKeyID,@awsSecretKey) if(ec2.nil?) @logger.error("Failed to create an access to EC2") return false end i = 0 while i < @maxRetries awsInstances=ec2.describe_instances([@instanceID]) if awsInstances.nil? @logger.error("Failed to initialize the instance " + @instanceID + " instance details could not be fetched ") return false end if awsInstances.length <= 0 @logger.error("Failed to initialize the instance " + @instanceID + " instance details could not be correctly fetched ") return false end awsInstances.each do |awsInstance| if( awsInstance[:aws_state] == "running" and awsInstance[:aws_instance_id] == @instanceID) @publicDomainName=awsInstance[:dns_name] #we are done as we have got the state as running from AWS return true end end @logger.debug ("put to retry" ) sleep @minRetryInterval end @logger.error("Failed to get the instance " + @instanceID + " running!!!") return false rescue RightAws::AwsError => err self.error_ec2(err) return false end end |