Returns dictionary of named VPCs {name: vpc}

  Assert fails if there's more than one VPC with same name.
326538
def get_vpc_dict():
  """"""

  client = get_ec2_client()
  response = client.describe_vpcs()
  assert is_good_response(response)

  result = OrderedDict()
  ec2 = get_ec2_resource()
  for vpc_response in response['Vpcs']:
    key = get_name(vpc_response.get('Tags', []))
    if not key or key == EMPTY_NAME:  # skip VPC's that don't have a name assigned
      continue

    if key in result:
      util.log(f"Warning: Duplicate VPC group {key} in {response}")
      if DUPLICATE_CHECKING:
        assert False
    result[key] = ec2.Vpc(vpc_response['VpcId'])

  return result
1276665
def pk_names(cls):
        
        if cls._cache_pk_names is None:
            cls._cache_pk_names = cls._get_primary_key_names()
        return cls._cache_pk_names
34798
def prior_model_name_constant_tuples_dict(self):
        
        return {name: list(prior_model.constant_tuples) for name, prior_model in self.prior_model_tuples}
1104445
def _get_dvs(service_instance, dvs_name):
    '''
    
    '''
    switches = list_dvs(service_instance)
    if dvs_name in switches:
        inventory = get_inventory(service_instance)
        container = inventory.viewManager.CreateContainerView(inventory.rootFolder, [vim.DistributedVirtualSwitch], True)
        for item in container.view:
            if item.name == dvs_name:
                return item

    return None
1150595
def _get_id(vpc_name=None, cidr=None, tags=None, region=None, key=None,
            keyid=None, profile=None):
    '''
    
    '''

    if vpc_name and not any((cidr, tags)):
        vpc_id = _cache_id(vpc_name, region=region,
                           key=key, keyid=keyid,
                           profile=profile)
        if vpc_id:
            return vpc_id

    vpc_ids = _find_vpcs(vpc_name=vpc_name, cidr=cidr, tags=tags, region=region,
                         key=key, keyid=keyid, profile=profile)
    if vpc_ids:
        log.debug("Matching VPC: %s", " ".join(vpc_ids))
        if len(vpc_ids) == 1:
            vpc_id = vpc_ids[0]
            if vpc_name:
                _cache_id(vpc_name, vpc_id,
                          region=region, key=key,
                          keyid=keyid, profile=profile)
            return vpc_id
        else:
            raise CommandExecutionError('Found more than one VPC matching the criteria.')
    else:
        log.info('No VPC found.')
        return None
791480
def _get_ids_from_hostname(self, hostname):
        """"""
        results = self.list_instances(hostname=hostname, mask="id")
        return [result['id'] for result in results]
150704
def get_vpc_security_group_ids(vpc_id, group_names)
      group_map = {}
      @log.info "resolving security groups #{group_names} in #{vpc_id}"
      vpc = AWS::EC2::VPC.new(vpc_id, :ec2_endpoint => "ec2.#{@region}.amazonaws.com")
      vpc.security_groups.each do |sg|
        next if sg.vpc_id != vpc_id
        group_map[sg.name] = sg.group_id
      end
      group_ids = []
      group_names.each do |sg_name|
        raise "Couldn't find security group #{sg_name} in #{vpc_id}" unless group_map.has_key?(sg_name)
        group_ids << group_map[sg_name]
      end
      group_ids
    end
661454
def _check_vpcs_version(self):
        
        try:
            output = yield from subprocess_check_output(self._vpcs_path(), "-v", cwd=self.working_dir)
            match = re.search("Welcome to Virtual PC Simulator, version ([0-9a-z\.]+)", output)
            if match:
                version = match.group(1)
                self._vpcs_version = parse_version(version)
                if self._vpcs_version < parse_version("0.6.1"):
                    raise VPCSError("VPCS executable version must be >= 0.6.1 but not a 0.8")
            else:
                raise VPCSError("Could not determine the VPCS version for {}".format(self._vpcs_path()))
        except (OSError, subprocess.SubprocessError) as e:
            raise VPCSError("Error while looking for the VPCS version: {}".format(e))
