Esempio n. 1
0
File: models.py Progetto: pnhowe/MCP
    def getHostDetail(self):
        """
    Get the Host detail, including info from Contractor, this is a bit expensive, use conservitivally.
    """
        result = {
            'structure_id': self.resource_instance.contractor_structure_id,
            'hostname': self.hostname
        }

        contractor = getContractor()
        try:
            config = contractor.getFullConfig(
                self.resource_instance.contractor_structure_id)
        except NotFound:
            config = None

        if config is not None:
            result['fqdn'] = config['_fqdn']
            result['site'] = config['_site']
            result['ip_address'] = config['_primary_address']['address']
            result['config_uuid'] = config['_structure_config_uuid']
            result['blueprint'] = config['_blueprint']

        try:
            result[
                'foundation_id'] = self.resource_instance.contractor_foundation_id
        except AttributeError:
            pass

        return result
Esempio n. 2
0
File: models.py Progetto: pnhowe/MCP
  def build( self ):
    contractor = getContractor()
    if not self.buildjobresourceinstance.auto_provision:
      return

    contractor.builStaticResource( self.contractor_structure_id )
    contractor.registerWebHook( self.buildjobresourceinstance, True, structure_id=self.contractor_structure_id )
Esempio n. 3
0
File: models.py Progetto: pnhowe/MCP
 def build( self ):
   contractor = getContractor()
   if self.buildjobresourceinstance.auto_provision:
     contractor.buildDynamicResource( self.contractor_foundation_id, self.contractor_structure_id )
     contractor.registerWebHook( self.buildjobresourceinstance, True, structure_id=self.contractor_structure_id )
   else:
     contractor.buildDynamicResource( self.contractor_foundation_id )
     contractor.registerWebHook( self.buildjobresourceinstance, True, foundation_id=self.contractor_foundation_id )
Esempio n. 4
0
    def available(self, quantity):
        contractor = getContractor()

        network = contractor.getNetworkUsage(self.name)
        if int(network['total']) - (int(network['static']) + int(
                network['dynamic']) + int(network['reserved'])) < quantity:
            return False

        return True
Esempio n. 5
0
    def foundationBuild(self, cookie):  # called from webhook
        if self.cookie != self.cookie:
            return

        self.state = 'built1'
        self.full_clean()
        self.save()

        contractor = getContractor()
        contractor.createStructure(self.structure_id)
Esempio n. 6
0
    def foundationDestroyed(self, cookie):  # called from webhook
        if self.cookie != self.cookie:
            return

        contractor = getContractor()
        contractor.deleteFoundation(self.foundation_id)

        self.state = 'released'
        self.foundation_id = None
        self.full_clean()
        self.save()
Esempio n. 7
0
File: models.py Progetto: pnhowe/MCP
  def available( self, quantity ):  # TODO: rethink, mabey it should be a class method, and probably should return the resources, merge with allocate?
    if self.monolithic:
      return self.build_set.all().count() == 0

    contractor = getContractor()

    network = contractor.getNetworkUsage( self.contractor_addressblock_id )
    if int( network[ 'total' ] ) - ( int( network[ 'static' ] ) + int( network[ 'dynamic' ] ) + int( network[ 'reserved' ] ) ) < quantity:
      return False

    return True
Esempio n. 8
0
File: models.py Progetto: pnhowe/MCP
  def allocate( self, blueprint, config_values, hostname ):
    interface_map = self.interface_map
    for interface in interface_map.keys():
      if 'network_id' not in interface_map[ interface ]:
        interface_map[ interface ][ 'network_id' ] = interface_map[ interface ][ 'network' ].contractor_network_id
        interface_map[ interface ][ 'address_block_id' ] = interface_map[ interface ][ 'network' ].contractor_addressblock_id

    contractor = getContractor()
    self.contractor_foundation_id, self.contractor_structure_id = contractor.allocateDynamicResource( self.site.name, self.dynamic_resource.dynamicresourcesite_set.get( site=self.site ).complex_id, blueprint, config_values, interface_map, hostname )
    self.full_clean()
    self.save()
Esempio n. 9
0
    def build(self, instance):
        contractor = getContractor()

        (foundation_id, structure_id) = contractor.createInstance(
            self.site.name, self.complex, self.blueprint, instance.hostname,
            instance.config_values, instance.network.name)
        instance.foundation_id = foundation_id
        instance.structure_id = structure_id
        instance.full_clean()
        instance.save()
        contractor.registerWebHook(instance, True)
        contractor.createFoundation(instance.foundation_id)
Esempio n. 10
0
    def _takeOver(self, instance, buildjob, name, index):
        instance.buildjob = buildjob
        instance.name = name
        instance.index = index
        instance.hostname = 'mcp-auto--{0}-{1}-{2}'.format(
            buildjob.pk, name, index)
        instance.full_clean()
        instance.save()

        contractor = getContractor()
        contractor.updateConfig(instance.structure_id, instance.config_values,
                                instance.hostname)
Esempio n. 11
0
 def release(self, instance):
     contractor = getContractor()
     contractor.registerWebHook(instance, False)
     contractor.destroyStructure(instance.structure_id)
Esempio n. 12
0
File: models.py Progetto: pnhowe/MCP
 def cleanup( self ):
   contractor = getContractor()
   contractor.deleteDynamicResource( self.contractor_foundation_id, self.contractor_structure_id )
   self.delete()
Esempio n. 13
0
File: models.py Progetto: pnhowe/MCP
 def release( self ):
   contractor = getContractor()
   if contractor.releaseDynamicResource( self.contractor_foundation_id, self.contractor_structure_id ):
     contractor.registerWebHook( self.buildjobresourceinstance, False, foundation_id=self.contractor_foundation_id )
Esempio n. 14
0
File: models.py Progetto: pnhowe/MCP
 def release( self ):
   contractor = getContractor()
   contractor.releaseStatic( self.contractor_structure_id )
   contractor.registerWebHook( self.buildjobresourceinstance, False, structure_id=self.contractor_structure_id )
Esempio n. 15
0
File: models.py Progetto: pnhowe/MCP
 def allocate( self, blueprint, config_values, hostname ):
   contractor = getContractor()
   contractor.allocateStaticResource( self.contractor_structure_id, blueprint, config_values, hostname )
   contractor.registerWebHook( self.buildjobresourceinstance, True, structure_id=self.contractor_structure_id )
Esempio n. 16
0
File: models.py Progetto: pnhowe/MCP
 def updateConfig( self, config_values, hostname ):
   contractor = getContractor()
   contractor.updateConfig( self.contractor_structure_id, config_values, hostname )