A default model with 500 nodes hosting 3000 VMs.
6 VMs per node
Each node has a 10GB network interface and 32 GB RAM
Each VM consumes 1GB Bandwidth and between 1 to 5 GB RAM
551281
private Model makeModel() {
        Model mo = new DefaultModel();
        Mapping mapping = mo.getMapping();

        int nbNodes = 300;
        int nbVMs = 6 * nbNodes;

        //Memory usage/consumption in GB
        ShareableResource rcMem = new ShareableResource("mem");

        //A resource representing the bandwidth usage/consumption of the elements in GB
        ShareableResource rcBW = new ShareableResource("bandwidth");

        nodes = new ArrayList<>(nbNodes);

        for (int i = 0; i < nbNodes; i++) {
            Node n = mo.newNode();
            nodes.add(n);
            mapping.addOnlineNode(n);

            //Each node provides a 10GB bandwidth and 32 GB RAM to its VMs
            rcBW.setCapacity(n, 10);
            rcMem.setCapacity(n, 32);
        }

        for (int i = 0; i < nbVMs; i++) {
            VM vm = mo.newVM();
            //Basic balancing through a round-robin: 6 VMs per node
            mapping.addRunningVM(vm, nodes.get(i % nodes.size()));

            //Each VM uses currently a 1GB bandwidth and 1,2 or 3 GB RAM
            rcBW.setConsumption(vm, 1);
            rcMem.setConsumption(vm, i % 5 + 1);
        }

        mo.attach(rcBW);
        mo.attach(rcMem);
        return mo;
    }
1203898
private static Set<NetworkAddress> buildNodesWithPrimaryPartitions(final List<NodeInfo> nodeInfos,
        final List<Partition> partitions) {
        Set<NetworkAddress> nodes = new HashSet<NetworkAddress>(nodeInfos.size());
        for (Partition partition : partitions) {
            int index = partition.master();
            if (index >= 0) {
                nodes.add(nodeInfos.get(index).hostname());
            }
        }
        return nodes;
    }
424167
def output_vm(gandi, vm, datacenters, output_keys, justify=10):
    
    output_generic(gandi, vm, output_keys, justify)

    if 'datacenter' in output_keys:
        for dc in datacenters:
            if dc['id'] == vm['datacenter_id']:
                dc_name = dc.get('dc_code', dc.get('iso', ''))
                break

        output_line(gandi, 'datacenter', dc_name, justify)

    if 'ip' in output_keys:
        for iface in vm['ifaces']:
            gandi.separator_line()
            output_line(gandi, 'bandwidth', iface['bandwidth'], justify)

            for ip in iface['ips']:
                ip_addr = ip['ip']

                output_line(gandi, 'ip%s' % ip['version'], ip_addr, justify)
175986
int D( int repl ) {
    int hsz = H2O.CLOUD.size();
  
    // See if this is a specifically homed Key
    if( !user_allowed() && repl < _kb[1] ) { // Asking for a replica# from the homed list?
      assert _kb[0] != Key.DVEC;
      H2ONode h2o = H2ONode.intern(_kb,2+repl*(4+2/*serialized bytesize of H2OKey*/));
      // Reverse the home to the index
      int idx = h2o.index();
      if( idx >= 0 ) return idx;
      // Else homed to a node which is no longer in the cloud!
      // Fall back to the normal home mode
    }
  
    // Distribution of Fluid Vectors is a special case.
    // Fluid Vectors are grouped into vector groups, each of which must have
    // the same distribution of chunks so that MRTask2 run over group of
    // vectors will keep data-locality.  The fluid vecs from the same group
    // share the same key pattern + each has 4 bytes identifying particular
    // vector in the group.  Since we need the same chunks end up on the same
    // node in the group, we need to skip the 4 bytes containing vec# from the
    // hash.  Apart from that, we keep the previous mode of operation, so that
    // ByteVec would have first 64MB distributed around cloud randomly and then
    // go round-robin in 64MB chunks.
    if( _kb[0] == DVEC ) {
      // Homed Chunk?
      if( _kb[1] != -1 ) throw H2O.unimpl();
      // For round-robin on Chunks in the following pattern:
      // 1 Chunk-per-node, until all nodes have 1 chunk (max parallelism).
      // Then 2 chunks-per-node, once around, then 4, then 8, then 16.
      // Getting several chunks-in-a-row on a single Node means that stencil
      // calculations that step off the end of one chunk into the next won't
      // force a chunk local - replicating the data.  If all chunks round robin
      // exactly, then any stencil calc will double the cached volume of data
      // (every node will have it's own chunk, plus a cached next-chunk).
      // Above 16-chunks-in-a-row we hit diminishing returns.
      int cidx = UnsafeUtils.get4(_kb, 1 + 1 + 4); // Chunk index
      int x = cidx/hsz; // Multiples of cluster size
      // 0 -> 1st trip around the cluster;            nidx= (cidx- 0*hsz)>>0
      // 1,2 -> 2nd & 3rd trip; allocate in pairs:    nidx= (cidx- 1*hsz)>>1
      // 3,4,5,6 -> next 4 rounds; allocate in quads: nidx= (cidx- 3*hsz)>>2
      // 7-14 -> next 8 rounds in octets:             nidx= (cidx- 7*hsz)>>3
      // 15+ -> remaining rounds in groups of 16:     nidx= (cidx-15*hsz)>>4
      int z = x==0 ? 0 : (x<=2 ? 1 : (x<=6 ? 2 : (x<=14 ? 3 : 4)));
      int nidx = (cidx-((1<<z)-1)*hsz)>>z;
      return ((nidx+repl)&0x7FFFFFFF) % hsz;
    }
  
    // Easy Cheesy Stupid:
    return ((_hash+repl)&0x7FFFFFFF) % hsz;
  }
