Ejemplo n.º 1
0
def get_vg(f):

    if not os.path.exists(f):
        perror(f + " : does not exist")
        return None

    f = open(f,'r')
    for line in f.readlines():
        vg = re.match(r'^VMVolGroup="(\w+?)"', line)
        if vg:
            return vg.group(1)
    f.close()
    return None
Ejemplo n.º 2
0
def attached_to_br(bridge_id):

    bridge_intf_path = "/sys/class/net/br%d/brif" % bridge_id
    vnet = []
    if not os.path.exists(bridge_intf_path):
        perror("\"br%d\" not found" % bridge_id)
        return vnet

    for lsfile in os.listdir(bridge_intf_path):
        if not lsfile.startswith('vnet'):
            continue

        vnet.append(lsfile)

    return vnet
Ejemplo n.º 3
0
def chpasswd(root='/'):
    randomsalt = ""
    pinfo("Please enter root password (apg -a 1 -n 1 -m 16 -x 16 -M LN -E 'azqwm')")
    password   = getpass.getpass()
    choices    = string.ascii_uppercase + string.digits + string.ascii_lowercase

    for _ in range(0,8):
        randomsalt += random.choice(choices)

    pwhash      = crypt.crypt(password, '$6$%s$' % randomsalt)
    shadowentry = 'root:' + pwhash + ':' + str(int(time.time() / 86400)) + ':0:99999:7:::'

    try:
        subprocess.call(["sed", "-i", "s#^root.*#" + shadowentry + "#1", root + "/etc/shadow"])
    except:
        perror("Failed to setup root password")
        pass
Ejemplo n.º 4
0
def remove_local_config(bridge_id, delete_vlan=True, phydev="bond0"):
    vnets = attached_to_br(bridge_id)
    if len(vnets) > 0:
        dom = []
        for vnet in vnets:
            dom.append(attached_domain_from_vnet(vnet))

        perror("Bridge br%d is used\n- " % bridge_id + "\n- ".join(dom))
        sys.exit(2)

    pinfo("Stop bridge interface br%d" % bridge_id)
    call(["ifdown", "br%d" % bridge_id])

    pinfo("Remove bridge configuration file")
    bridge_cfg_file = "/etc/sysconfig/network-scripts/ifcfg-br%d" % bridge_id

    if os.path.exists(bridge_cfg_file):
        os.unlink(bridge_cfg_file)
    else:
        perror("%s does not exist" % bridge_cfg_file)

    if delete_vlan:
        pinfo("Stop VLAN interface %s.%d" % (phydev, bridge_id))
        call(["ifdown", "%s.%d" % (phydev, bridge_id)])

        pinfo("Remove VLAN configuration file")
        vlan_cfg_file = "/etc/sysconfig/network-scripts/ifcfg-%s.%d" % (phydev, bridge_id)

        if os.path.exists(vlan_cfg_file):
            os.unlink(vlan_cfg_file)
        else:
            perror("%s does not exist" % vlan_cfg_file)
Ejemplo n.º 5
0
        usage()
except:
    usage()
    sys.exit(1)

conf = vmcConfig()

if conf.do_cluster:
    # Check if the domain is running somewhere
    # And undefine everywhere
    for h in conf.cluster_nodes:
        conn = libvirt.open("qemu+ssh://" + h + "/system")
        try:
            dom = conn.lookupByName(toundefine)
        except:
            perror("\"%s\" domain isn't defined on %s" % (toundefine, h))
            dom = None
            pass

        if not dom == None:
            if dom.isActive():
                perror("\"%s\" domain is running on %s, shutdown the domain and retry" % (toundefine, h))
                conn.close()
                sys.exit(1)
            else:
                pinfo("Undefine \"%s\" on %s" % (toundefine, h))
                dom.undefine()

        conn.close()

else:
Ejemplo n.º 6
0
    def set_puppet_config(self):
        pinfo("Setting up Puppet configuration")

        fqdn = self.vm.name + "." + self.vm.domain 

        try:
            f = open(self.new_root + "/etc/puppet/puppet.conf", "w")
            if self.ip == "dhcp":
                f.write("""[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
#factpath=$vardir/lib/facter
templatedir=$confdir/templates
pluginsync=true

[agent]
ssldir = /etc/puppet/ssl
server=puppetmaster.accelance.net
certname=%s
fqdn=%s
listen=true
client=false
#bindaddress=
report=true
environment=production\n""" % (fqdn, fqdn))
            else:
                f.write("""[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
#factpath=$vardir/lib/facter
templatedir=$confdir/templates
pluginsync=true

[agent]
ssldir = /etc/puppet/ssl
server=puppetmaster.accelance.net
certname=%s
fqdn=%s
listen=true
client=false
bindaddress=%s
report=true
environment=production\n""" % (fqdn, fqdn, self.ip))

            f.close()

            open(self.new_root + "/etc/puppet/namespaceauth.conf", "a").close()
        except:
            perror("Failed to configure Puppet")
            pass

        f = open(self.new_root + "/etc/default/puppet", "w")
        f.write( """# Defaults for puppet - sourced by /etc/init.d/puppet

# Start puppet on boot?
START=yes

# Startup options
DAEMON_OPTS=\"-w 5\"\n""")
        f.close()

        f = open(self.new_root + "/etc/puppet/auth.conf", "w")
        f.write("""path /run
method save
allow puppetmaster.accelance.net\n""")
        f.close()
Ejemplo n.º 7
0
    def set_puppet_config(self):
        pinfo("Setting up Puppet configuration")

        fqdn = self.vm.name + "." + self.vm.domain 

        try:
            f = open(self.new_root + "/etc/puppet/puppet.conf", "w")
            if self.ip == "dhcp":
                f.write("""[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
#factpath=$vardir/lib/facter
templatedir=$confdir/templates
pluginsync=true

[agent]
ssldir = /etc/puppet/ssl
server=puppetmaster.accelance.net
certname=%s
fqdn=%s
listen=true
client=false
#bindaddress=
report=true
environment=production\n""" % (fqdn, fqdn))
            else:
                f.write("""[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
#factpath=$vardir/lib/facter
templatedir=$confdir/templates
pluginsync=true

[agent]
ssldir = /etc/puppet/ssl
server=puppetmaster.accelance.net
certname=%s
fqdn=%s
listen=true
client=false
bindaddress=%s
report=true
environment=production\n""" % (fqdn, fqdn, self.ip))

            f.close()

            open(self.new_root + "/etc/puppet/namespaceauth.conf", "a").close()
        except:
            perror("Failed to configure Puppet")
            pass

        f = open(self.new_root + "/etc/sysconfig/puppet", "w")
        f.write( """# The puppetmaster server
#PUPPET_SERVER=puppet

# If you wish to specify the port to connect to do so here
#PUPPET_PORT=8140

# Where to log to. Specify syslog to send log messages to the system log.
#PUPPET_LOG=/var/log/puppet/puppet.log

# You may specify other parameters to the puppet client here
PUPPET_EXTRA_OPTS=\"-w 5\"\n""")
        f.close()

        f = open(self.new_root + "/etc/puppet/auth.conf", "w")
        f.write("""path /run
method save
allow puppetmaster.accelance.net\n""")
        f.close()