rysnc a file to the vm with the given role
774437
def injectFile(self, fromFile, toFile, role):
        
        maxRetries = 10
        for retry in range(maxRetries):
            try:
                self.coreRsync([fromFile, ":" + toFile], applianceName=role)
                return True
            except Exception as e:
                logger.debug("Rsync to new node failed, trying again. Error message: %s" % e)
                time.sleep(10*retry)
        raise RuntimeError("Failed to inject file %s to %s with ip %s" % (fromFile, role, self.effectiveIP) )
484918
def export(vault_client, opt):
    """"""
    ctx = Context.load(get_secretfile(opt), opt) \
                 .fetch(vault_client)
    for resource in ctx.resources():
        resource.export(opt.directory)
292092
def _create_snapshot(logger, snapshot_name, vm, save_vm_memory_to_snapshot):
        
        logger.info("Create virtual machine snapshot")
        dump_memory = save_vm_memory_to_snapshot
        quiesce = True
        task = vm.CreateSnapshot(snapshot_name, 'Created by CloudShell vCenterShell', dump_memory, quiesce)
        return task
505548
def run_role(self, name,
                 options=None,
                 content=None):
        
        if options is None:
            options = {}
        if content is None:
            content = []
        role_fn, _ = role(name,
                          self.language,
                          self.node.line,
                          self.reporter)
        vec, _ = role_fn(name,
                         rawtext=str(content),
                         text=str(content),
                         lineno=self.node.line,
                         inliner=self.memo.inliner,
                         options=options,
                         content=content)
        assert len(vec) == 1, 'only support one list in role'
        return vec[0]
1297183
def _generate_entry(self, vm):
        
        return \
            '{name} ' \
            'ansible_host={ip} ' \
            'ansible_ssh_private_key_file={key}'.format(
                name=vm.name(),
                ip=vm.ip(),
                key=self.prefix.paths.ssh_id_rsa()
            )
195175
function buildRole(options, roleName='LambdaCfnRole') {
  let role = {
    Resources: {}
  };

  role.Resources[roleName] = {
    Type: 'AWS::IAM::Role',
    Properties: {
      AssumeRolePolicyDocument: {
        Statement: [
          {
            Sid: '',
            Effect: 'Allow',
            Principal: {
              Service: 'lambda.amazonaws.com'
            },
            Action: 'sts:AssumeRole'
          },
          {
            Sid: '',
            Effect: 'Allow',
            Principal: {
              Service: 'events.amazonaws.com'
            },
            Action: 'sts:AssumeRole'
          }
        ]
      },
      Path: '/',
      Policies: [
        {
          PolicyName: 'basic',
          PolicyDocument: {
            Statement: [
              {
                Effect: 'Allow',
                Action: [
                  'logs:*'
                ],
                Resource: cf.join(['arn:aws:logs:*:', cf.accountId, ':*'])
              },
              {
                Effect: 'Allow',
                Action: [
                  'sns:Publish'
                ],
                Resource: cf.ref('ServiceAlarmSNSTopic')
              },
              {
                Effect: 'Allow',
                Action: [
                  'iam:SimulateCustomPolicy'
                ],
                Resource: '*'
              }
            ]
          }
        },
      ]
    }
  };

  if (options.eventSources && options.eventSources.webhook) {
    role.Resources[roleName].Properties.AssumeRolePolicyDocument.Statement.push({
      Sid: '',
      Effect: 'Allow',
      Principal: {
        Service: 'apigateway.amazonaws.com'
      },
      Action: 'sts:AssumeRole'
    });
  }

  if (options.statements) {
    statementValidation(options);

    role.Resources[roleName].Properties.Policies.push({
      PolicyName: options.name,
      PolicyDocument: {
        Statement: options.statements
      }
    });
  }

  return role;
}
37753
def AmiName(ami_release_name, ubuntu_release_name, virtualization_type,
            mapr_version, role):
  
  if not role in valid_instance_roles:
    raise RuntimeError('Specified role (%s) not a valid role: %s' %
                         (role, valid_instance_roles))
  if virtualization_type not in valid_virtualization_types:
    raise RuntimeError('Specified virtualization type (%s) not valid: %s' %
                         (virtualization_type, valid_virtualization_types))
  ami_name = 'cirrus-%s-ubuntu-%s-%s-mapr%s-%s' % (ami_release_name,
                                                   ubuntu_release_name,
                                                   virtualization_type,
                                                   mapr_version, role)
  return ami_name
