コード例 #1
0
ファイル: models.py プロジェクト: T3kton/contractor_plugins
def _containerSpec( foundation ):
  result = {}

  structure_config = getConfig( foundation.structure )
  structure_config = mergeValues( structure_config )

  result[ 'image' ] = structure_config[ 'docker_image' ]
  result[ 'port_list' ] = structure_config.get( 'port_list', [] )
  result[ 'environment_map' ] = structure_config.get( 'environment_map', {} )
  result[ 'command' ] = structure_config.get( 'docker_command', None )

  return result
コード例 #2
0
def _vmSpec(foundation):
    result = {}

    structure_config = getConfig(foundation.structure)
    structure_config = mergeValues(structure_config)

    result['vmid'] = foundation.proxmox_vmid
    result['core_count'] = structure_config.get('cpu_count', 1)
    result['memory_size'] = structure_config.get('memory_size', 1024)  # in MiB
    # result[ 'swap_size' ] = structure_config.get( 'swap_size', 1024 ) # for lxc
    result['disk_size'] = structure_config.get('disk_size', 10)  # in GiB
    result['type'] = 'qemu'  # only support quemu right now

    return result
コード例 #3
0
ファイル: models.py プロジェクト: pnhowe/contractor_plugins
def _vmSpec(foundation):
    result = {}

    structure_config = getConfig(foundation.structure)
    structure_config = mergeValues(structure_config)

    result['azure_size'] = structure_config.get('azure_size', 'Standard_D1_v2')

    for key in ('azure_admin_username', 'azure_admin_password', 'azure_image'):
        try:
            result[key] = structure_config[key]
        except KeyError:
            pass

    return result
コード例 #4
0
ファイル: lib.py プロジェクト: troyf/contractor
def updateRecord(target):
    db = collection(target)

    if target.__class__.__name__ in ('StructureBluePrint',
                                     'FoundationBluePrint'):
        item = getConfig(target)
    else:
        item = mergeValues(getConfig(target))

    for i in ('__contractor_host', '__pxe_template_location',
              '__pxe_location'):  # these are the same everywhere
        del item[i]

    key = {'_id': target.pk}

    prepConfig(item)
    db.update(key, item, upsert=True)
コード例 #5
0
def _vmSpec(foundation):
    result = {}

    structure_config = getConfig(foundation.structure)
    structure_config = mergeValues(structure_config)

    result['cpu_count'] = structure_config.get('cpu_count', 1)
    result['memory_size'] = structure_config.get('memory_size', 1024)
    result['disk_size'] = structure_config.get('disk_size', 10)

    if 'ova' in structure_config:
        result['ova'] = structure_config['ova']

        for key in ('vcenter_property_map', 'vcenter_deployment_option',
                    'vcenter_ip_protocol'):
            try:
                result[key] = structure_config[key]
            except KeyError:
                pass

    if 'template' in structure_config:
        result['template'] = structure_config['template']

        for key in ('vcenter_hostname', 'vcenter_domain',
                    'vcenter_dnsserver_list', 'vcenter_dnssuffix_list',
                    'vcenter_property_map'):
            try:
                result[key] = structure_config[key]
            except KeyError:
                pass

    else:
        result['vcenter_guest_id'] = structure_config.get(
            'vcenter_guest_id', 'otherGuest')

        for key in ('vcenter_virtual_exec_usage', 'vcenter_virtual_mmu_usage',
                    'vcenter_virtual_vhv', 'vcenter_network_interface_class',
                    'vcenter_property_map'):
            try:
                result[key] = structure_config[key]
            except KeyError:
                pass

    return result
コード例 #6
0
def _vmSpec( foundation ):
  result = {}

  structure_config = getConfig( foundation.structure )
  structure_config = mergeValues( structure_config )

  result[ 'cpu_count' ] = structure_config.get( 'cpu_count', 1 )
  result[ 'memory_size' ] = structure_config.get( 'memory_size', 1024 )  # in MiB
  result[ 'disk_size' ] = structure_config.get( 'disk_size', 10 )  # in GiB

  result[ 'virtualbox_guest_type' ] = structure_config.get( 'virtualbox_guest_type', 'Other' )

  for key in ( 'virtualbox_network_adapter_type', ):
    try:
      result[ key ] = structure_config[ key ]
    except KeyError:
      pass

  return result
コード例 #7
0
def handler(request):
    match = url_regex.match(request.uri.lower())
    if not match:
        return Response(400, data='Invalid config uri', content_type='text')

    (request_type, _, config_uuid, structure_id, foundation_locator,
     ip_address, _, _, _) = match.groups()

    target = None

    if config_uuid is not None:
        try:
            target = Structure.objects.get(config_uuid=config_uuid[2:])
        except Structure.DoesNotExist:
            return Response(404,
                            data='Config UUID Not Found',
                            content_type='text')

    elif structure_id is not None:
        try:
            target = Structure.objects.get(pk=int(structure_id[2:]))
        except Structure.DoesNotExist:
            return Response(404,
                            data='Structure Not Found',
                            content_type='text')

    elif foundation_locator is not None:
        try:
            target = Foundation.objects.get(pk=foundation_locator[2:]).subclass
        except Foundation.DoesNotExist:
            return Response(404,
                            data='Foundation Not Found',
                            content_type='text')

    else:
        if ip_address is not None:
            address = BaseAddress.lookup(ip_address[2:])
        else:
            address = BaseAddress.lookup(request.remote_addr)

        if address is None:
            return Response(404, data='Address Not Found', content_type='text')

        address = address.subclass
        if address.type == 'Address':
            target = address.networked.subclass
        else:
            target = address

    if target is None:
        return Response(500, data='Target is missing', content_type='text')

    data = None
    config = getConfig(target)

    if request_type in ('boot_script', 'pxe_template'):
        pxe = None
        if isinstance(target, Structure):
            pxe = target.provisioning_interface.pxe
        elif isinstance(target, Foundation):
            pxe = target.structure.provisioning_interface.pxe
        elif isinstance(target, DynamicAddress):
            pxe = target.pxe

        if pxe is None:
            return Response(200, data='', content_type='text')

        if request_type == 'boot_script':
            template = '#!ipxe\n\n' + pxe.boot_script

        elif request_type == 'pxe_template':
            template = pxe.template

        data = renderTemplate(template, config)
        return Response(200, data=data, content_type='text')

    elif request_type == 'config':
        _fromPythonMap(
            config
        )  # this does not go out CInP's converter, we need to make the python dict JSON encodable our selves
        return Response(200, data=mergeValues(config))

    return Response(400, data='Invalid request type', content_type='text')
