Ejemplo n.º 1
0
def turn_on_flag(item):
    """
    Turn on rebalance flag on puppet master server in file "/etc/puppet/modules/openstack/manifests/swift_ringbuilder.pp"
    """
    
    
    ring_config_file = "/etc/puppet/modules/openstack/manifests/swift_ringbuilder.pp"
    bk_file = __backup_file__(ring_config_file)
    
    try:
        f = open(ring_config_file, 'rb')
        tmp_str = f.read()
        f.close()
        
        
        if item == "rebalance":
            tmp_str = tmp_str.replace("$enforce_rebalance = 'no'", "$enforce_rebalance = 'yes'")
    
        
        if item == "remove":
            tmp_str = tmp_str.replace("$enable_node_remove = 'no'", "$enable_node_remove = 'yes'")
        
        
        f = open(ring_config_file, 'wb')
        f.write(tmp_str)
        f.close()
    
    except:
        cmd="cp bk_file /etc/puppet/modules/openstack/manifests/swift_ringbuilder.pp"
        exec_command(cmd) 
        
    finally :
        os.remove(bk_file)
Ejemplo n.º 2
0
def add_device_config():
    
    try:
         turn_off_flag("remove")
    except FileNotExist:
        print "Sorry that file does not exist"
    
    cmd= "puppet agent -t"
    exec_command(cmd)       
Ejemplo n.º 3
0
def node_status(servertype):
    """
    Params:
        servertype: Could be proxy-node/storage-node/all
    Steps:
    Gather type, process status information from each server and display
    """
    all_status(servertype,status)
    exec_command(cmd)
Ejemplo n.º 4
0
def remove_device_config():
    
    try:
        turn_on_remove()
    except FileNotExist:
        print "Sorry that file does not exist"
    
    cmd= "puppet agent -t"
    exec_command(cmd)       
    
    try:
        turn_off_remove()
    except FileNotExist:
        print" sorry this file does not exist"
Ejemplo n.º 5
0
def add_device(ring, devices):
    """
    Params:
      ring : object|container|account
      devices: The list of devices which we want to add into the ring
      ['IP:PORT/sda6',.....]
      
    Steps:
      1. Remove devices from "remove_devices.conf" on puppet master;
      2. Turn off "remove" flag on puppet master;
      3. Send command to ringbuilder server to refresh puppet agent, so that it starts ring rebuilding
      4. Send command to all storage node and proxy node to refresh puppet agent
    """
    
    for item in devices:
     cmd="salt -G 'servertype:swift-%s'ring.add_device_delete(%s)"%ring,item
     exec_command(cmd)
    cmd="salt -G 'servertype:swift-%s' ring.add_device_config()"%ring
    exec_command(cmd)
    push_config('ringbuilder')
    push_ring() 
Ejemplo n.º 6
0
def print_formatted_output(cmd):
        data=[]
        retcode, output, errors, interval =exec_command([cmd])
        tmplist = output.split(':', 1)
        node = tmplist[0]
        obj = eval(tmplist[1])
        msg = obj['stdout']
        line1 = [node, str(retcode), msg]
        data.append(line1)
        title = ['node', 'status', 'message']
        width = 30, 7, 60
        formatter = OutputFormatter(data, title, width)
        formatter.print_dict()
Ejemplo n.º 7
0
def ring_rebalance():
    try:
        cmd= "rm /etc/swift/enforce-rebalance"
        exec_command_alone(cmd)
    except FileNotExist:
        
        print"File does not exist : %s" % cmd
        continue
    
    try:
        turn_on_rebalance()
    except FileNotExist:
        print "Sorry that file does not exist"
        sys.exit(1)
            
    cmd= "puppet agent -t"
    exec_command(cmd)       
    
    try:
        turn_off_rebalance()
    except FileNotExist:
        print" sorry this file does not exist"
        sys.exit(1)      
Ejemplo n.º 8
0
def __run_cmd_print__(cmd, consolecmd, rettype='dict'):
    """
    Params:
      cmd : The shell command line which will be run by python
      consolecmd : The console command line, which will show in result, i.e. "show-ring account"
      rettype : The return type of cmd.
        str : The result likes "node : {.....}"
        dict: The resule likes "{'node' : {.....}}"
    """
    
    retcode, output, errors, interval = exec_command(cmd)
    data = __normalize_ret__(output, rettype)

    title = ['node', 'retcode', 'message']
    width = (30, 10, 88)
    
    formatter = OutputFormatter(data,title, width, cmd=consolecmd)
    formatter.print_dict()
        for line in printlines:
            print "%s" % (line)

        del printlines
        
    
###############################################
## For testing
##    

from swiftconsole.common.utils import exec_command

if __name__ == '__main__':
    data = []
    cmd = "salt 'ciswift001.webex.com' puppet.run"
    retcode, output, errors, interval = exec_command([cmd])
   
    tmplist = output.split(':', 1)
    node = tmplist[0]
    obj = eval(tmplist[1])
    msg = obj['stdout']
        
    line1 = [node, str(retcode), msg]
    data.append(line1)
    
    title = ['node', 'status', 'message']
    width = (30, 7, 60)
    
    formatter = OutputFormatter(data,title, width)
    formatter.print_dict()