def main(self):
        cert_dir=constants.INV_HUB_CERTS_PATH

        if not os.path.exists(cert_dir):
            os.makedirs(cert_dir)

	cert=os.path.join(constants.INV_HUB_CERTS_PATH, constants.INV_HUB_PUB_CERT)
	pem=os.path.join(constants.INV_HUB_CERTS_PATH, constants.INV_HUB_PEM)
	pkey=os.path.join(constants.INV_HUB_CERTS_PATH, constants.INV_HUB_PRIV_KEY)

	sys.stdout.write("key: %s\ncert: %s\npem: %s\n" % (pkey,cert,pem))

	# try to erase old files	
	for f in (cert,pem,pkey):
            fileutils.safe_delete_node(f)

        # generate a new private key
        with open(pkey, 'w') as f:
            sp.Popen(ENV + ['openssl','genrsa','1024'], stdout=f).wait()

        # make private
        os.chmod(pkey, 0400)

        cnf=constants.INV_HUB_CERT_SSL_CONF
        # create self-signed cert from the key
        with open(cert,'w') as f:
            sp.Popen(ENV + ['openssl','req','-new','-x509','-nodes','-sha1','-days','3650','-key',pkey,'-config',cnf,'-batch'], \
                     stdout=f).wait()

        # create pem file
        with open(pem,'w') as f:
            sp.Popen(ENV + ['cat',pkey,cert],stdout=f).wait()
    def main(self):
        cert_dir = constants.INV_HUB_CERTS_PATH

        if not os.path.exists(cert_dir):
            os.makedirs(cert_dir)

        cert = os.path.join(constants.INV_HUB_CERTS_PATH,
                            constants.INV_HUB_PUB_CERT)
        pem = os.path.join(constants.INV_HUB_CERTS_PATH, constants.INV_HUB_PEM)
        pkey = os.path.join(constants.INV_HUB_CERTS_PATH,
                            constants.INV_HUB_PRIV_KEY)

        sys.stdout.write("key: %s\ncert: %s\npem: %s\n" % (pkey, cert, pem))

        # try to erase old files
        for f in (cert, pem, pkey):
            fileutils.safe_delete_node(f)

        # generate a new private key
        with open(pkey, 'w') as f:
            sp.Popen(ENV + ['openssl', 'genrsa', '1024'], stdout=f).wait()

        # make private
        os.chmod(pkey, 0400)

        cnf = constants.INV_HUB_CERT_SSL_CONF
        # create self-signed cert from the key
        with open(cert, 'w') as f:
            sp.Popen(ENV + ['openssl','req','-new','-x509','-nodes','-sha1','-days','3650','-key',pkey,'-config',cnf,'-batch'], \
                     stdout=f).wait()

        # create pem file
        with open(pem, 'w') as f:
            sp.Popen(ENV + ['cat', pkey, cert], stdout=f).wait()
예제 #3
0
def main():
    syslog.openlog('pre-image-clean', 0, syslog.LOG_LOCAL5)
    
    install_root=path.dirname(path.dirname(path.abspath(sys.argv[0])))
    overlay_root=path.join(install_root, "overlay")
    install_bin=path.join(install_root, 'bin')

    stdout.write("\nRemoving hub certs and keys...\n")
    fileutils.safe_delete_node(constants.INV_HUB_CERTS_PATH)

    stdout.write("\nRemoving udev NIC naming rules...\n")
    fileutils.safe_delete_node('/etc/udev/rules.d/70-persistent-net.rules')

    # remove any lock files that might block rule regeneration
    fileutils.safe_delete_node('/dev/.udev/.lock-70-persistent-net.rules')

    stdout.write("\nClearing APT cache...\n")
    sp.call(['apt-get','autoremove'])
    sp.call(['apt-get','autoclean'])
    sp.call(['apt-get','clean'])

    #
    # remove old kernels
    #
    
    # remove old kernels
    print "Attempting to remove old kernels. Don't worry about any errors"
    sp.call(['apt-get','remove','-y','--force-yes','--purge','.*-1[6789]-generic'])
    sp.call(['apt-get','remove','-y','--force-yes','--purge','.*-2[01]-generic'])
    
    print "Ignore any error above about 'package not found'"

    print "Done"
        
    return 0