425197
def vms(nictag):
    '''
    
    '''
    ret = {}
    cmd = 'nictagadm vms {0}'.format(nictag)
    res = __salt__['cmd.run_all'](cmd)
    retcode = res['retcode']
    if retcode != 0:
        ret['Error'] = res['stderr'] if 'stderr' in res else 'Failed to get list of vms.'
    else:
        ret = res['stdout'].splitlines()
    return ret
1037155
def allocate(self):
        """"""
        network_name = None

        self._hypervisor = libvirt.open(
            self.configuration.get('hypervisor', 'qemu:///system'))

        self._storage_pool = self._retrieve_pool()

        if 'network' in self.configuration:
            self._network = network.create(self._hypervisor, self.identifier,
                                           self.configuration['network'])
            network_name = self._network.name()

        disk_path = self._retrieve_disk_path()

        if self._storage_pool is not None:
            self._storage_pool.refresh()

        self._domain = domain_create(self._hypervisor, self.identifier,
                                     self.configuration['domain'],
                                     disk_path, network_name=network_name)

        if self._network is None:
            self._network = network.lookup(self._domain)
993505
def get_vm_size(vm_):
    
    '''
    vm_size = config.get_cloud_config_value('size', vm_, __opts__)
    ram = avail_sizes()[vm_size]['RAM']

    if vm_size.startswith('Linode'):
        vm_size = vm_size.replace('Linode ', '')

    if ram == int(vm_size):
        return ram
    else:
        raise SaltCloudNotFound(
            'The specified size, {0}, could not be found.'.format(vm_size)
        )
70646
def vm_created(name, vm_name, cpu, memory, image, version, interfaces,
               disks, scsi_devices, serial_ports, datacenter, datastore,
               placement, ide_controllers=None, sata_controllers=None,
               cd_dvd_drives=None, advanced_configs=None, power_on=False):
    '''
    
    '''
    result = {'name': name,
              'result': None,
              'changes': {},
              'comment': ''}

    if __opts__['test']:
        result['comment'] = 'Virtual machine {0} will be created'.format(
                vm_name)
        return result

    service_instance = __salt__['vsphere.get_service_instance_via_proxy']()
    try:
        info = __salt__['vsphere.create_vm'](vm_name, cpu, memory, image,
                                             version, datacenter, datastore,
                                             placement, interfaces, disks,
                                             scsi_devices,
                                             serial_ports=serial_ports,
                                             ide_controllers=ide_controllers,
                                             sata_controllers=sata_controllers,
                                             cd_drives=cd_dvd_drives,
                                             advanced_configs=advanced_configs,
                                             service_instance=service_instance)
    except salt.exceptions.CommandExecutionError as exc:
        log.error('Error: %s', exc)
        if service_instance:
            __salt__['vsphere.disconnect'](service_instance)
        result.update({
            'result': False,
            'comment': six.text_type(exc)})
        return result

    if power_on:
        try:
            __salt__['vsphere.power_on_vm'](vm_name, datacenter,
                                            service_instance=service_instance)
        except salt.exceptions.VMwarePowerOnError as exc:
            log.error('Error: %s', exc)
            if service_instance:
                __salt__['vsphere.disconnect'](service_instance)
            result.update({
                'result': False,
                'comment': six.text_type(exc)})
            return result
        info['power_on'] = power_on

    changes = {'name': vm_name, 'info': info}
    __salt__['vsphere.disconnect'](service_instance)
    result = {'name': name,
              'result': True,
              'changes': changes,
              'comment': 'Virtual machine '
                         '{0} created successfully'.format(vm_name)}

    return result
22892
def create(cls, ip_version, datacenter, bandwidth, vlan, vm, ip,
               background):
        
        if not background and not cls.intty():
            background = True

        datacenter_id_ = int(Datacenter.usable_id(datacenter))

        iface_params = {
            'ip_version': ip_version,
            'datacenter_id': datacenter_id_,
            'bandwidth': bandwidth,
        }
        if vlan:
            iface_params['vlan'] = Vlan.usable_id(vlan)
            if ip:
                iface_params['ip'] = ip

        result = cls.call('hosting.iface.create', iface_params)

        if background and not vm:
            return result

        # interactive mode, run a progress bar
        cls.echo('Creating your iface.')
        cls.display_progress(result)
        iface_info = cls._info(result['iface_id'])
        cls.echo('Your iface has been created with the following IP '
                 'addresses:')
        for _ip in iface_info['ips']:
            cls.echo('ip%d:\t%s' % (_ip['version'], _ip['ip']))

        if not vm:
            return result

        vm_id = Iaas.usable_id(vm)
        result = cls._attach(result['iface_id'], vm_id)

        if background:
            return result

        cls.echo('Attaching your iface.')
        cls.display_progress(result)
        return result
794195
def avail_sizes(call=None):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The avail_sizes function must be called with '
            '-f or --function, or with the --list-sizes option'
        )

    ret = {
        'block devices': {},
        'memory': {},
        'processors': {},
    }
    conn = get_conn()
    response = conn.getCreateObjectOptions()
    for device in response['blockDevices']:
        #return device['template']['blockDevices']
        ret['block devices'][device['itemPrice']['item']['description']] = {
            'name': device['itemPrice']['item']['description'],
            'capacity':
                device['template']['blockDevices'][0]['diskImage']['capacity'],
        }
    for memory in response['memory']:
        ret['memory'][memory['itemPrice']['item']['description']] = {
            'name': memory['itemPrice']['item']['description'],
            'maxMemory': memory['template']['maxMemory'],
        }
    for processors in response['processors']:
        ret['processors'][processors['itemPrice']['item']['description']] = {
            'name': processors['itemPrice']['item']['description'],
            'start cpus': processors['template']['startCpus'],
        }
    return ret
1038370
def set_ram(self, ram):
        

        if self._ram == ram:
            return

        yield from self._hypervisor.send('vm set_ram "{name}" {ram}'.format(name=self._name, ram=ram))
        log.info('Router "{name}" [{id}]: RAM updated from {old_ram}MB to {new_ram}MB'.format(name=self._name,
                                                                                              id=self._id,
                                                                                              old_ram=self._ram,
                                                                                              new_ram=ram))
        self._ram = ram
1211109
def allocate(self):
        """"""
        disk_path = self.provider_image

        self._hypervisor = libvirt.open(
            self.configuration.get('hypervisor', 'vbox:///session'))

        self._domain = domain_create(self._hypervisor, self.identifier,
                                     self.configuration['domain'], disk_path)
568419
def list_nodes(call=None):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The list_nodes function must be called with -f or --function.'
        )

    ret = {}
    nodes = list_nodes_full()
    if 'error' in nodes:
        raise SaltCloudSystemExit(
            'An error occurred while listing nodes: {0}'.format(
                nodes['error']['Errors']['Error']['Message']
            )
        )
    for node in nodes:
        ret[node] = {
            'id': nodes[node]['hostname'],
            'ram': nodes[node]['maxMemory'],
            'cpus': nodes[node]['maxCpu'],
        }
        if 'primaryIpAddress' in nodes[node]:
            ret[node]['public_ips'] = nodes[node]['primaryIpAddress']
        if 'primaryBackendIpAddress' in nodes[node]:
            ret[node]['private_ips'] = nodes[node]['primaryBackendIpAddress']
        if 'status' in nodes[node]:
            ret[node]['state'] = six.text_type(nodes[node]['status']['name'])
    return ret
299140
def transformer_wikitext103_l16k_memory_v0():
  """"""
  hparams = transformer_wikitext103_l4k_memory_v0()

  hparams.max_length = 16384
  hparams.split_targets_chunk_length = 64
  hparams.split_targets_max_chunks = int(
      hparams.max_length / hparams.split_targets_chunk_length)

  # The hparams specify batch size *before* chunking, but we want to have a
  # consistent 4K batch size *after* chunking to fully utilize the hardware.
  target_tokens_per_batch = 4096
  hparams.batch_size = int(target_tokens_per_batch * (
      hparams.max_length / hparams.split_targets_chunk_length))

  hparams.max_relative_position = 2 * hparams.split_targets_chunk_length

  return hparams
428826
def allocate(vertices_resources, nets, machine, constraints, placements):
    
    allocation = {}

    # Globally reserved resource ranges {resource, [slice, ...], ...}
    globally_reserved = defaultdict(list)
    # Locally reserved resource ranges {(x, y): {resource, [slice, ...], ...}}
    locally_reserved = defaultdict(lambda: defaultdict(list))

    # Alignment of each resource
    alignments = defaultdict(lambda: 1)

    # Collect constraints
    for constraint in constraints:
        if isinstance(constraint, ReserveResourceConstraint):
            if constraint.location is None:
                globally_reserved[constraint.resource].append(
                    constraint.reservation)
            else:
                locally_reserved[constraint.location][
                    constraint.resource].append(constraint.reservation)
        elif isinstance(constraint, AlignResourceConstraint):
            alignments[constraint.resource] = constraint.alignment

    # A dictionary {(x, y): [vertex, ...], ...}
    chip_contents = defaultdict(list)
    for vertex, xy in iteritems(placements):
        chip_contents[xy].append(vertex)

    for xy, chip_vertices in iteritems(chip_contents):
        # Index of the next free resource in the current chip
        resource_pointers = {resource: 0
                             for resource in machine.chip_resources}

        for vertex in chip_vertices:
            vertex_allocation = {}

            # Make allocations, advancing resource pointers
            for resource, requirement in iteritems(vertices_resources[vertex]):
                proposed_allocation = None
                proposal_overlaps = True
                while proposal_overlaps:
                    # Check that the proposed allocation doesn't overlap a
                    # reserved area.
                    start = align(resource_pointers[resource],
                                  alignments[resource])
                    proposed_allocation = slice(start, start + requirement)
                    proposal_overlaps = False
                    if proposed_allocation.stop > machine[xy][resource]:
                        raise InsufficientResourceError(
                            "{} over-allocated on chip {}".format(resource,
                                                                  xy))
                    for reservation in globally_reserved[resource]:
                        if slices_overlap(proposed_allocation, reservation):
                            resource_pointers[resource] = reservation.stop
                            proposal_overlaps = True
                    local_reservations \
                        = locally_reserved.get(xy, {}).get(resource, [])
                    for reservation in local_reservations:
                        if slices_overlap(proposed_allocation, reservation):
                            resource_pointers[resource] = reservation.stop
                            proposal_overlaps = True

                # Getting here means the proposed allocation is not blocked
                # by any reservations
                vertex_allocation[resource] = proposed_allocation
                resource_pointers[resource] = proposed_allocation.stop

            allocation[vertex] = vertex_allocation

    return allocation
484184
def report_usage_to_host(host_ip, vmid):
	
	#base value
	cpu_usage = 0.0
	os_mem_usage = 0.0
	task_mem_usage = 0.0
	io_usage = 0.0

	cpu_usage = get_cpu_usage()
	os_mem_usage = get_os_mem_usage()
	task_mem_usage = get_task_mem_usage()
	io_usage = get_io_usage()

	usage = str(vmid.strip())+' | '+str(cpu_usage)+' | '+str(os_mem_usage)+' | '+str(task_mem_usage)+' | '+str(io_usage)
	#usage = "'cpu |sdbfsj |sdfsdhf |sdfvsdvfgdfvj'"
	#cmd = 'python /var/lib/virtdc/vmonere/host/vmonere_listener.py '+usage
	

	''''''

	#report usage via socket
	start_client_socket(host_ip, usage)
1142578
def list_nodes_full(conn=None, call=None):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The list_nodes_full function must be called with -f or '
            '--function.'
        )

    if not conn:
        conn = get_conn()

    ret = {}
    nodes = conn.list_servers()

    for node in nodes:
        ret[node['name']] = node

    return ret