1313935
def _verify_dict(self, conf):
        
        if not conf:
            raise SATOSAConfigurationError("Missing configuration or unknown format")

        for key in SATOSAConfig.mandatory_dict_keys:
            if key not in conf:
                raise SATOSAConfigurationError("Missing key '%s' in config" % key)

        for key in SATOSAConfig.sensitive_dict_keys:
            if key not in conf and "SATOSA_{key}".format(key=key) not in os.environ:
                raise SATOSAConfigurationError("Missing key '%s' from config and ENVIRONMENT" % key)
742520
def _get_name_map(saltenv='base'):
    '''
    
    '''
    u_name_map = {}
    name_map = get_repo_data(saltenv).get('name_map', {})

    if not six.PY2:
        return name_map

    for k in name_map:
        u_name_map[k] = name_map[k]
    return u_name_map
1246364
def GetCpuStolenMs(self):
        ''''''
        counter = c_uint64()
        ret = vmGuestLib.VMGuestLib_GetCpuStolenMs(self.handle.value, byref(counter))
        if ret != VMGUESTLIB_ERROR_SUCCESS: raise VMGuestLibException(ret)
        return counter.value
90419
def findInRemotesByName(self, name: str):
        
        remotes = [r for r in self.remotes.values()
                   if r.name == name]
        if len(remotes) > 1:
            raise DuplicateRemotes(remotes)
        if not remotes:
            raise RemoteNotFound(name)
        return remotes[0]
1155121
def GetCpuShares(self):
        ''''''
        counter = c_uint()
        ret = vmGuestLib.VMGuestLib_GetCpuShares(self.handle.value, byref(counter))
        if ret != VMGUESTLIB_ERROR_SUCCESS: raise VMGuestLibException(ret)
        return counter.value
654628
def vpc_name
      @vpc_name ||= connect.describe_vpcs.vpcs.each_with_object({}) do |v, m|
        next unless (tag = v.tags.find { |t| t.key == 'Name' })

        m[v.vpc_id] = tag.value
      end
    end
538601
def find_or_create(name)
      resp = ec2.describe_security_groups(
        filters: [
          {name: 'vpc-id', values: [fallback_vpc_id]},
          {name: 'group-name', values: [name]}]
        )
      sg = resp.security_groups.first
      return sg if sg

      puts "Creating security group #{name}".colorize(:green)
      result = ec2.create_security_group(
        group_name: name,
        description: name,
        vpc_id: fallback_vpc_id,
      )
      # TODO: add waiter
      # ec2.create_tags(
      #   resources: [result.group_id],
      #   tags: [{ key: "Name", value: name }],
      # )
      resp = ec2.describe_security_groups(group_ids: [result.group_id])
      resp.security_groups.first
    end
1095371
def get_sdc_by_name(self, name):
        
        for sdc in self.sdc:
            if sdc.name == name:
                return sdc
        raise KeyError("SDC of that name not found")
1188465
def _get_free_vpcids_on_switches(switch_ip_list):
    ''''''

    session = bc.get_reader_session()

    prev_view = aliased(nexus_models_v2.NexusVPCAlloc)
    query = session.query(prev_view.vpc_id)
    prev_swip = switch_ip_list[0]

    for ip in switch_ip_list[1:]:
        cur_view = aliased(nexus_models_v2.NexusVPCAlloc)
        cur_swip = ip
        query = query.join(cur_view, sa.and_(
            prev_view.switch_ip == prev_swip, prev_view.active == False,  # noqa
            cur_view.switch_ip == cur_swip, cur_view.active == False,     # noqa
            prev_view.vpc_id == cur_view.vpc_id))
        prev_view = cur_view
        prev_swip = cur_swip

    unique_vpcids = query.all()
    shuffle(unique_vpcids)
    return unique_vpcids