332884
def attach(gandi, disk, vm, position, read_only, background, force):
    
    if not force:
        proceed = click.confirm("Are you sure you want to attach disk '%s'"
                                " to vm '%s'?" % (disk, vm))
        if not proceed:
            return

    disk_info = gandi.disk.info(disk)
    attached = disk_info.get('vms_id', False)
    if attached and not force:
        gandi.echo('This disk is still attached')
        proceed = click.confirm('Are you sure you want to detach %s?' % disk)

        if not proceed:
            return

    result = gandi.disk.attach(disk, vm, background, position, read_only)
    if background and result:
        gandi.pretty_echo(result)

    return result
79695
def from_file(self, vasprun_file):
        """"""
        vrun_obj = Vasprun(vasprun_file, parse_projected_eigen=True)
        return VasprunLoader(vrun_obj)
6736
def get_caller_identity_arn(self):
        
        assumed_role = self.boto_session.client('sts').get_caller_identity()['Arn']

        if 'AmazonSageMaker-ExecutionRole' in assumed_role:
            role = re.sub(r'^(.+)sts::(\d+):assumed-role/(.+?)/.*$', r'\1iam::\2:role/service-role/\3', assumed_role)
            return role

        role = re.sub(r'^(.+)sts::(\d+):assumed-role/(.+?)/.*$', r'\1iam::\2:role/\3', assumed_role)

        # Call IAM to get the role's path
        role_name = role[role.rfind('/') + 1:]
        try:
            role = self.boto_session.client('iam').get_role(RoleName=role_name)['Role']['Arn']
        except ClientError:
            LOGGER.warning("Couldn't call 'get_role' to get Role ARN from role name {} to get Role path."
                           .format(role_name))

        return role
1291114
def _get_role_arn():
    
    role_arn = bottle.request.headers.get('X-Role-ARN')
    if not role_arn:
        role_arn = _lookup_ip_role_arn(bottle.request.environ.get('REMOTE_ADDR'))
    if not role_arn:
        role_arn = _role_arn
    return role_arn
422422
def _get_role(rolename):
    """"""
    path = os.path.join('roles', rolename + '.json')
    if not os.path.exists(path):
        abort("Couldn't read role file {0}".format(path))
    with open(path, 'r') as f:
        try:
            role = json.loads(f.read())
        except ValueError as e:
            msg = "Little Chef found the following error in your"
            msg += " {0}.json file:\n  {1}".format(rolename, str(e))
            abort(msg)
        role['fullname'] = rolename
        return role
219786
def get_ec2_role(self, role, mount_point='aws-ec2'):
        
        return self._adapter.get('/v1/auth/{0}/role/{1}'.format(mount_point, role)).json()
370802
def create_vm(self, userid, cpu, memory, disk_list,
                  user_profile, max_cpu, max_mem, ipl_from,
                  ipl_param, ipl_loadparam):
        """"""
        LOG.info("Creating the user directory for vm %s", userid)

        info = self._smtclient.create_vm(userid, cpu, memory,
                                   disk_list, user_profile,
                                   max_cpu, max_mem, ipl_from,
                                   ipl_param, ipl_loadparam)

        # add userid into smapi namelist
        self._smtclient.namelist_add(self._namelist, userid)
        return info
920810
def _attach(cls, disk_id, vm_id, options=None):
        
        options = options or {}
        oper = cls.call('hosting.vm.disk_attach', vm_id, disk_id, options)
        return oper
235198
def create_storage_policy(profile_manager, policy_spec):
    '''
    
    '''
    try:
        profile_manager.Create(policy_spec)
    except vim.fault.NoPermission as exc:
        log.exception(exc)
        raise VMwareApiError('Not enough permissions. Required privilege: '
                             '{0}'.format(exc.privilegeId))
    except vim.fault.VimFault as exc:
        log.exception(exc)
        raise VMwareApiError(exc.msg)
    except vmodl.RuntimeFault as exc:
        log.exception(exc)
        raise VMwareRuntimeError(exc.msg)
793607
def get_rg_from_id(vmss_id):
    ''''''
    rgname = re.search('Groups/(.+?)/providers', vmss_id).group(1)
    print('Resource group: ' + rgname)
    return rgname