def get_nics(network): nic = Nic(ip='192.168.0.4', boot=True) nic.network = network nic2 = Nic(boot=False) return [nic, nic2]
def get_hardwareprofile(): hwprofile = HardwareProfile() hwprofile.nics = [Nic(ip='192.168.0.1', boot=True)] hwprofile.hardwareprofilenetworks = [] return hwprofile
def start(self, addNodesRequest: dict, dbSession: Session, dbHardwareProfile: HardwareProfile, dbSoftwareProfile: Optional[SoftwareProfile] = None): """ Create nodes """ # # Load resource adapter settings # config = self.getResourceAdapterConfig( sectionName=addNodesRequest.get( 'resource_adapter_configuration', 'default') ) nodes = [] for _ in range(addNodesRequest['count']): random_host_name_suffix = get_random_host_name_suffix() node = Node(name='compute-{}'.format(random_host_name_suffix)) node.softwareprofile = dbSoftwareProfile node.hardwareprofile = dbHardwareProfile node.isIdle = False node.state = self.STATE_TRANSITIONS[0] # create dummy nic nic = Nic(boot=True, ip=generate_fake_ip()) node.nics.append(nic) self._simulate_state_changes( node, config.get('state', self.settings['state'].default) ) nodes.append(node) return nodes
def dbm(): dbmgr = DbManager(create_engine('sqlite:///:memory:', echo=False)) dbmgr.init_database() rhel7_os_family_info = osFamilyInfo.OsFamilyInfo('rhel', '7', 'x86_64') os_info = osInfo.OsInfo('centos', '7.4', 'x86_64') os_info.setOsFamilyInfo(rhel7_os_family_info) installer_fqdn = getfqdn() settings = { 'language': 'en', 'keyboard': 'en_US', 'timezone': 'UTC', 'utc': 'true', 'intWebPort': '8008', 'intWebServicePort': '8444', 'adminPort': '8443', 'eulaAccepted': 'true', 'depotpath': '/opt/tortuga/depot', 'osInfo': os_info, 'fqdn': installer_fqdn, 'installer_software_profile': 'Installer', 'installer_hardware_profile': 'Installer', } with dbmgr.session() as session: primeDb(session, settings) init_global_parameters(session, settings) # create sample tags all_tags = [{ 'name': 'tag{:d}'.format(idx), 'value': 'value{:d}'.format(idx) } for idx in range(1, 5 + 1)] installer_node = session.query(Node).filter( Node.name == installer_fqdn).one() os_ = session.query(OperatingSystem).filter( OperatingSystem.name == 'centos').one() rhel7_os_family = session.query(OperatingSystemFamily).filter( OperatingSystemFamily.name == 'rhel').one() # add add'l operating system/family rhel75_os = OperatingSystem(name='rhel', version='7.5', arch='x86_64') rhel75_os.family = rhel7_os_family session.add(rhel75_os) admin = Admin(username='******', password=pbkdf2_sha256.hash('password'), realname='realname', description='description') session.add(admin) eth1_network_device = NetworkDevice(name='eth1') # Add dummy provisioning network network = Network() network.address = '10.2.0.0' network.netmask = '255.255.255.0' network.name = 'Provisioning network on eth1' network.type = 'provision' session.add(network) # create 'hardwareprofilenetwork' entry hwpn1 = HardwareProfileNetwork( hardwareprofile=installer_node.hardwareprofile, network=network, networkdevice=eth1_network_device) # create nic on installer installer_nic = Nic() installer_nic.ip = '10.2.0.1' installer_nic.network = network installer_nic.networkdevice = eth1_network_device installer_node.nics = [installer_nic] # create 'base' kit kit = Kit() kit.name = 'base' kit.version = '7.1.1' kit.iteration = '0' kit.description = 'Sample base kit' installer_component = Component(name='installer', version='7.0') installer_component.family = [rhel7_os_family] installer_component.kit = kit core_component = Component(name='core', version='7.0', description='Compute component') core_component.family = [rhel7_os_family] core_component.kit = kit session.add(kit) # create OS kit os_kit = Kit(name='centos', version='7.4', iteration='0') os_kit.isOs = True os_component = Component(name='centos-7.4-x86_64', version='7.4') os_component.os = [os_] os_component.kit = os_kit os_kit.components.append(os_component) session.add(os_kit) # create resource adapter kit ra_kit = Kit(name='awsadapter', version='0.0.1', iteration='0') ra_component = Component(name='management', version='0.0.1') ra_component.family.append(rhel7_os_family) ra_kit.components.append(ra_component) installer_node.softwareprofile.components.append(ra_component) installer_node.softwareprofile.components.append(installer_component) session.commit() # create 'default' resource adapter default_adapter = ResourceAdapter( name=DEFAULT_CONFIGURATION_PROFILE_NAME, kit=kit, ) # create resource adapter aws_adapter = ResourceAdapter(name='AWS') aws_adapter.kit = ra_kit aws_adapter_cfg = ResourceAdapterConfig( name=DEFAULT_CONFIGURATION_PROFILE_NAME, description='Example default resource adapter configuration') with mock_ec2_deprecated(): ec2_conn = boto.ec2.connect_to_region('us-east-1') amis = ec2_conn.get_all_images() aws_adapter_cfg.configuration.append( ResourceAdapterSetting(key='ami', value=amis[0].id)) aws_adapter.resource_adapter_config.append(aws_adapter_cfg) # add second resource adapter configuration aws_adapter_cfg2 = ResourceAdapterConfig(name='nondefault', admin=admin) aws_adapter_cfg2.configuration.append( ResourceAdapterSetting(key='another_key', value='another_value')) session.add(aws_adapter) # create 'AWS' hardware profile aws_hwprofile = HardwareProfile(name='AWS') aws_hwprofile.location = 'remote' aws_hwprofile.resourceadapter = aws_adapter session.add(aws_hwprofile) aws_hwprofile2 = HardwareProfile(name='aws2', location='remote', resourceadapter=aws_adapter, nameFormat='*') session.add(aws_hwprofile2) # create 'compute' software profile compute_swprofile = SoftwareProfile(name='compute') compute_swprofile.os = os_ compute_swprofile.components = [core_component] compute_swprofile.type = 'compute' # create 'compute2' software profile compute2_swprofile = SoftwareProfile(name='compute2', os=os_, components=[core_component], type='compute') # map 'AWS' to 'compute' aws_hwprofile.mappedsoftwareprofiles.append(compute_swprofile) aws_hwprofile2.mappedsoftwareprofiles.append(compute_swprofile) # create 'localiron' hardware profile localiron_hwprofile = HardwareProfile(name='localiron', nameFormat='compute-#NN') localiron_hwprofile.resourceadapter = default_adapter localiron_hwprofile.mappedsoftwareprofiles.append(compute_swprofile) localiron_hwprofile.mappedsoftwareprofiles.append(compute2_swprofile) localiron_hwprofile.hardwareprofilenetworks.append(hwpn1) # create 'nonetwork' hardware profile nonetwork_hwprofile = HardwareProfile(name='nonetwork') nonetwork_hwprofile.resourceadapter = default_adapter nonetwork_hwprofile.mappedsoftwareprofiles.append(compute_swprofile) eth0_networkdevice = NetworkDevice(name='eth0') # create compute (compute-01, compute-02, ...) nodes for n in range(1, 11): compute_node = Node(name='compute-{0:02d}.private'.format(n), state='Installed') compute_node.addHostSession = '1234' compute_node.softwareprofile = compute_swprofile compute_node.hardwareprofile = localiron_hwprofile compute_node.nics.append( Nic(ip='10.2.0.{}'.format(100 + n), mac='FF:00:00:00:00:00:{:02x}'.format(100 + n), boot=True, network=network, networkdevice=eth0_networkdevice)) if n in (1, 2): # compute-01 and compute-02 have all tags compute_node.tags = [ NodeTag( name=tag['name'], value=tag['value'], ) for tag in all_tags ] elif n in (3, 4): # compute-03 and compute-04 have 'tag1' and 'tag2' compute_node.tags = [ NodeTag( name=all_tags[0]['name'], value=all_tags[0]['value'], ), NodeTag( name=all_tags[1]['name'], value=all_tags[1]['value'], ), ] elif n in (5, 6): # compute-05 and compute-06 have 'tag2' and 'tag3' compute_node.tags = [ NodeTag( name=all_tags[1]['name'], value=all_tags[1]['value'], ), NodeTag( name=all_tags[2]['name'], value=all_tags[2]['value'], ), ] elif n == 7: # compute-07 has 'tag4' compute_node.tags = [ NodeTag( name=all_tags[3]['name'], value=all_tags[3]['value'], ), ] elif n == 8: # compute-08 has 'tag5' compute_node.tags = [ NodeTag( name=all_tags[4]['name'], value=all_tags[4]['value'], ), ] session.add(compute_node) # create arbitrary aws nodes for idx in range(1, 10): new_node = Node( name='ip-10-10-10-{:0d}.ec2.internal'.format(idx), hardwareprofile=aws_hwprofile, softwareprofile=compute_swprofile, ) new_node.instance = InstanceMapping( instance='i-{:08x}'.format(idx)) new_node.instance.resource_adapter_configuration = aws_adapter_cfg session.add(new_node) # create arbitrary hardware profiles hwprofile1 = HardwareProfile( name='profile1', tags=[ HardwareProfileTag( name=all_tags[0]['name'], value=all_tags[0]['value'], ), ], ) hwprofile2 = HardwareProfile( name='profile2', tags=[ HardwareProfileTag( name=all_tags[1]['name'], value=all_tags[1]['value'], ), ], ) session.add(hwprofile1) session.add(hwprofile2) # create arbitrary software profiles SoftwareProfile( name='swprofile1', os=os_, type='compute', tags=[ SoftwareProfileTag(name=all_tags[0]['name'], value=all_tags[0]['value']), ], ) SoftwareProfile( name='swprofile2', os=os_, type='compute', tags=[ SoftwareProfileTag( name=all_tags[1]['name'], value=all_tags[1]['value'], ), ], ) session.commit() return dbmgr
def dbm(): dbmgr = DbManager(create_engine('sqlite:///:memory:', echo=False)) dbmgr.init_database() rhel7_os_family_info = osFamilyInfo.OsFamilyInfo('rhel', '7', 'x86_64') os_info = osInfo.OsInfo('centos', '7.4', 'x86_64') os_info.setOsFamilyInfo(rhel7_os_family_info) settings = { 'language': 'en', 'keyboard': 'en_US', 'timezone': 'UTC', 'utc': 'true', 'intWebPort': '8008', 'intWebServicePort': '8444', 'adminPort': '8443', 'eulaAccepted': 'true', 'depotpath': '/opt/tortuga/depot', 'osInfo': os_info, 'fqdn': getfqdn(), 'installer_software_profile': 'Installer', 'installer_hardware_profile': 'Installer', } with dbmgr.session() as session: primeDb(session, settings) init_global_parameters(session, settings) # create sample tags all_tags = [] for idx in range(1, 5 + 1): tag = dict( name='tag{:d}'.format(idx), value='value{:d}'.format(idx), ) all_tags.append(tag) installer_node = session.query(Node).filter( Node.name == settings['fqdn']).one() os_ = session.query(OperatingSystem).filter( OperatingSystem.name == 'centos').one() rhel7_os_family = session.query(OperatingSystemFamily).filter( OperatingSystemFamily.name == 'rhel').one() # add add'l operating system/family rhel75_os = OperatingSystem(name='rhel', version='7.5', arch='x86_64') rhel75_os.family = rhel7_os_family session.add(rhel75_os) admin = Admin(username='******', password=pbkdf2_sha256.hash('password'), realname='realname', description='description') session.add(admin) eth0_network_device = NetworkDevice(name='eth0') eth1_network_device = NetworkDevice(name='eth1') # Add dummy provisioning network network = Network(address='10.2.0.0', netmask='255.255.255.0', name='Provisioning network on eth1', type='provision') installer_node.hardwareprofile.hardwareprofilenetworks.append( HardwareProfileNetwork( network=network, networkdevice=eth1_network_device, )) # create nic on installer installer_nic = Nic( ip='10.2.0.1', network=network, networkdevice=eth1_network_device, ) installer_node.nics = [installer_nic] # create 'base' kit kit = Kit() kit.name = 'base' kit.version = '7.1.0' kit.iteration = '0' kit.description = 'Sample base kit' installer_component = Component(name='installer', version='7.0') installer_component.family = [rhel7_os_family] installer_component.kit = kit core_component = Component(name='core', version='7.0', description='Compute component') core_component.family = [rhel7_os_family] core_component.kit = kit # add component not enabled by default pdsh_component = Component(name='pdsh', version='7.0', description='pdsh component') pdsh_component.family = [rhel7_os_family] pdsh_component.kit = kit # add fake dhcp component dhcpd_component = Component(name='dhcpd', version='7.0', description='Mock dhcpd component') dhcpd_component.family = [rhel7_os_family] dhcpd_component.kit = kit session.add(kit) # create OS kit os_kit = Kit(name='centos', version='7.4', iteration='0') os_kit.isOs = True os_component = Component(name='centos-7.4-x86_64', version='7.4') os_component.os = [os_] os_component.kit = os_kit os_kit.components.append(os_component) session.add(os_kit) # create resource adapter kit ra_kit = Kit(name='awsadapter', version='0.0.1', iteration='0') ra_component = Component(name='management', version='0.0.1') ra_component.family.append(rhel7_os_family) ra_kit.components.append(ra_component) installer_node.softwareprofile.components.append(ra_component) installer_node.softwareprofile.components.append(installer_component) installer_node.softwareprofile.components.append(dhcpd_component) # create 'default' resource adapter default_adapter = ResourceAdapter(name='default', kit=kit) # create resource adapter aws_adapter = ResourceAdapter(name='aws', kit=ra_kit) aws_adapter_cfg = ResourceAdapterConfig( name='default', description='Example default resource adapter configuration') aws_adapter_cfg.configuration.append( ResourceAdapterSetting(key='ami', value='ami-XXXXXX')) aws_adapter_cfg.configuration.append( ResourceAdapterSetting(key='use_instance_hostname', value='true')) aws_adapter.resource_adapter_config.append(aws_adapter_cfg) # add second resource adapter configuration aws_adapter_cfg2 = ResourceAdapterConfig(name='nondefault', admin=admin) aws_adapter_cfg2.configuration.append( ResourceAdapterSetting(key='another_key', value='another_value')) aws_adapter.resource_adapter_config.append(aws_adapter_cfg2) session.add(aws_adapter) # create 'aws' hardware profile # does *not* have a default resource adapter config aws_hwprofile = HardwareProfile(name='aws') aws_hwprofile.location = 'remote' aws_hwprofile.resourceadapter = aws_adapter aws_hwprofile.nameFormat = '*' session.add(aws_hwprofile) # add hardware profile 'aws2' with non-default configuration profile aws_hwprofile2 = HardwareProfile( name='aws2', location='remote', resourceadapter=aws_adapter, default_resource_adapter_config=aws_adapter_cfg2, nameFormat='*', ) session.add(aws_hwprofile2) # create 'compute' software profile compute_swprofile = SoftwareProfile(name='compute') compute_swprofile.os = os_ compute_swprofile.components = [core_component] compute_swprofile.type = 'compute' # create 'compute2' software profile compute2_swprofile = SoftwareProfile(name='compute2', os=os_, components=[core_component], type='compute') # map 'aws' and 'aws2' to 'compute' compute_swprofile.hardwareprofiles.extend( (aws_hwprofile, aws_hwprofile2)) # create 'localiron' hardware profile localiron_hwprofile = HardwareProfile( name='localiron', nameFormat='compute-#NN', location='local', ) localiron_hwprofile.resourceadapter = default_adapter localiron_hwprofile.mappedsoftwareprofiles = [ compute_swprofile, compute2_swprofile ] localiron_hwprofile.hardwareprofilenetworks.append( HardwareProfileNetwork( network=network, networkdevice=eth0_network_device, )) session.add(localiron_hwprofile) # create "localironalt" hardware profile with nameFormat set to '*' localironalt_hwprofile = HardwareProfile( name='localironalt', nameFormat='*', location='local', ) localironalt_hwprofile.resourceadapter = default_adapter localironalt_hwprofile.mappedsoftwareprofiles = [ compute_swprofile, compute2_swprofile ] localironalt_hwprofile.hardwareprofilenetworks.append( HardwareProfileNetwork( network=network, networkdevice=eth0_network_device, )) # create 'nonetwork' hardware profile nonetwork_hwprofile = HardwareProfile(name='nonetwork') nonetwork_hwprofile.resourceadapter = default_adapter nonetwork_hwprofile.mappedsoftwareprofiles.append(compute_swprofile) # create compute (compute-01, compute-02, ...) nodes for n in range(1, 11): compute_node = Node(name='compute-{0:02d}.private'.format(n), state='Installed') compute_node.addHostSession = '1234' compute_node.softwareprofile = compute_swprofile compute_node.hardwareprofile = localiron_hwprofile compute_node.nics.append( Nic(ip='10.2.0.{}'.format(100 + n), mac='FF:00:00:00:00:00:{:02x}'.format(100 + n), boot=True, network=network, networkdevice=eth0_network_device)) if n in (1, 2): # compute-01 and compute-02 have all tags for tag in all_tags: compute_node.tags.append( NodeTag(name=tag['name'], value=tag['value'])) elif n in (3, 4): # compute-03 and compute-04 have 'tag1' and 'tag2' compute_node.tags.append( NodeTag(name=all_tags[0]['name'], value=all_tags[0]['value'])) compute_node.tags.append( NodeTag(name=all_tags[1]['name'], value=all_tags[1]['value'])) elif n in (5, 6): # compute-05 and compute-06 have 'tag2' and 'tag3' compute_node.tags.append( NodeTag(name=all_tags[1]['name'], value=all_tags[1]['value'])) compute_node.tags.append( NodeTag(name=all_tags[2]['name'], value=all_tags[2]['value'])) elif n == 7: # compute-07 has 'tag4' compute_node.tags.append( NodeTag(name=all_tags[3]['name'], value=all_tags[3]['value'])) elif n == 8: # compute-08 has 'tag5' compute_node.tags.append( NodeTag(name=all_tags[4]['name'], value=all_tags[4]['value'])) session.add(compute_node) # create arbitrary hardware profiles hwprofile1 = HardwareProfile(name='profile1', nameFormat='*', tags=[ HardwareProfileTag( name=all_tags[0]['name'], value=all_tags[0]['value']) ]) hwprofile2 = HardwareProfile(name='profile2', nameFormat='*', tags=[ HardwareProfileTag( name=all_tags[1]['name'], value=all_tags[1]['value']) ]) hwprofile_notags = HardwareProfile(name='notags', nameFormat='*') session.add(hwprofile1) session.add(hwprofile2) session.add(hwprofile_notags) # create arbitrary software profiles swprofile1 = SoftwareProfile(name='swprofile1', os=os_, type='compute', tags=[ SoftwareProfileTag( name=all_tags[0]['name'], value=all_tags[0]['value']) ]) swprofile2 = SoftwareProfile(name='swprofile2', os=os_, type='compute', tags=[ SoftwareProfileTag( name=all_tags[1]['name'], value=all_tags[1]['value']) ]) swprofile_notags = SoftwareProfile(name='notags', os=os_, type='compute') session.add(swprofile1) session.add(swprofile2) session.add(swprofile_notags) session.commit() return dbmgr
def _initializeNics(self, session: Session, dbNode: Node, dbHardwareProfile: HardwareProfile, nic_defs: List[dict], bValidateIp: bool = True, bGenerateIp: bool = True) -> List[Nic]: """ Return list of Nic objects reflecting the configuration of dbNode and nic definitions provided in nic_defs. :raises NetaNotFound: :raises InvalidMacAddress: :raises MacAddressAlreadyExists: """ nics = [] hwpnetworks = dbHardwareProfile.hardwareprofilenetworks[:] hwpnetworks.sort(key=lambda a: a.networkdevice.name) for nic_def, dbHardwareProfileNetwork in itertools.zip_longest( nic_defs, hwpnetworks, fillvalue=None): # Create a nic for each associated hardware profile network dbNic = Nic() dbNic.node = dbNode if nic_def and 'mac' in nic_def: # # MAC addresses are generated for virtualization platforms # such as libvirt and VMware # dbNic.mac = self._validate_mac_address( session, nic_def['mac'], dbHardwareProfileNetwork.network) # # Validate IP, if specified, otherwise generate an IP, if # requested # if nic_def and 'ip' in nic_def: if bValidateIp: self._validate_ip_address(nic_def['ip'], dbHardwareProfileNetwork.network) dbNic.ip = nic_def['ip'] else: if dbHardwareProfile.location == 'local' and \ not dbHardwareProfileNetwork: raise NicNotFound( 'Hardware profile [%s] does not have a provisioning' ' network' % (dbHardwareProfile.name)) if bGenerateIp and \ dbHardwareProfileNetwork.network.type == 'provision': # Generate an IP address for the specified nic dbNic.ip = self.generate_provisioning_ip_address( dbHardwareProfileNetwork.network) self._logger.debug('Generated IP [%s] for node [%s]' % (dbNic.ip, dbNode.name)) if dbNic.ip or \ dbHardwareProfileNetwork and \ dbHardwareProfileNetwork.network.type != 'provision': # Only add a network and network device for nodes that have # managed IP addresses. if dbHardwareProfileNetwork: dbNic.network = dbHardwareProfileNetwork.network dbNic.networkdevice = \ dbHardwareProfileNetwork.networkdevice # Set the 'boot' flag if this is a provisioning network dbNic.boot = dbNic.network and dbNic.network.type == 'provision' if dbNic.ip: reservedIps.append(dbNic.ip) nics.append(dbNic) return nics
def _instance_post_launch(self, instance, node_dict=None, node_spec=None): """ Called after instance has launched successfully. :param instance: Oracle instance :param node_dict: instance/node mapping dict :param node_spec: instance launch specification :return: Nodes object """ self.getLogger().debug( 'Instance post-launch action for instance [%s]' % ( instance.id) ) if 'node' not in node_dict: domain = self.installer_public_hostname.split('.')[1:] fqdn = '.'.join([instance.display_name] + domain) node = self.__initialize_node( fqdn, node_spec['db_hardware_profile'], node_spec['db_software_profile'] ) node_spec['db_session'].add(node) node_dict['node'] = node else: node = node_dict['node'] node.state = state.NODE_STATE_PROVISIONED # Get ip address from instance nics = [] for ip in self.__get_instance_private_ips( instance.id, instance.compartment_id): nics.append( Nic(ip=ip, boot=True) ) node.nics = nics node_spec['db_session'].commit() self.instanceCacheSet( node.name, { 'id': instance.id, 'compartment_id': instance.id, 'shape': node_spec['configDict']['shape'], 'vcpus': str(node_spec['configDict']['shape'].split('.')[-1]) } ) ip = [nic for nic in node.nics if nic.boot][0].ip self._pre_add_host( node.name, node.hardwareprofile.name, node.softwareprofile.name, ip) self.getLogger().debug( '_instance_post_launch(): node=[%s]' % ( node) ) self.fire_provisioned_event(node) return node
def _addNic(self, session, nicName): # Get IP address and netmask using facter facterNicName = nicName.replace(':', '_').replace('.', '_') entries = [ 'ipaddress_%s' % (facterNicName), 'netmask_%s' % (facterNicName), 'macaddress_%s' % (facterNicName), 'network_%s' % (facterNicName) ] d = self._getMultipleFacterEntries(entries) if not 'ipaddress_%s' % (facterNicName) in d or \ not d['ipaddress_%s' % (facterNicName)]: if not self.getArgs().ipaddress: raise InvalidCliRequest( 'Unable to determine IP address, use command-line' ' override') ipaddress = self.getArgs().ipaddress else: ipaddress = d['ipaddress_%s' % (facterNicName)] if not 'netmask_%s' % (facterNicName) in d or \ not d['netmask_%s' % (facterNicName)]: if not self.getArgs().netmask: raise InvalidCliRequest( 'Unable to determine netmask, use command-line' ' override') netmask = self.getArgs().netmask else: netmask = d['netmask_%s' % (facterNicName)] if not 'network_%s' % (facterNicName) in d or \ not d['network_%s' % (facterNicName)]: if not self.getArgs().network: raise InvalidCliRequest( 'Unable to determine network, use command-line' ' override') network = self.getArgs().network else: network = d['network_%s' % (facterNicName)] # Check if nic is the default gateway as well... self._check_default_gateway_nic(nicName) dbNetwork = None # Attempt to find matching network try: dbNetwork = session.query(Network).filter( and_(Network.address == network, Network.netmask == netmask)).one() print('Found network [%s/%s]' % (dbNetwork.address, dbNetwork.netmask)) except NoResultFound: # Network is not known to Tortuga, add it pass if dbNetwork is None: print('Adding network [%s/%s]' % (network, netmask)) dbNetwork = self._addNetwork(nicName, network, netmask, session) # Attempt to find entry in NetworkDevices dbNetworkDevice = self._getNetworkDevice(nicName, session) if not dbNetworkDevice: # Create network device print('Adding network device [%s] as provisioning NIC' % (nicName)) dbNetworkDevice = self._addNetworkDevice(nicName, session) else: print('Found existing network device [%s]' % (nicName)) dbNode = NodesDbHandler().getNode(session, self._cm.getInstaller()) # Attempt to find Nics entry for dbNic in dbNode.nics: if dbNic.networkdevice.name == nicName.lower(): print('Found existing NIC entry for [%s]' % (dbNic.networkdevice.name)) break else: print('Creating NIC entry for [%s]' % (dbNetworkDevice.name)) dbNic = Nic() dbNic.networkdevice = dbNetworkDevice dbNic.ip = ipaddress dbNic.boot = True dbNic.network = dbNetwork dbNode.nics.append(dbNic) # Attempt to find NIC association with hardware profile (commonly # known as hardware profile provisioning NIC) for dbHwProfileNic in dbNode.hardwareprofile.nics: if dbHwProfileNic == dbNic: break else: print('Adding NIC [%s] to hardware profile [%s]' % (dbNic.networkdevice.name, dbNode.hardwareprofile.name)) dbNode.hardwareprofile.nics.append(dbNic) # Attempt to find 'HardwareProfileNetworks' entry for dbHardwareProfileNetwork in \ dbNode.hardwareprofile.hardwareprofilenetworks: if dbHardwareProfileNetwork.network == dbNetwork and \ dbHardwareProfileNetwork.networkdevice == dbNetworkDevice: print('Found existing hardware profile/network association') break else: dbHardwareProfileNetwork = HardwareProfileNetwork() dbHardwareProfileNetwork.network = dbNetwork dbHardwareProfileNetwork.networkdevice = dbNetworkDevice dbNode.hardwareprofile.hardwareprofilenetworks.append( dbHardwareProfileNetwork) session.commit() bUpdated = self._updateNetworkConfig(session, dbNode) if bUpdated and self.getArgs().bSync: print('Applying changes to Tortuga...') cmd = ('/opt/puppetlabs/bin/puppet agent --onetime' ' --no-daemonize >/dev/null 2>&1') tortugaSubprocess.executeCommandAndIgnoreFailure(cmd)