def _run_main_command(self, parsed_args, parsed_globals): ec2_result = None emr_result = None self.iam_endpoint_url = parsed_args.iam_endpoint self._check_for_iam_endpoint(self.region, self.iam_endpoint_url) self.emr_endpoint_url = \ self._session.create_client( 'emr', region_name=self.region, endpoint_url=parsed_globals.endpoint_url, verify=parsed_globals.verify_ssl).meta.endpoint_url LOG.debug('elasticmapreduce endpoint used for resolving' ' service principal: ' + self.emr_endpoint_url) # Check if the default EC2 Role for EMR exists. role_name = EC2_ROLE_NAME if self._check_if_role_exists(role_name, parsed_globals): LOG.debug('Role ' + role_name + ' exists.') else: LOG.debug('Role ' + role_name + ' does not exist.' ' Creating default role for EC2: ' + role_name) ec2_result = self._create_role_with_role_policy( role_name, role_name, EC2, emrutils.dict_to_string(EC2_ROLE_POLICY), parsed_globals) # Check if the default EC2 Instance Profile for EMR exists. instance_profile_name = EC2_ROLE_NAME if self._check_if_instance_profile_exists(instance_profile_name, parsed_globals): LOG.debug('Instance Profile ' + instance_profile_name + ' exists.') else: LOG.debug('Instance Profile ' + instance_profile_name + 'does not exist. Creating default Instance Profile ' + instance_profile_name) self._create_instance_profile_with_role(instance_profile_name, instance_profile_name, parsed_globals) # Check if the default EMR Role exists. role_name = EMR_ROLE_NAME if self._check_if_role_exists(role_name, parsed_globals): LOG.debug('Role ' + role_name + ' exists.') else: LOG.debug('Role ' + role_name + ' does not exist.' ' Creating default role for EMR: ' + role_name) emr_result = self._create_role_with_role_policy( role_name, role_name, EMR, emrutils.dict_to_string(EMR_ROLE_POLICY), parsed_globals) configutils.update_roles(self._session) emrutils.display_response( self._session, 'create_role', self._construct_result(ec2_result, emr_result), parsed_globals) return 0
def _run_main_command(self, parsed_args, parsed_globals): ec2_result = None ec2_policy = None emr_result = None emr_policy = None self.iam_endpoint_url = parsed_args.iam_endpoint self._check_for_iam_endpoint(self.region, self.iam_endpoint_url) self.emr_endpoint_url = self._session.create_client( "emr", region_name=self.region, endpoint_url=parsed_globals.endpoint_url, verify=parsed_globals.verify_ssl ).meta.endpoint_url LOG.debug("elasticmapreduce endpoint used for resolving" " service principal: " + self.emr_endpoint_url) # Check if the default EC2 Role for EMR exists. role_name = EC2_ROLE_NAME if self._check_if_role_exists(role_name, parsed_globals): LOG.debug("Role " + role_name + " exists.") else: LOG.debug("Role " + role_name + " does not exist." " Creating default role for EC2: " + role_name) role_arn = get_ec2_role_policy_arn(self.region) ec2_result = self._create_role_with_role_policy(role_name, EC2, role_arn, parsed_globals) ec2_policy = self._get_role_policy(role_arn, parsed_globals) # Check if the default EC2 Instance Profile for EMR exists. instance_profile_name = EC2_ROLE_NAME if self._check_if_instance_profile_exists(instance_profile_name, parsed_globals): LOG.debug("Instance Profile " + instance_profile_name + " exists.") else: LOG.debug( "Instance Profile " + instance_profile_name + "does not exist. Creating default Instance Profile " + instance_profile_name ) self._create_instance_profile_with_role(instance_profile_name, instance_profile_name, parsed_globals) # Check if the default EMR Role exists. role_name = EMR_ROLE_NAME if self._check_if_role_exists(role_name, parsed_globals): LOG.debug("Role " + role_name + " exists.") else: LOG.debug("Role " + role_name + " does not exist." " Creating default role for EMR: " + role_name) role_arn = get_service_role_policy_arn(self.region) emr_result = self._create_role_with_role_policy(role_name, EMR, role_arn, parsed_globals) emr_policy = self._get_role_policy(role_arn, parsed_globals) configutils.update_roles(self._session) emrutils.display_response( self._session, "create_role", self._construct_result(ec2_result, ec2_policy, emr_result, emr_policy), parsed_globals, ) return 0
def _run_main_command(self, parsed_args, parsed_globals): self.iam_endpoint_url = parsed_args.iam_endpoint self._check_for_iam_endpoint(self.region, self.iam_endpoint_url) self.emr_endpoint_url = \ self._session.create_client( 'emr', region_name=self.region, endpoint_url=parsed_globals.endpoint_url, verify=parsed_globals.verify_ssl).meta.endpoint_url LOG.debug('elasticmapreduce endpoint used for resolving' ' service principal: ' + self.emr_endpoint_url) # Create default EC2 Role for EMR if it does not exist. ec2_result, ec2_policy = self._create_role_if_not_exists(parsed_globals, EC2_ROLE_NAME, EC2_ROLE_POLICY_NAME, [EC2]) # Create default EC2 Instance Profile for EMR if it does not exist. instance_profile_name = EC2_ROLE_NAME if self.check_if_instance_profile_exists(instance_profile_name, parsed_globals): LOG.debug('Instance Profile ' + instance_profile_name + ' exists.') else: LOG.debug('Instance Profile ' + instance_profile_name + 'does not exist. Creating default Instance Profile ' + instance_profile_name) self._create_instance_profile_with_role(instance_profile_name, instance_profile_name, parsed_globals) # Create default EMR Role if it does not exist. emr_result, emr_policy = self._create_role_if_not_exists(parsed_globals, EMR_ROLE_NAME, EMR_ROLE_POLICY_NAME, [EMR]) # Create default EMR AutoScaling Role if it does not exist. emr_autoscaling_result, emr_autoscaling_policy = \ self._create_role_if_not_exists(parsed_globals, EMR_AUTOSCALING_ROLE_NAME, EMR_AUTOSCALING_ROLE_POLICY_NAME, [EMR, APPLICATION_AUTOSCALING]) configutils.update_roles(self._session) emrutils.display_response( self._session, 'create_role', self._construct_result(ec2_result, ec2_policy, emr_result, emr_policy, emr_autoscaling_result, emr_autoscaling_policy), parsed_globals) return 0