system.osi.gethostname

Here are the examples of the python api system.osi.gethostname taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

Example 1

Project: rockstor-core Source File: appliances.py
Function: update_hostname
    @staticmethod
    @transaction.atomic
    def _update_hostname():
        a = Appliance.objects.get(current_appliance=True)
        cur_hostname = gethostname()
        if (cur_hostname != a.hostname):
            a.hostname = cur_hostname
        if (a.ipaddr != a.ip):
            a.ip = a.ipaddr
        a.save()

Example 2

Project: rockstor-core Source File: email_client.py
def update_generic(sender, revert=False):
    """
    overrites the contents of /etc/postfix/generic with the following mapping
    @<hostname> <sender-email-address>
    @<hostname>.localdomain <sender-email-address>
    Then sets the file permissions and runs "postmap generic" to create the db
    file and change it's permissions in turn.
    :param sender: email address entered as the sender email account
    :param revert: if True wipe the generic_file and db (defaults to False)
    :return:
    """
    generic_file = '/etc/postfix/generic'
    hostname = gethostname()
    with open(generic_file, 'w') as fo:
        if (not revert):
            fo.write('@%s %s\n' % (hostname, sender))
            fo.write('@%s.localdomain %s\n' %(hostname, sender))
            # todo need an entry here to add @<hostname>.<domain>
    os.chmod(generic_file, 0400)

Example 3

Project: rockstor-core Source File: email_util.py
def email_root(subject, message):
    """
    Simple wrapper to email root, which generally will be forwarded to admin
    personnel if email notifications are enabled hence acting as remote monitor
    / notification system
    :param subject: of the email
    :param message: body content of the email
    """
    hostname = gethostname()

    msg = MIMEMultipart()
    msg['From'] = 'notifications@%s' % hostname
    msg['To'] = 'root@%s' % hostname
    msg['Date'] = formatdate(localtime=True)
    msg['Subject'] = subject
    msg.attach(MIMEText(message))

    smtp = smtplib.SMTP('localhost')
    smtp.sendmail(msg['From'], msg['To'], msg.as_string())
    smtp.close()