コード例 #8
0
 def getConfig( self ):
   return mergeValues( getConfig( self.subclass ) )
コード例 #9
0
  def updateConfig( self, config_value_map ):  # TODO: this is a bad Idea, need to figure out a better way to do this, at least restrict it to accounts that can create/updatre structures
    self.config_values.update( config_value_map )
    self.full_clean()
    self.save()

    return mergeValues( getConfig( self ) )
コード例 #10
0
 def getConfig( self ):
   return mergeValues( getConfig( self ) )
コード例 #11
0
 def getConfig( self ):
   """
   returns the computed config for this foundation
   """
   return mergeValues( getConfig( self.subclass ) )
コード例 #12
0
ファイル: config_test.py プロジェクト: troyf/contractor
def test_mergeValues():
  values = { 'a': 'c' }
  assert { 'a': 'c' } == mergeValues( values )
  assert { 'a': 'c' } == values

  values = { 'a': 3 }
  assert { 'a': 3 } == mergeValues( values )
  assert { 'a': 3 } == values

  values = { 'a': 3, 'b': { 'c': 3 } }
  assert { 'a': 3, 'b': { 'c': 3 } } == mergeValues( values )
  assert { 'a': 3, 'b': { 'c': 3 } } == values

  values = { 'a': 3, 'b': [ 1, '3', 2 ] }
  assert { 'a': 3, 'b': [ 1, '3', 2 ] } == mergeValues( values )
  assert { 'a': 3, 'b': [ 1, '3', 2 ] } == values

  values = { 'a': 'c', 'd': '{{a}}' }
  assert { 'a': 'c', 'd': 'c' } == mergeValues( values )
  assert { 'a': 'c', 'd': '{{a}}' } == values

  values = { 'a': 1, 'd': '{{a}}', 'e': '"{{a}}"' }
  assert { 'a': 1, 'd': '1', 'e': '"1"' } == mergeValues( values )
  assert { 'a': 1, 'd': '{{a}}', 'e': '"{{a}}"' } == values

  values = { 'a': 'c', 'd': '{{ a }}' }
  assert { 'a': 'c', 'd': 'c' } == mergeValues( values )
  assert { 'a': 'c', 'd': '{{ a }}' } == values

  values = { 'a': 'c', 'd': '{{z|default(\'v\')}}' }
  assert { 'a': 'c', 'd': 'v' } == mergeValues( values )
  assert { 'a': 'c', 'd': '{{z|default(\'v\')}}' } == values

  values = { 'a': 'c', 'd': '{{a|default(\'v\')}}' }
  assert { 'a': 'c', 'd': 'c' } == mergeValues( values )
  assert { 'a': 'c', 'd': '{{a|default(\'v\')}}' } == values

  values = { 'a': 'c', 'd': { 'bob': 'sdf', 'sally': '{{a}}' } }
  assert { 'a': 'c', 'd': { 'bob': 'sdf', 'sally': 'c' } } == mergeValues( values )
  assert { 'a': 'c', 'd': { 'bob': 'sdf', 'sally': '{{a}}' } } == values

  values = { 'a': 'c', 'b': 'f', 'd': [ '{{a}}', '{{b}}', '{{a}}' ] }
  assert { 'a': 'c', 'b': 'f', 'd': [ 'c', 'f', 'c' ] } == mergeValues( values )
  assert { 'a': 'c', 'b': 'f', 'd': [ '{{a}}', '{{b}}', '{{a}}' ] } == values

  values = { 'zone': 'local', 'dns_search': [ 'bob.{{zone}}', '{{zone}}' ], 'fqdn': 'mybox.{{zone}}' }
  assert { 'zone': 'local', 'dns_search': [ 'bob.local', 'local' ], 'fqdn': 'mybox.local' } == mergeValues( values )
  assert { 'zone': 'local', 'dns_search': [ 'bob.{{zone}}', '{{zone}}' ], 'fqdn': 'mybox.{{zone}}' } == values

  # make sure we are not crossing item boundires
  values = { 'a': '{', 'b': '{a', 'c': '{', 'd': '{', 'e': '}}' }
  assert { 'a': '{', 'b': '{a', 'c': '{', 'd': '{', 'e': '}}' } == mergeValues( values )
  assert { 'a': '{', 'b': '{a', 'c': '{', 'd': '{', 'e': '}}' } == values

  values = { 'a': 'c', 'b': 'a', 'd': '{{ "{{" }}{{b}}}}' }
  assert { 'a': 'c', 'b': 'a', 'd': 'c' } == mergeValues( values )
  assert { 'a': 'c', 'b': 'a', 'd': '{{ "{{" }}{{b}}}}' } == values