Startup the ec2 instance

def startup(self):
        """Startup the ec2 instance
        """
        import boto.ec2

        if not self.browser_config.get('launch'):
            self.warning_log("Skipping launch")
            return True

        self.info_log("Starting up")

        instance = None
        try:

            # KEY NAME
            key_name = self.browser_config.get(
                "ssh_key_path"
            ).split(os.sep)[-1][:-4]
            # SECURITY GROUP

            if type(self.browser_config.get("security_group_ids")) == str:
                security_group_ids = [
                    self.browser_config.get("security_group_ids")
                ]

            elif type(self.browser_config.get("security_group_ids")) == list:
                security_group_ids = self.browser_config.get(
                    "security_group_ids"
                )

            else:
                msg = "The config security_group_ids must be a string or a list of string"  # noqa
                self.critial_log(msg)
                raise Exception(msg)

            # LAUNCH INSTANCE
            ec2 = boto.ec2.connect_to_region(self.browser_config.get("region"))
            reservation = ec2.run_instances(
                    self.browser_config.get('amiid'),
                    key_name=key_name,
                    instance_type=self.browser_config.get("instance_type"),
                    security_group_ids=security_group_ids
            )

            wait_after_instance_launched = BROME_CONFIG['ec2']['wait_after_instance_launched']  # noqa
            if wait_after_instance_launched:
                self.info_log(
                    "Waiting after instance launched: %s seconds..." %
                    wait_after_instance_launched
                )
                sleep(wait_after_instance_launched)

            else:
                self.warning_log("Skipping waiting after instance launched")

            try:
                instance = reservation.instances[0]

            except Exception as e:
                self.critical_log(
                    'Instance reservation exception: %s' % str(e)
                )
                raise

            self.instance_id = instance.id

            self.info_log('Waiting for the instance to start...')

            for i in range(60*5):
                try:
                    status = instance.update()
                    if status == 'running':
                        break

                    else:
                        sleep(1)
                except Exception as e:
                    self.error_log(
                        'Exception while wait pending: %s' % str(e)
                    )
                    sleep(1)

            # Wait until instance is running
            status = instance.update()
            if status == 'running':
                instance.add_tag(
                    "Name",
                    "%s-selenium-node-%s-%s" %
                    (
                        self.browser_config.get('platform'),
                        self.browser_config.get('browserName'),
                        self.index
                    )
                )

                self.info_log(
                    "New instance (%s) public ip (%s) private ip (%s)" % (
                        instance.id,
                        instance.ip_address,
                        instance.private_ip_address
                    )
                )
            else:
                msg = "Instance status is %s and should be (running)" % status
                self.error_log(msg)
                raise Exception(msg)

            if BROME_CONFIG['ec2']['wait_until_system_and_instance_check_performed']:  # noqa
                check_successful = False

                for i in range(5*60):

                    try:

                        if not i % 60:
                            if not type(status) == str:
                                self.info_log(
                                    'System_status: %s, instance_status: %s' %
                                    (
                                        status.system_status,
                                        status.instance_status
                                    )
                                )

                        status = ec2.get_all_instance_status(
                            instance_ids=[instance.id]
                        )[0]
                        if status.system_status.status == u'ok' and status.instance_status.status == u'ok':  # noqa

                            self.info_log('system_status: %s, instance_status: %s' % (status.system_status, status.instance_status))  # noqa
                            check_successful = True
                            break

                    except Exception as e:
                        self.error_log('Waiting instance ready exception: %s' % str(e))  # noqa
                    sleep(1)

                if not check_successful:
                    msg = "System and instance check were not successful"
                    self.warning_log(msg)
                    raise Exception(msg)
            else:
                self.warning_log("Skipping wait until system and instance check performed")  # noqa

            self.info_log('Starting the selenium node server')

            self.private_ip = instance.private_ip_address
            self.public_dns = instance.public_dns_name
            self.private_dns = instance.private_dns_name
            self.public_ip = instance.ip_address

            # LINUX
            if self.browser_config.get('platform').lower() == "linux":
                command = self.browser_config.get(
                    "selenium_command"
                ).format(**self.browser_config.config)
                self.execute_command(command)

            elif self.browser_config.get('platform').upper() == "windows":

                # TODO this code is out of date
                config = self.browser_config.config.copy()
                config['instance_ip_address'] = instance.ip_address
                command = self.browser_config(
                    "selenium_command"
                ).format(**config)
                process = Popen(
                    command.split(" "),
                    stdout=devnull,
                    stderr=devnull
                )
                self.runner.xvfb_pids.append(process.pid)

            else:

                msg = "The provided platform name is not supported: select either (WINDOWS) or (LINUX)"  # noqa
                self.critical_log(msg)
                raise Exception(msg)

            return True

        except Exception as e:
            self.error_log('Startup exception: %s' % str(e))
            raise