コード例 #1
0
def net_ads_join(user, pswd, password_server):
  try:
    cmd_to_run = "net ads join -S %s  -U %s%%%s"%(password_server, user, pswd)
    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      errors = []
      client = salt.client.LocalClient()
      print 'Running %s'%cmd_to_run
      #assert False
      r1 = client.cmd('*', 'cmd.run_all', [cmd_to_run])
      print r1
      if r1:
        for node, ret in r1.items():
          #print ret
          if ret["retcode"] != 0:
            e = "Error joining AD on node %s"%node
            if "stderr" in ret:
              e += " : %s"%ret["stderr"]
            errors.append(e)
            print errors
      print r1
      if errors:
        raise Exception(' '.join(errors))
    else:
      lines, err = command.get_command_output(cmd_to_run)
      if err:
        raise Exception(err)
  except Exception, e:
    return False , 'Error joining AD : %s'%str(e)
コード例 #2
0
def delete_local_group(grpname):

  try:
    if not grpname:
      raise Exception('No username specified')
    d, err = get_local_group(grpname)
    if not d:
      if err:
        raise Exception('Error locating group : %s'%err)
      else:
        raise Exception('Error locating group')

    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      client = salt.client.LocalClient()
      rc = client.cmd('*', 'group.delete', [grpname] )
      #print rc
      if rc:
        for hostname, status in rc.items():
          if not status:
            raise Exception("Error deleting the system group")
      else:
            raise Exception("Error deleting the system group")
    else:
      cmd_to_run = 'groupdel  %s'%(grpname)
      lines, err = command.get_command_output(cmd_to_run)
      if err:
        raise Exception(err)
    
  except Exception, e:
    return False, 'Error deleting local group : %s'%str(e)
コード例 #3
0
def kinit(user, pswd, realm):
  try:
    cmd_to_run = 'echo "%s\n" | kinit %s@%s'%(pswd, user, realm)
    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      errors = []
      client = salt.client.LocalClient()
      print 'Running %s'%cmd_to_run
      #assert False
      r1 = client.cmd('*', 'cmd.run_all', [cmd_to_run])
      if r1:
        for node, ret in r1.items():
          #print ret
          if ret["retcode"] != 0:
            e = "Error initiating kerberos on GRIDCell %s"%node
            if "stderr" in ret:
              e += " : %s"%ret["stderr"]
            errors.append(e)
            print errors
      print r1
      if errors:
        raise Exception(' '.join(errors))
    else:
      lines, err = command.get_command_output(cmd_to_run)
      if err:
        raise Exception(err)
  except Exception, e:
    return False, 'Error initializing kerberos : %s'%str(e)
コード例 #4
0
def flag_node(request):

  try:
    return_dict = {}
    if "node" not in request.GET:
      raise Exception("Error flagging node. No node specified")
  
    node_name = request.GET["node"]
    blink_time = 255
    use_salt, err = common.use_salt()
    if use_salt:
      import salt.client
      client = salt.client.LocalClient()
      ret = client.cmd(node_name,'cmd.run',['ipmitool chassis identify %s' %(blink_time)])
      print ret
      if ret[node_name] == 'Chassis identify interval: %s seconds'%(blink_time):
        return django.http.HttpResponse("Success")
      else:
        raise Exception("")
    else:
      out_list, err = command.get_command_output('service winbind status')
      if err:
        raise Exception(err)
      if 'Chassis identify interval: %s seconds'%(blink_time) in out_list[0]:
        return django.http.HttpResponse("Success")
      else:
        raise Exception("")
  except Exception, e:
    return django.http.HttpResponse("Error")
コード例 #5
0
def delete_local_group(grpname):

  try:
    if not grpname:
      raise Exception('No username specified')
    d, err = get_local_group(grpname)
    if not d:
      if err:
        raise Exception('Error locating group : %s'%err)
      else:
        raise Exception('Error locating group')

    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      client = salt.client.LocalClient()
      rc = client.cmd('*', 'group.delete', [grpname] )
      #print rc
      if rc:
        for hostname, status in rc.items():
          if not status:
            raise Exception("Error deleting the system group")
      else:
            raise Exception("Error deleting the system group")
    else:
      cmd_to_run = 'groupdel  %s'%(grpname)
      lines, err = command.get_command_output(cmd_to_run)
      if err:
        raise Exception(err)
    
  except Exception, e:
    return False, 'Error deleting local group : %s'%str(e)
コード例 #6
0
def restart_samba_services():
  try:
    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      client = salt.client.LocalClient()
      rc = client.cmd('*', 'service.reload', ['smbd'] )
      print rc
      rc = client.cmd('*', 'service.reload', ['winbind'] )
      print rc
      #rc = client.cmd('*', 'service.reload', ['nmbd'] )
      #print rc
    else:
      (ret, rc), err = command.execute_with_rc('service smb reload')
      if err:
        raise Exception(err)
      (ret, rc), err = command.execute_with_rc('service winbind reload')
      if err:
        raise Exception(err)
      if rc != 0:
        err = ''
        tl, er = command.get_output_list(ret)
        if er:
          raise Exception(er)
        if tl:
          err = ','.join(tl)
        tl, er = command.get_error_list(ret)
        if er:
          raise Exception(er)
        if tl:
          err = err + ','.join(tl)
        raise Exception("Return code : %d. Error : %s"%(rc, err))
      (ret, rc), err = command.execute_with_rc('service nmb reload')
      if err:
        raise Exception(err)
      if rc != 0:
        err = ''
        tl, er = command.get_output_list(ret)
        if er:
          raise Exception(er)
        if tl:
          err = ','.join(tl)
        tl, er = command.get_error_list(ret)
        if er:
          raise Exception(er)
        if tl:
          err = err + ','.join(tl)
        raise Exception("Return code : %d. Error : %s"%(rc, err))
  except Exception, e:
    return False, 'Error restarting samba services: %s'%str(e)
コード例 #7
0
def delete_local_user(username):

  try:
    if not username:
      raise Exception('No username specified')
    d, err = get_local_user(username)
    if not d:
      if err:
        raise Exception('Error locating user : %s'%err)
      else:
        raise Exception('Error locating user')

    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      client = salt.client.LocalClient()
      rc = client.cmd('*', 'user.delete', [username] )
      #print rc
      if rc:
        for hostname, status in rc.items():
          if not status:
            raise Exception("Error deleting the system user")
      else:
            raise Exception("Error deleting the system user")
    else:
      cmd_to_run = 'userdel  %s'%(username)
      lines, err = command.get_command_output(cmd_to_run)
      if err:
        raise Exception(err)

    if d['smb_user']:
      lines, err = command.get_command_output(r'pdbedit -d 1 -x %s'%username)
      if err:
        raise Exception(err)
    
  except Exception, e:
    return False, 'Error deleting local user : %s'%str(e)
コード例 #8
0
def delete_local_user(username):

  try:
    if not username:
      raise Exception('No username specified')
    d, err = get_local_user(username)
    if not d:
      if err:
        raise Exception('Error locating user : %s'%err)
      else:
        raise Exception('Error locating user')

    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      client = salt.client.LocalClient()
      rc = client.cmd('*', 'user.delete', [username] )
      #print rc
      if rc:
        for hostname, status in rc.items():
          if not status:
            raise Exception("Error deleting the system user")
      else:
            raise Exception("Error deleting the system user")
    else:
      cmd_to_run = 'userdel  %s'%(username)
      lines, err = command.get_command_output(cmd_to_run)
      if err:
        raise Exception(err)

    if d['smb_user']:
      lines, err = command.get_command_output(r'pdbedit -d 1 -x %s'%username)
      if err:
        raise Exception(err)
    
  except Exception, e:
    return False, 'Error deleting local user : %s'%str(e)
コード例 #9
0
def _reload_config():
  try:
    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      errors = ''
      client = salt.client.LocalClient()
      r1 = client.cmd('*', 'cmd.run_all', ['smbcontrol all reload-config'])
      if r1:
        for node, ret in r1.items():
          #print ret
          if ret["retcode"] != 0:
            errors += "Error reloading samba on node %s "%node
      if errors:
        raise Exception(errors)
    else:
      cmd_to_run = 'smbcontrol all reload-config'
      lines, err = command.get_command_output(cmd_to_run)
      if err:
        raise Exception(err)
  except Exception, e:
    return False, 'Error reloading CIFS configuration : %s'%str(e)
コード例 #10
0
def create_local_group(grpname, gid = None):
  try:
    #First check if groups exists. if so kick out
    gl, err = get_local_groups()
    if gl:
      for gd in gl:
        if gd["grpname"] == grpname:
          raise Exception("Error creating group. The group \"%s\" already exists. "%grpname)
    elif err:
      raise Exception("Error retrieving group list : %s"%err)

    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      client = salt.client.LocalClient()
      if not gid:
        rc = client.cmd('*', 'group.add', [grpname])
      else:
        rc = client.cmd('*', 'group.add', [grpname,gid])
      print rc
      if not rc:
        raise Exception('Group creation failed')
      for hostname, status in rc.items():
        if not status:
          raise Exception('Group creation failed')
    else:
      if gid:
        cmd_to_run = 'groupadd  -g %s %s'%(gid, grpname)
      else:
        cmd_to_run = 'groupadd   %s'%(grpname)
      lines, err = command.get_command_output(cmd_to_run)
      if err:
        raise Exception(err)
  except Exception, e:
    return False, 'Error creating a local group : %s'%str(e)
コード例 #11
0
def create_local_group(grpname, gid = None):
  try:
    #First check if groups exists. if so kick out
    gl, err = get_local_groups()
    if gl:
      for gd in gl:
        if gd["grpname"] == grpname:
          raise Exception("Error creating group. The group \"%s\" already exists. "%grpname)
    elif err:
      raise Exception("Error retrieving group list : %s"%err)

    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      client = salt.client.LocalClient()
      if not gid:
        rc = client.cmd('*', 'group.add', [grpname])
      else:
        rc = client.cmd('*', 'group.add', [grpname,gid])
      print rc
      if not rc:
        raise Exception('Group creation failed')
      for hostname, status in rc.items():
        if not status:
          raise Exception('Group creation failed')
    else:
      if gid:
        cmd_to_run = 'groupadd  -g %s %s'%(gid, grpname)
      else:
        cmd_to_run = 'groupadd   %s'%(grpname)
      lines, err = command.get_command_output(cmd_to_run)
      if err:
        raise Exception(err)
  except Exception, e:
    return False, 'Error creating a local group : %s'%str(e)
コード例 #12
0
def generate_status_info(path):
    status_dict = None
    try:
        pp = pprint.PrettyPrinter(indent=4)

        # First load the status
        fqdn = socket.getfqdn()
        use_salt, err = common.use_salt()
        if err:
            raise Exception(err)
        if use_salt:
            import salt.client
            local = salt.client.LocalClient()
            sd = local.cmd('*', 'integralstor.status')
        else:
            tmpsd, err = status()
            if err:
                raise Exception(err)
            sd = {}
            sd[fqdn] = tmpsd

        #pp.pprint(sd)
        if not sd:
            raise Exception('Did not get a response from salt')
        #pp.pprint(sd[fqdn]['interfaces'])

        # Load the manifest to check for discrepencies
        try:
            with open(path, 'r') as f:
                md = json.load(f)
        except Exception, e:
            raise Exception('Error reading the manifest file : %s' % str(e))
        #pp.pprint(md)

        status_dict = {}

        # Match the status against the manifest entries for discrepencies
        for hostname, manifest in md.items():
            #print hostname, len(hostname)
            temp_d = {}
            temp_d["errors"] = []
            node_status = 0
            #print sd.keys()

            if hostname not in sd.keys():
                node_status = -1
                #print "Not found in sd"
            else:
                if sd[hostname] and 'hardware_specific_dict' in sd[hostname]:
                    temp_d['hardware_specific_dict'] = sd[hostname][
                        'hardware_specific_dict']

                # Process disk information
                disks = {}
                for disk_sn, disk in manifest["disks"].items():
                    #print disk_sn
                    #print sd[hostname]['disks'].keys()
                    dd = {}
                    if disk_sn in sd[hostname]["disks"]:
                        dd["status"] = sd[hostname]["disks"][disk_sn]["status"]
                        if dd['status']:
                            if 'hw_raid' in disk and (not disk['hw_raid']):
                                if (dd["status"] not in ['PASSED', 'OK']):
                                    node_status = 1
                                    temp_d["errors"].append(
                                        "Disk with serial number %s is reporting SMART errors."
                                        % disk_sn)
                            elif dd["status"].lower() != 'ok':
                                node_status = 1
                                temp_d["errors"].append(
                                    "Disk with serial number %s has errors." %
                                    disk_sn)
                        dd["name"] = sd[hostname]["disks"][disk_sn]["name"]
                    else:
                        sd[hostname]['disks'][disk_sn] = disk
                        sd[hostname]['disks'][disk_sn][
                            'status'] = 'Disk missing'
                        dd["status"] = "Disk Missing"
                        node_status = 1
                        temp_d["errors"].append(
                            "Disk with serial number %s seems to be missing." %
                            disk_sn)
                    disks[disk_sn] = dd
                for td in sd[hostname]["disks"].keys():
                    new_disk = True
                    if td in manifest["disks"]:
                        new_disk = False
                        break
                    if new_disk:
                        temp_d["errors"].append(
                            "New disk detected. Disk with serial number %s  seems to be new."
                            % td)
                        node_status = 2
                #temp_d["disks"] = disks
                temp_d["disks"] = sd[hostname]['disks']
                #pp.pprint(temp_d['disks'])

                if sd[hostname]['services']:
                    for service_name, service_info in sd[hostname][
                            'services'].items():
                        if service_info[0] != 0:
                            temp_d['errors'].append(
                                'Service %s seems to have failed.' %
                                service_name)
                            node_status = 1
                    temp_d["services"] = sd[hostname]['services']

                # Process interface information
                interfaces = {}
                for ifname, ifdict in manifest["interfaces"].items():
                    #Check for all initially present interfaces
                    id = {}
                    if ifname in sd[hostname]["interfaces"]:
                        id, err = _convert_to_status_interface_dict(
                            sd[hostname]["interfaces"][ifname])
                        if err:
                            raise Exception(err)
                    else:
                        id["status"] = "Interface Missing"
                        node_status = 1
                        temp_d["errors"].append(
                            "Interface with number %s seems to be missing." %
                            ifname)
                    interfaces[ifname] = id
                for ifname, ifinfo in sd[hostname]["interfaces"].items():
                    #Check for all newly created interfaces - bonds, vlans, etc
                    #print 'ifname is ', ifname
                    if ifname not in manifest["interfaces"]:
                        id, err = _convert_to_status_interface_dict(
                            sd[hostname]["interfaces"][ifname])
                        if err:
                            raise Exception(err)
                        interfaces[ifname] = id
                temp_d["interfaces"] = interfaces

                for ifname, id in temp_d['interfaces'].items():
                    if ('ip_configured' in id
                            or 'slave_to' in id) and id["status"] != 'up':
                        node_status = 1
                        temp_d["errors"].append("Interface %s is not up." %
                                                ifname)

                #print 'interfaces are ', temp_d['interfaces']

                if "memory" in sd[hostname]:
                    if sd[hostname]["memory"]["mem_total"]["unit"] == "kB":
                        sd[hostname]["memory"]["mem_total"]["value"] = str(
                            int(sd[hostname]["memory"]["mem_total"]["value"]) /
                            1024)
                        sd[hostname]["memory"]["mem_total"]["unit"] = "MB"
                    if sd[hostname]["memory"]["mem_free"]["unit"] == "kB":
                        sd[hostname]["memory"]["mem_free"]["value"] = str(
                            int(sd[hostname]["memory"]["mem_free"]["value"]) /
                            1024)
                        sd[hostname]["memory"]["mem_free"]["unit"] = "MB"
                    temp_d["memory"] = sd[hostname]["memory"]
                if "disk_usage" in sd[hostname]:
                    temp_d["disk_usage"] = sd[hostname]["disk_usage"]
                if "pools" in sd[hostname]:
                    temp_d["pools"] = sd[hostname]["pools"]
                if "load_avg" in sd[hostname]:
                    # To get around a django quirk of not recognising hyphens in dicts
                    sd[hostname]["load_avg"]["15_min"] = sd[hostname][
                        "load_avg"]["15-min"]
                    sd[hostname]["load_avg"]["5_min"] = sd[hostname][
                        "load_avg"]["5-min"]
                    sd[hostname]["load_avg"]["1_min"] = sd[hostname][
                        "load_avg"]["1-min"]
                    sd[hostname]["load_avg"].pop("15-min", None)
                    sd[hostname]["load_avg"].pop("5-min", None)
                    sd[hostname]["load_avg"].pop("1-min", None)
                    temp_d["load_avg"] = sd[hostname]["load_avg"]

                if "cpu_model" in manifest:
                    temp_d["cpu_model"] = manifest["cpu_model"]

                if "fqdn" in manifest:
                    temp_d["fqdn"] = manifest["fqdn"]

                if 'ipmi_status' in sd[hostname]:
                    temp_d["ipmi_status"] = sd[hostname]["ipmi_status"]

                if temp_d["load_avg"]['15_min'] >= temp_d["load_avg"][
                        'cpu_cores']:
                    temp_d["errors"].append(
                        "The 15-minute load average (%.2f) has been high." %
                        temp_d["load_avg"]['15_min'])
                    node_status = "Degraded"
                if temp_d["load_avg"]['5_min'] >= temp_d["load_avg"][
                        'cpu_cores']:
                    temp_d["errors"].append(
                        "The 5-minute load average (%.2f) has been high." %
                        temp_d["load_avg"]['5_min'])

                if 'ipmi_status' in temp_d:
                    for status_item in temp_d['ipmi_status']:
                        if status_item["status"] not in ['ok', 'nr']:
                            temp_d["errors"].append(
                                'The %s of the %s is reporting errors' %
                                (status_item["parameter_name"],
                                 status_item["component_name"]))

                pools = temp_d["pools"]
                component_status_dict, err = zfs.get_all_components_status(
                    pools)
                if err:
                    raise Exception(err)
                if component_status_dict:
                    for pool_name, component_status_list in component_status_dict.items(
                    ):
                        msg = None
                        for component in component_status_list:
                            if 'status' in component and 'state' in component[
                                    'status'] and component['status'][
                                        'state'] != 'ONLINE':
                                if not msg:
                                    msg = "The ZFS pool '%s' has the following issue(s) : " % pool_name
                                msg += "The component %s of type '%s' has a state of '%s'. " % (
                                    component['name'], component['type'],
                                    component['status']['state'])
                        if msg:
                            temp_d['errors'].append(msg)

                temp_d['zfs_version'] = sd[hostname]['zfs_version']
                temp_d['os_version'] = sd[hostname]['os_version']

            temp_d["node_status"] = node_status
            if node_status == 0:
                temp_d["node_status_str"] = "Healthy"
            elif node_status == 1:
                temp_d["node_status_str"] = "Degraded"
            elif node_status == 2:
                temp_d["node_status_str"] = "New on-node hardware detected"
            elif node_status == -1:
                temp_d["node_status_str"] = "No response. Down?"
                temp_d['errors'].append('Node %s seems to be down' % hostname)

            status_dict[hostname] = temp_d
コード例 #13
0
def dashboard(request,page):
  return_dict = {}
  try:
    if request.method != 'GET':
      raise Exception('Invalid access method. Please use the menus')
    si, err = system_info.load_system_config()
    if err:
      raise Exception(err)
    if not si:
      raise Exception('Error loading system configuration')
    return_dict['system_info'] = si
    #By default show error page
    template = "logged_in_error.html"
    num_nodes_bad = 0
    total_pool = 0
    total_nodes = len(si)
    nodes = {}
    # Chart specific declarations
    today_day = (datetime.date.today()).strftime('%d') # will return 02, instead of 2.
    #today_day = datetime.datetime.today().day
    #if today_day < 10:
    #  today_day = '0%d'%today_day
    value_list = []
    time_list = []
    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
        
    ks = si.keys()
    if not ks:
      raise Exception('System configuration invalid')
    info = ks[0]
    # CPU status
    if page == "cpu":
      return_dict["page_title"] = 'CPU statistics'
      return_dict['tab'] = 'cpu_tab'
      return_dict["error"] = 'Error loading CPU statistics'
      cpu,err = stats.get_system_stats(today_day,"cpu")
      if err:
        raise Exception(err)
      value_dict = {}
      if cpu:
        for key in cpu.keys():
          value_list = []
          time_list = []
          if key == "date":
            pass
          else:
            if cpu[key]:
              for a in cpu[key]:
                time_list.append(a[0])
                value_list.append(a[1])
            value_dict[key] = value_list
      return_dict["data_dict"] = value_dict
      queue,err = stats.get_system_stats(today_day,"queue")
      if err:
        raise Exception(err)
      value_dict = {}
      if queue:
        for key in queue.keys():
          value_list = []
          time_list = []
          if key == "date":
            pass
          else:
            for a in queue[key]:
              time_list.append(a[0])
              value_list.append(a[1])
            value_dict[key] = value_list
      return_dict["data_dict_queue"] = value_dict
      return_dict['node_name'] = info
      return_dict['node'] = si[info]
      d = {}
      template = "view_cpu_status.html"
    # Hardware
    elif page == "hardware":
      return_dict["page_title"] = 'Hardware status'
      return_dict['tab'] = 'hardware_tab'
      return_dict["error"] = 'Error loading hardware status'
      d = {}
      d['ipmi_status'] = si[info]['ipmi_status']
      return_dict['hardware_status'] =  d
      return_dict['node_name'] = info
      template = "view_hardware_status.html"
    # Memory
    elif page == "memory":
      return_dict["page_title"] = 'Memory statistics'
      return_dict['tab'] = 'memory_tab'
      return_dict["error"] = 'Error loading memory statistics'
      mem,err = stats.get_system_stats(today_day,"memory")
      if err:
        raise Exception(err)
      if mem:
        for a in mem["memfree"]:
          time_list.append(a[0])
          value_list.append(a[1])
      return_dict['memory_status'] =  si[info]['memory']
      template = "view_memory_status.html"
    # Network
    elif page == "network":
      return_dict["page_title"] = 'Network statistics'
      return_dict['tab'] = 'network_tab'
      return_dict["error"] = 'Error loading Network statistics'
      network,err = stats.get_system_stats(today_day,"network")
      if err:
        raise Exception(err)
      value_dict = {}
      if network:
        for key in network.keys():
          value_list = []
          time_list = []
          if key == "date" or key == "lo":
            pass
          else:
            for a in network[key]["ifutil-percent"]:
              time_list.append(a[0])
              value_list.append(a[1])
            value_dict[key] = value_list
          
      return_dict["data_dict"] = value_dict
      print si[info]["interfaces"]
      return_dict["network_status"] = si[info]['interfaces']
      template = "view_network_status.html"
    # Services
    elif page == "services":
      return_dict["page_title"] = 'System services status'
      return_dict['tab'] = 'services_tab'
      return_dict["error"] = 'Error loading system services status'
      return_dict['services_status'] = {}
      if use_salt:
        import salt.client
        client = salt.client.LocalClient()
        winbind = client.cmd(info,'cmd.run',['service winbind status'])
        smb = client.cmd(info,'cmd.run',['service smb status'])
        nfs = client.cmd(info,'cmd.run',['service nfs status'])
        iscsi = client.cmd(info,'cmd.run',['service tgtd status'])
        ntp = client.cmd(info,'cmd.run',['service ntpd status'])
        return_dict['services_status']['winbind'] = winbind[info]
        return_dict['services_status']['smb'] = smb[info]
        return_dict['services_status']['nfs'] = nfs[info]
        return_dict['services_status']['iscsi'] = iscsi[info]
        return_dict['services_status']['ntp'] = ntp[info]
      else:
        out_list, err = command.get_command_output('service winbind status', False)
        if err:
          raise Exception(err)
        if out_list:
          return_dict['services_status']['winbind'] = ' '.join(out_list)
  
        out_list, err = command.get_command_output('service smb status', False)
        if err:
          raise Exception(err)
        if out_list:
          return_dict['services_status']['smb'] = ' '.join(out_list)
  
        out_list, err = command.get_command_output('service nfs status', False)
        if err:
          raise Exception(err)
        if out_list:
          return_dict['services_status']['nfs'] = ' '.join(out_list)
  
        out_list, err = command.get_command_output('service tgtd status', False)
        if err:
          raise Exception(err)
        if out_list:
          return_dict['services_status']['iscsi'] = ' '.join(out_list)
  
        out_list, err = command.get_command_output('service ntpd status', False)
        if err:
          raise Exception(err)
        if out_list:
          return_dict['services_status']['ntp'] = ' '.join(out_list)
          
      template = "view_services_status.html"
    # Disks
    elif page == "disks":
      return_dict["page_title"] = 'Hard drives status'
      return_dict['tab'] = 'disk_tab'
      return_dict["error"] = 'Error loading hard drives status'
      sorted_disks = []
      if 'disks' in si[info] and si[info]['disks']:
        for key,value in sorted(si[info]["disks"].iteritems(), key=lambda (k,v):v["position"]):
          sorted_disks.append(key)
      return_dict['node'] = si[info]
      return_dict["disk_status"] = si[info]['disks']
      return_dict["disk_pos"] = sorted_disks
      return_dict['node_name'] = info
      template = "view_disks_status.html"
    # Pools
    elif page == "pools":
      return_dict["page_title"] = 'ZFS pools status'
      return_dict['tab'] = 'pools_tab'
      return_dict["error"] = 'Error loading ZFS pools status'
      pools, err = zfs.get_pools()
      if err:
        raise Exception(err)
      if pools:
        return_dict['pools'] = pools            
      template = "view_pools_status.html"
    return_dict["labels"] = time_list
    return_dict["data"] = value_list
    return django.shortcuts.render_to_response(template, return_dict, context_instance=django.template.context.RequestContext(request))
  except Exception, e:
    return_dict['base_template'] = "dashboard_base.html"
    return_dict["error_details"] = str(e)
    return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
コード例 #14
0
def dashboard(request, page):
    return_dict = {}

    try:
        return_dict["page_title"] = 'Overall system health'
        return_dict['tab'] = 'system_health_tab'
        return_dict["error"] = 'Error loading system health data'

        if request.method != 'GET':
            raise Exception('Invalid access method. Please use the menus')
        si, err = system_info.load_system_config()
        if err:
            raise Exception(err)
        if not si:
            raise Exception('Error loading system configuration')

        node = si[si.keys()[0]]
        return_dict['node'] = node
        #print node.keys()

        #By default show error page
        template = "logged_in_error.html"

        # Chart specific declarations
        todays_date = (datetime.date.today()).strftime(
            '%02d')  # will return 02, instead of 2.
        start_hour = '%02d' % (datetime.datetime.today().hour - 3)
        end_hour = '%02d' % (datetime.datetime.today().hour)
        minute = '%02d' % (datetime.datetime.today().minute)
        start = str(start_hour) + ":" + str(minute) + str(":10")
        end = str(end_hour) + ":" + str(minute) + str(":40")

        value_list = []
        time_list = []
        use_salt, err = common.use_salt()
        if err:
            raise Exception(err)

        num_bad_disks = 0
        num_hw_raid_bad_disks = 0
        num_hw_raid_ctrl_disks = 0
        num_smart_ctrl_disks = 0
        num_disks = len(node['disks'])
        disks_ok = True
        disks_hw_ok = "N.A"
        for sn, disk in node['disks'].items():
            if 'status' in disk:
                if 'hw_raid' in disk:
                    if not disk['hw_raid']:
                        num_smart_ctrl_disks += 1
                        if (disk['status'] is not None
                                and disk['status'].upper()
                                not in ['PASSED', 'OK']):
                            num_bad_disks += 1
                            disks_ok = False
                    else:
                        num_hw_raid_ctrl_disks += 1
                        if (disk['status'] is not None
                                and disk['status'].upper() != 'OK'):
                            num_hw_raid_bad_disks += 1
                            disks_ok = False
                else:
                    #Assume its a non raid disk
                    num_smart_ctrl_disks += 1
                    if (disk['status'] is not None and disk['status'].upper()
                            not in ['PASSED', 'OK']):
                        num_bad_disks += 1
                        disks_ok = False

        return_dict['num_disks'] = num_disks
        return_dict['num_bad_disks'] = num_bad_disks
        return_dict['disks_ok'] = disks_ok
        #return_dict['disks_hw_ok'] = disks_hw_ok
        return_dict['num_hw_raid_bad_disks'] = num_hw_raid_bad_disks
        return_dict['num_hw_raid_ctrl_disks'] = num_hw_raid_ctrl_disks
        return_dict['num_smart_ctrl_disks'] = num_smart_ctrl_disks

        if 'ipmi_status' in node:
            num_sensors = len(node['ipmi_status'])
            num_bad_sensors = 0
            ipmi_ok = True
            for sensor in node['ipmi_status']:
                if sensor['status'] in ['ok', 'nr', 'na']:
                    continue
                else:
                    num_bad_sensors += 1
                    ipmi_ok = False
            return_dict['num_sensors'] = num_sensors
            return_dict['num_bad_sensors'] = num_bad_sensors
            return_dict['ipmi_ok'] = ipmi_ok

        #services_list =  ['winbind', 'smb', 'nfs', 'tgtd', 'ntpd', 'vsftpd']

        services_dict, err = services_management.get_sysd_services_status()
        if err:
            raise Exception(err)
        num_services = len(services_dict)
        num_failed_services = 0
        num_active_services = 0
        num_inactive_services = 0
        services_ok = True

        if services_dict:
            #service = services_dict.keys ()
            for service in services_dict.keys():
                if services_dict[service]["info"]["status"][
                        "status_str"] == "Active":
                    num_active_services += 1
                elif services_dict[service]["info"]["status"][
                        "status_str"] == "Inactive":
                    num_inactive_services += 1
                elif services_dict[service]["info"]["status"][
                        "status_str"] == "Failed":
                    num_failed_services += 1
                    services_ok = False
                elif services_dict[service]["info"]["status"][
                        "status_str"] == "Unknown State":
                    num_failed_services += 1
                    services_ok = False
            return_dict['num_services'] = num_services
            return_dict['num_active_services'] = num_active_services
            return_dict['num_inactive_services'] = num_inactive_services
            return_dict['num_failed_services'] = num_failed_services
            return_dict['services_ok'] = services_ok
        else:
            raise Exception('Fetched services status list is empty')

        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)

        info = si.keys()[0]
        num_pools = len(pools)
        num_bad_pools = 0
        num_degraded_pools = 0
        num_high_usage = 0
        for pool in pools:
            if pool['usage']['capacity']['value'] > 75:
                num_high_usage += 1
            if pool['config']['pool']['root']['status']['state'] == 'ONLINE':
                pass
            elif pool['config']['pool']['root']['status'][
                    'state'] == 'DEGRADED':
                num_degraded_pools += 1
            else:
                num_bad_pools += 1
        return_dict['num_pools'] = num_pools
        return_dict['num_bad_pools'] = num_bad_pools
        return_dict['num_degraded_pools'] = num_degraded_pools
        return_dict['num_high_usage'] = num_high_usage

        load_avg_ok = True
        if (node["load_avg"]["5_min"] > node["load_avg"]["cpu_cores"]) or (
                node["load_avg"]["15_min"] > node["load_avg"]["cpu_cores"]):
            load_avg_ok = False
        return_dict['load_avg_ok'] = load_avg_ok

        shares_list, err = cifs_common.load_shares_list()
        if err:
            raise Exception(err)
        return_dict['num_cifs_shares'] = len(shares_list)

        exports_list, err = nfs.load_exports_list()
        if err:
            raise Exception(err)
        return_dict['num_nfs_exports'] = len(exports_list)

        target_list, err = iscsi_stgt.get_targets()
        if err:
            raise Exception(err)
        return_dict['num_iscsi_targets'] = len(target_list)

        with open('/proc/uptime', 'r') as f:
            uptime_seconds = float(f.readline().split()[0])
            uptime_str = '%s hours' % (':'.join(
                str(timedelta(seconds=uptime_seconds)).split(':')[:2]))
            return_dict['uptime_str'] = uptime_str

        # CPU status
        if page == "cpu":
            return_dict["page_title"] = 'CPU statistics'
            return_dict['tab'] = 'cpu_tab'
            return_dict["error"] = 'Error loading CPU statistics'
            cpu, err = stats.get_system_stats(todays_date, start, end, "cpu")
            if err:
                raise Exception(err)
            value_dict = {}
            if cpu:
                for key in cpu.keys():
                    value_list = []
                    time_list = []
                    if key == "date":
                        pass
                    else:
                        if cpu[key]:
                            for a in cpu[key]:
                                time_list.append(a[0])
                                value_list.append(a[1])
                        value_dict[key] = value_list
            return_dict["data_dict"] = value_dict
            queue, err = stats.get_system_stats(todays_date, start, end,
                                                "queue")
            if err:
                raise Exception(err)
            value_dict = {}
            if queue:
                for key in queue.keys():
                    value_list = []
                    time_list = []
                    if key == "date":
                        pass
                    else:
                        for a in queue[key]:
                            time_list.append(a[0])
                            value_list.append(a[1])
                        value_dict[key] = value_list
            return_dict["data_dict_queue"] = value_dict
            return_dict['node_name'] = info
            return_dict['node'] = si[info]
            d = {}
            template = "view_cpu_status.html"
        elif page == "dashboard":
            return_dict["page_title"] = 'Overall system health'
            return_dict['tab'] = 'system_health_tab'
            return_dict["error"] = 'Error loading system health data'
            template = "dashboard_system_health.html"
            hw_platform, err = common.get_hardware_platform()
            if hw_platform:
                return_dict['hw_platform'] = hw_platform
                if hw_platform == 'dell':
                    from integralstor_common.platforms import dell
                    idrac_url, err = dell.get_idrac_addr()
                    if idrac_url:
                        return_dict['idrac_url'] = idrac_url
        # Hardware
        elif page == "hardware":
            return_dict["page_title"] = 'Hardware status'
            return_dict['tab'] = 'hardware_tab'
            return_dict["error"] = 'Error loading hardware status'
            d = {}
            if 'ipmi_status' in si[info]:
                d['ipmi_status'] = si[info]['ipmi_status']
                return_dict['hardware_status'] = d
            return_dict['node_name'] = info
            template = "view_hardware_status.html"
        # Memory
        elif page == "memory":
            return_dict["page_title"] = 'Memory statistics'
            return_dict['tab'] = 'memory_tab'
            return_dict["error"] = 'Error loading memory statistics'
            mem, err = stats.get_system_stats(todays_date, start, end,
                                              "memory")
            if err:
                raise Exception(err)
            if mem:
                for a in mem["memused"]:
                    time_list.append(a[0])
                    value_list.append((a[1] / (1024 * 1024)))
            return_dict['memory_status'] = si[info]['memory']
            template = "view_memory_status.html"
        # Network
        elif page == "network":
            return_dict["page_title"] = 'Network statistics'
            return_dict['tab'] = 'network_tab'
            return_dict["error"] = 'Error loading Network statistics'
            network, err = stats.get_system_stats(todays_date, start, end,
                                                  "network")
            if err:
                raise Exception(err)
            value_dict = {}
            if network:
                for key in network.keys():
                    value_list = []
                    time_list = []
                    if key == "date" or key == "lo":
                        pass
                    else:
                        for a in network[key]["ifutil-percent"]:
                            time_list.append(a[0])
                            value_list.append(a[1])
                        value_dict[key] = value_list

            return_dict["data_dict"] = value_dict
            return_dict["network_status"] = si[info]['interfaces']
            template = "view_network_status.html"
        # Services
        elif page == "services":
            return_dict["page_title"] = 'System services status'
            return_dict['tab'] = 'services_tab'
            return_dict["error"] = 'Error loading system services status'
            return_dict['services_status'] = {}
            if use_salt:
                import salt.client
                client = salt.client.LocalClient()
                winbind = client.cmd(info, 'cmd.run',
                                     ['service winbind status'])
                smb = client.cmd(info, 'cmd.run', ['service smb status'])
                nfss = client.cmd(info, 'cmd.run', ['service nfs status'])
                iscsi = client.cmd(info, 'cmd.run', ['service tgtd status'])
                ntp = client.cmd(info, 'cmd.run', ['service ntpd status'])
                ftp = client.cmd(info, 'cmd.run', ['service vsftpd status'])
                return_dict['services_status']['winbind'] = winbind[info]
                return_dict['services_status']['smb'] = smb[info]
                return_dict['services_status']['nfs'] = nfss[info]
                return_dict['services_status']['iscsi'] = iscsi[info]
                return_dict['services_status']['ntp'] = ntp[info]
                return_dict['services_status']['ftp'] = ftp[info]
            else:
                """
        services_list, err = services_management.get_sysd_services_status ()
        if err:
          raise Exception (err)
        if services_list:
          #for service in services_list:
          return_dict['services_status'] = services_list  
        else:
          raise Exception ('Fetched services status list is empty')
        """

                out_list, err = command.get_command_output(
                    'service winbind status', False)
                if err:
                    raise Exception(err)
                if out_list:
                    return_dict['services_status']['winbind'] = ' '.join(
                        out_list)

                out_list, err = command.get_command_output(
                    'service smb status', False)
                if err:
                    raise Exception(err)
                if out_list:
                    return_dict['services_status']['smb'] = ' '.join(out_list)

                out_list, err = command.get_command_output(
                    'service nfs status', False)
                if err:
                    raise Exception(err)
                if out_list:
                    return_dict['services_status']['nfs'] = ' '.join(out_list)

                out_list, err = command.get_command_output(
                    'service tgtd status', False)
                if err:
                    raise Exception(err)
                if out_list:
                    return_dict['services_status']['iscsi'] = ' '.join(
                        out_list)

                out_list, err = command.get_command_output(
                    'service ntpd status', False)
                if err:
                    raise Exception(err)
                if out_list:
                    return_dict['services_status']['ntp'] = ' '.join(out_list)

                out_list, err = command.get_command_output(
                    'service vsftpd status', False)
                if err:
                    raise Exception(err)
                if out_list:
                    return_dict['services_status']['ftp'] = ' '.join(out_list)

            template = "view_services_status.html"
        # Disks
        elif page == "disks":
            return_dict["page_title"] = 'Hard drives status'
            return_dict['tab'] = 'disk_tab'
            return_dict["error"] = 'Error loading hard drives status'
            return_dict['node'] = si[info]
            return_dict["disk_status"] = si[info]['disks']
            #print si[info]['disks']
            return_dict['node_name'] = info
            template = "view_disks_status.html"
        # Pools
        elif page == "pools":
            return_dict["page_title"] = 'ZFS pools status'
            return_dict['tab'] = 'pools_tab'
            return_dict["error"] = 'Error loading ZFS pools status'
            pools, err = zfs.get_pools()
            if err:
                raise Exception(err)
            if pools:
                return_dict['pools'] = pools
            template = "view_pools_status.html"
        return_dict["labels"] = time_list
        return_dict["data"] = value_list
        return django.shortcuts.render_to_response(
            template,
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "dashboard_base.html"

        return_dict["error_details"] = e
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
コード例 #15
0
def display_status():

  try :
    hostname = socket.gethostname()
    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      print "Salt master service status :",
      (r, rc), err = command.execute_with_rc('service salt-master status')
      if err:
        raise Exception(err)
      l, err = command.get_output_list(r)
      if err:
        raise Exception(err)
      if l:
        print '\n'.join(l)
      else:
        l, err = command.get_error_list(r)
        if err:
          raise Exception(err)
        if l:
          print '\n'.join(l)
      print "Salt minion service status :",
      (r, rc), err = command.execute_with_rc('service salt-minion status')
      if err:
        raise Exception(err)
      l, err = command.get_output_list(r)
      if err:
        raise Exception(err)
      if l:
        print '\n'.join(l)
      else:
        l, err = command.get_error_list(r)
        if err:
          raise Exception(err)
        print l
        if l:
          print '\n'.join(l)
    print "Samba service status :",
    (r, rc), err = command.execute_with_rc('service smb status')
    if err:
      raise Exception(err)
    l, err = command.get_output_list(r)
    if err:
      raise Exception(err)
    if l:
      print '\n'.join(l)
    else:
      l, err = command.get_error_list(r)
      if err:
        raise Exception(err)
      if l:
        print '\n'.join(l)
    print "Winbind service status :",
    (r, rc), err = command.execute_with_rc('service winbind status')
    if err:
      raise Exception(err)
    l, err = command.get_output_list(r)
    if err:
      raise Exception(err)
    if l:
      print '\n'.join(l)
    else:
      l, err = command.get_error_list(r)
      if err:
        raise Exception(err)
      if l:
        print '\n'.join(l)
  except Exception, e:
    print "Error displaying system status : %s"%e
    return -1
コード例 #16
0
def create_local_user(username, name, pswd, gid = None, smb_user=True):

  try:

    #First check if user exists. if so kick out
    ul, err = get_local_users()
    if ul:
      for ud in ul:
        if ud["username"] == username:
          raise Exception("Error creating user. The user \"%s\" already exists. "%username)
    elif err:
      raise Exception("Error retrieving user list : %s"%err)

  
    enc_pswd = crypt.crypt(pswd, "28")
    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      client = salt.client.LocalClient()
      if gid:
        rc = client.cmd('*', 'user.add', [username, None, gid])
      else:
        rc = client.cmd('*', 'user.add', [username])
      #print rc
      if not rc:
        error_list.append("Error creating the username")
      for hostname, status in rc.items():
        if not status:
          error_list.append("Error creating the username on node"%hostname)
      rc = client.cmd('*', 'shadow.set_password', [username, enc_pswd] )
      for hostname, status in rc.items():
        if not status:
          error_list.append("Error setting the password for username on GRIDCell %s"%hostname)
      rc = client.cmd('*', 'user.chfullname', [username, "integralstor_user_%s"%name] )
      for hostname, status in rc.items():
        if not status:
          error_list.append("Error setting the name for username on node %s"%hostname)
    else:
      #print '1'
      if gid:
        cmd_to_run = 'useradd -g %s -p %s -c integralstor_user_%s %s'%(gid, enc_pswd, name, username)
      else:
        cmd_to_run = 'useradd  -p %s -c integralstor_user_%s %s'%(enc_pswd, name, username)
      lines, err = command.get_command_output(cmd_to_run)
      #print '2'
      #print lines, err
      if err:
        raise Exception(err)
  
    if smb_user:
      #print '/usr/bin/pdbedit  -d 1 -t -a  -u %s -f %s'%(username, name), "%s\n%s"%(pswd, pswd)
      # Now all set to create samba user
      #print '3'
      #lines, err = command.get_command_output(r'/usr/bin/pdbedit  -d 1 -t -a  -u %s -f %s'%(username, name), "%s\n%s"%(pswd, pswd))
      (ret, rc), err = command.execute_with_conf_and_rc(r'/usr/bin/pdbedit  -d 1 -t -a  -u %s -f %s'%(username, name), "%s\n%s"%(pswd, pswd))
      if rc == 0:
        lines, er = command.get_output_list(ret)
        if er:
          raise Exception(er)
      else:
        err = ''
        tl, er = command.get_output_list(ret)
        if er:
          raise Exception(er)
        if tl:
          err = ','.join(tl)
        tl, er = command.get_error_list(ret)
        if er:
          raise Exception(er)
        if tl:
          err = err + ','.join(tl)
        raise Exception(err)
      #print '4'
      #print lines, err
  except Exception, e:
    return False, 'Error creating local user : %s'%str(e)
コード例 #17
0
def download_sys_log(request):
  """ Download the system log of the type specified in sys_log_type POST param for the node specified in the hostname POST parameter. 
  This calls the /sys_log via an http request on that node to get the info"""

  return_dict = {}
  try:
    scl, err = system_info.load_system_config()
    if err:
      raise Exception(err)
    form = log_management_forms.SystemLogsForm(request.POST or None, system_config_list = scl)
  
    if request.method == 'POST':
      if form.is_valid():
        cd = form.cleaned_data
        sys_log_type = cd['sys_log_type']
        hostname = cd["hostname"]
  
        iv_logging.debug("Got sys log download request for type %s hostname %s"%(sys_log_type, hostname))
  
        fn = {'boot':'/var/log/boot.log', 'dmesg':'/var/log/dmesg', 'message':'/var/log/messages', 'smb':'/var/log/smblog.vfs', 'winbind':'/var/log/samba/log.winbindd','ctdb':'/var/log/log.ctdb'}
        dn = {'boot':'boot.log', 'dmesg':'dmesg', 'message':'messages','smb':'samba_logs','winbind':'winbind_logs','ctdb':'ctdb_logs'}
  
        file_name = fn[sys_log_type]
        display_name = dn[sys_log_type]
  
        import os

        use_salt, err = common.use_salt()
        if err:
          raise Exception(err)
        if use_salt:
          import salt.client
          client = salt.client.LocalClient()
          ret = client.cmd('%s'%(hostname),'cp.push',[file_name])
  
        # This has been maintained for reference purposes.
        # dt = datetime.datetime.now()
        # dt_str = dt.strftime("%d%m%Y%H%M%S")
  
        # lfn = "/tmp/%s_%s"%(sys_log_type, dt_str)
        # cmd = "/opt/fractal/bin/client %s get_file %s %s"%(hostname, file_name, lfn)
        # print "command is "+cmd
  
        # try :
        #   ret, rc = command.execute_with_rc(cmd)
        # except Exception, e:
        #   return_dict["error"] = "Error retrieving remote log file : %s"%e
        #   return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request))
  
        # if rc != 0 :
        #   return_dict["error"] = "Error retrieving remote log file. Retrieval returned an error code of %d"%rc
        #   return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request))
  
        zf_name = '%s.zip'%display_name
  
        try:
          zf = zipfile.ZipFile(zf_name, 'w')
          if use_salt:
            zf.write("/var/cache/salt/master/minions/%s/files/%s"%(hostname,file_name), arcname = display_name)
          else:
            zf.write(file_name, arcname = display_name)
          zf.close()
        except Exception as e:
          raise Exception("Error compressing remote log file : %s"%str(e))
  
        try:
          response = django.http.HttpResponse()
          response['Content-disposition'] = 'attachment; filename=%s.zip'%(display_name)
          response['Content-type'] = 'application/x-compressed'
          with open(zf_name, 'rb') as f:
            byte = f.read(1)
            while byte:
              response.write(byte)
              byte = f.read(1)
          response.flush()
        except Exception as e:
          return None
  
        return response
  
    # either a get or an invalid form so send back form
    return_dict['form'] = form
    return django.shortcuts.render_to_response('download_sys_log_form.html', return_dict, context_instance=django.template.context.RequestContext(request))
  except Exception, e:
    return_dict['base_template'] = "logging_base.html"
    return_dict["page_title"] = 'Download system logs'
    return_dict['tab'] = 'download_system_logs_tab'
    return_dict["error"] = 'Error downloading system logs'
    return_dict["error_details"] = str(e)
    return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
コード例 #18
0
def generate_manifest_info():
    manifest_dict = {}
    try:
        #pp = pprint.PrettyPrinter(indent=4)

        use_salt, err = common.use_salt()
        if err:
            raise Exception(err)
        fqdn = socket.getfqdn()
        if use_salt:
            import salt.modules.network, salt.modules.ps, salt.modules.status, salt.client, salt.wheel, salt.config
            local = salt.client.LocalClient()

            cfg, err = common.get_salt_master_config()
            if err:
                raise Exception(err)
            opts = salt.config.master_config(cfg)
            wheel = salt.wheel.Wheel(opts)
            keys = wheel.call_func('key.list_all')
            if not keys:
                raise Exception('No GRIDCells found!')
            nodes = keys['minions']
            #print nodes
            for node in nodes:
                manifest_dict[node] = {}

            roles = local.cmd('*', 'grains.item', ['roles'])
            for node, info in roles.items():
                if node not in manifest_dict:
                    manifest_dict[node] = {}
                manifest_dict[node]['roles'] = info['roles']
            ret = local.cmd('*', 'integralstor.status')
            for node, info in ret.items():
                if node not in manifest_dict:
                    manifest_dict[node] = {}
                manifest_dict[node]['cpu_model'] = info['cpu_model']
                manifest_dict[node]['disks'] = info['disks']
                for dn, dv in manifest_dict[node]['disks'].items():
                    if 'pool' in dv:
                        dv.pop('pool')
                manifest_dict[node]['interfaces'] = info['interfaces']
                manifest_dict[node]['memory'] = info['memory']
                manifest_dict[node]['fqdn'] = info['fqdn']
                if 'hardware_specific_dict' in info:
                    manifest_dict[node]['hardware_specific_dict'] = info[
                        'hardware_specific_dict']
        else:
            # Single node so get the info using a direct call and just bung it into the fqdn key!
            manifest_dict[fqdn] = {}
            status_dict, err = status()
            if err:
                raise Exception(err)
            manifest_dict[fqdn]['cpu_model'] = status_dict['cpu_model']
            manifest_dict[fqdn]['disks'] = status_dict['disks']
            for dn, dv in manifest_dict[fqdn]['disks'].items():
                if 'pool' in dv:
                    dv.pop('pool')
            manifest_dict[fqdn]['interfaces'] = status_dict['interfaces']
            manifest_dict[fqdn]['memory'] = status_dict['memory']
            manifest_dict[fqdn]['fqdn'] = fqdn

        #Remove transitory info and only keep the actual hardware info
        for node in manifest_dict.keys():
            if 'interfaces' in manifest_dict[node]:
                for int_name, interface in manifest_dict[node][
                        'interfaces'].items():
                    if 'up' in interface:
                        interface.pop('up')
                    if 'inet' in interface:
                        interface.pop('inet')
            if 'disks' in manifest_dict[node]:
                for disk_name, diskinfo in manifest_dict[node]['disks'].items(
                ):
                    if 'status' in diskinfo:
                        diskinfo.pop('status')
            if 'memory' in manifest_dict[node]:
                if 'mem_free' in manifest_dict[node]['memory']:
                    manifest_dict[node]['memory'].pop('mem_free')

        if not manifest_dict:
            raise Exception('Error getting manifest information')

    except Exception, e:
        return None, 'Error generating the manifest dictionary : %s' % str(e)
コード例 #19
0
def configure_interface():

  try :
    os.system('clear')
    interfaces, err = networking.get_interfaces()
    if err:
      raise Exception('Error retrieving interface information : %s'%err)
    if not interfaces:
      raise Exception('No interfaces detected')
    print
    print
    print 'Integralstor Unicell interface configuration'
    print '--------------------------------------------'
    print
    print
    print 'Current network interfaces : '
    print
    for if_name, iface in interfaces.items():
      if if_name.startswith('lo'):
        continue
      print '- %s'%if_name
    print
    
    valid_input = False
    while not valid_input:
      ifname = raw_input('Enter the name of the interface that you wish to configure : ')
      if ifname not in interfaces or ifname.startswith('lo'):
        print 'Invalid interface name'
      else:
        valid_input = True
    print
    ip_info, err = networking.get_ip_info(ifname)
    '''
    if err:
      raise Exception('Error retrieving interface information : %s'%err)
    '''
    if ip_info:
      ip = ip_info["ipaddr"]
      netmask = ip_info["netmask"]
    else:
      ip = None
      netmask = None
    #print ip_info
    old_boot_proto, err = networking.get_interface_bootproto(ifname)
    if err:
      raise Exception('Error retrieving interface information : %s'%err)
    



    config_changed = False

    str_to_print = "Configure for DHCP or static addressing (dhcp/static)? : "
    valid_input = False
    while not valid_input :
      input = raw_input(str_to_print)
      if input:
        if input.lower() in ['static', 'dhcp']:
          valid_input = True
          boot_proto = input.lower()
          if boot_proto != old_boot_proto:
            config_changed = True
      if not valid_input:
        print "Invalid value. Please try again."
    print


    if boot_proto == 'static':
      if ip:
        str_to_print = "Enter IP address (currently %s, press enter to retain current value) : "%ip
      else:
        str_to_print = "Enter IP address (currently not set) : "
      valid_input = False
      while not valid_input :
        input = raw_input(str_to_print)
        if input:
          ok, err = networking.validate_ip(input)
          if err:
            raise Exception('Error validating IP : %s'%err)
          if ok:
            valid_input = True
            ip = input
            config_changed = True
        elif ip:
          valid_input = True
        if not valid_input:
          print "Invalid value. Please try again."
      print
  
      if netmask:
        str_to_print = "Enter netmask (currently %s, press enter to retain current value) : "%netmask
      else:
        str_to_print = "Enter netmask (currently not set) : "
      valid_input = False
      while not valid_input:
        input = raw_input(str_to_print)
        if input:
          ok, err = networking.validate_netmask(input)
          if err:
            raise Exception('Error validating netmask : %s'%err)
          if ok:
            valid_input = True
            netmask = input
            config_changed = True
        elif netmask:
          valid_input = True
        if not valid_input:
          print "Invalid value. Please try again."
      print

    if config_changed:
      d = {}
      d['addr_type'] = boot_proto
      if boot_proto == 'static':
        d['ip'] = ip
        d['netmask'] = netmask
      ret, err = networking.set_interface_ip_info(ifname, d)
      if not ret:
        if err:
          raise Exception('Error changing interface address : %s'%err)
        else:
          raise Exception('Error changing interface address')
  
      restart = False
      print
      print
      valid_input = False
      while not valid_input:
        str_to_print = 'Restart network services now (y/n) :'
        print
        input = raw_input(str_to_print)
        if input:
          if input.lower() in ['y', 'n']:
            valid_input = True
            if input.lower() == 'y':
              restart = True
        if not valid_input:
          print "Invalid value. Please try again."
      print
      if restart:
        (r, rc), err = command.execute_with_rc('service network restart')
        if err:
          raise Exception(err)
        if rc == 0:
          print "Network service restarted succesfully."
        else:
          print "Error restarting network services."
          raw_input('Press enter to return to the main menu')
          return -1
        use_salt, err = common.use_salt()
        if err:
          raise Exception(err)
        if use_salt:
          (r, rc), err = command.execute_with_rc('service salt-minion restart')
          if err:
            raise Exception(err)
          if rc == 0:
            print "Salt minion service restarted succesfully."
          else:
            print "Error restarting salt minion services."
            raw_input('Press enter to return to the main menu')
            return -1
    else:
      print
      print
      raw_input('No changes have been made to the configurations. Press enter to return to the main menu.')
      return 0

  except Exception, e:
    print "Error configuring network settings : %s"%e
    return -1
コード例 #20
0
def create_local_user(username, name, pswd, gid = None, smb_user=True):

  try:

    #First check if user exists. if so kick out
    ul, err = get_local_users()
    if ul:
      for ud in ul:
        if ud["username"] == username:
          raise Exception("Error creating user. The user \"%s\" already exists. "%username)
    elif err:
      raise Exception("Error retrieving user list : %s"%err)

  
    enc_pswd = crypt.crypt(pswd, "28")
    use_salt, err = common.use_salt()
    if err:
      raise Exception(err)
    if use_salt:
      client = salt.client.LocalClient()
      if gid:
        rc = client.cmd('*', 'user.add', [username, None, gid])
      else:
        rc = client.cmd('*', 'user.add', [username])
      #print rc
      if not rc:
        error_list.append("Error creating the username")
      for hostname, status in rc.items():
        if not status:
          error_list.append("Error creating the username on node"%hostname)
      rc = client.cmd('*', 'shadow.set_password', [username, enc_pswd] )
      for hostname, status in rc.items():
        if not status:
          error_list.append("Error setting the password for username on GRIDCell %s"%hostname)
      rc = client.cmd('*', 'user.chfullname', [username, "integralstor_user_%s"%name] )
      for hostname, status in rc.items():
        if not status:
          error_list.append("Error setting the name for username on node %s"%hostname)
    else:
      #print '1'
      if gid:
        cmd_to_run = 'useradd -g %s -p %s -c integralstor_user_%s %s'%(gid, enc_pswd, name, username)
      else:
        cmd_to_run = 'useradd  -p %s -c integralstor_user_%s %s'%(enc_pswd, name, username)
      lines, err = command.get_command_output(cmd_to_run)
      #print '2'
      #print lines, err
      if err:
        raise Exception(err)
  
    if smb_user:
      #print '/usr/bin/pdbedit  -d 1 -t -a  -u %s -f %s'%(username, name), "%s\n%s"%(pswd, pswd)
      # Now all set to create samba user
      #print '3'
      #lines, err = command.get_command_output(r'/usr/bin/pdbedit  -d 1 -t -a  -u %s -f %s'%(username, name), "%s\n%s"%(pswd, pswd))
      (ret, rc), err = command.execute_with_conf_and_rc(r'/usr/bin/pdbedit  -d 1 -t -a  -u %s -f %s'%(username, name), "%s\n%s"%(pswd, pswd))
      if rc == 0:
        lines, er = command.get_output_list(ret)
        if er:
          raise Exception(er)
      else:
        err = ''
        tl, er = command.get_output_list(ret)
        if er:
          raise Exception(er)
        if tl:
          err = ','.join(tl)
        tl, er = command.get_error_list(ret)
        if er:
          raise Exception(er)
        if tl:
          err = err + ','.join(tl)
        raise Exception(err)
      #print '4'
      #print lines, err
  except Exception, e:
    return False, 'Error creating local user : %s'%str(e)
コード例 #21
0
def configure_interface():

    try:
        os.system('clear')
        interfaces, err = networking.get_interfaces()
        if err:
            raise Exception('Error retrieving interface information : %s' %
                            err)
        if not interfaces:
            raise Exception('No interfaces detected')
        print
        print
        print 'Integralstor Unicell interface configuration'
        print '--------------------------------------------'
        print
        print
        print 'Current network interfaces : '
        print
        for if_name, iface in interfaces.items():
            if if_name.startswith('lo'):
                continue
            print '- %s' % if_name
        print

        valid_input = False
        while not valid_input:
            ifname = raw_input(
                'Enter the name of the interface that you wish to configure : '
            )
            if ifname not in interfaces or ifname.startswith('lo'):
                print 'Invalid interface name'
            else:
                valid_input = True
        print
        ip_info, err = networking.get_ip_info(ifname)
        '''
    if err:
      raise Exception('Error retrieving interface information : %s'%err)
    '''
        if ip_info:
            ip = ip_info["ipaddr"]
            netmask = ip_info["netmask"]
            if "default_gateway" in ip_info:
                gateway = ip_info["default_gateway"]
            else:
                gateway = None
        else:
            ip = None
            netmask = None
            gateway = None

        old_boot_proto, err = networking.get_interface_bootproto(ifname)
        if err:
            raise Exception('Error retrieving interface information : %s' %
                            err)
            time.sleep(5)

        config_changed = False

        str_to_print = "Configure for DHCP or static addressing (dhcp/static)? : "
        valid_input = False
        while not valid_input:
            input = raw_input(str_to_print)
            if input:
                if input.lower() in ['static', 'dhcp']:
                    valid_input = True
                    boot_proto = input.lower()
                    if boot_proto != old_boot_proto:
                        config_changed = True
            if not valid_input:
                print "Invalid value. Please try again."
        print

        if boot_proto == 'static':
            if ip:
                str_to_print = "Enter IP address (currently %s, press enter to retain current value) : " % ip
            else:
                str_to_print = "Enter IP address (currently not set) : "
            valid_input = False
            while not valid_input:
                input = raw_input(str_to_print)
                if input:
                    ok, err = networking.validate_ip(input)
                    if err:
                        raise Exception('Error validating IP : %s' % err)
                    if ok:
                        valid_input = True
                        ip = input
                        config_changed = True
                elif ip:
                    valid_input = True
                if not valid_input:
                    print "Invalid value. Please try again."
            print

            if netmask:
                str_to_print = "Enter netmask (currently %s, press enter to retain current value) : " % netmask
            else:
                str_to_print = "Enter netmask (currently not set) : "
            valid_input = False
            while not valid_input:
                input = raw_input(str_to_print)
                if input:
                    ok, err = networking.validate_netmask(input)
                    if err:
                        raise Exception('Error validating netmask : %s' % err)
                    if ok:
                        valid_input = True
                        netmask = input
                        config_changed = True
                elif netmask:
                    valid_input = True
            if not valid_input:
                print "Invalid value. Please try again."
            print

            if gateway:
                str_to_print = "Enter gateway (currently %s, press enter to retain current value) : " % gateway
            else:
                str_to_print = "Enter gateway (currently not set) : "
            valid_input = False
            while not valid_input:
                input = raw_input(str_to_print)
                if input:
                    ok, err = networking.validate_ip(input)
                    if err:
                        raise Exception('Error validating gateway : %s' % err)
                    if ok:
                        valid_input = True
                        gateway = input
                        config_changed = True
                elif gateway:
                    valid_input = True
                if not valid_input:
                    print "Invalid value. Please try again."
            print
        if config_changed:
            d = {}
            d['addr_type'] = boot_proto
            if boot_proto == 'static':
                d['ip'] = ip
                d['netmask'] = netmask
                d['default_gateway'] = gateway
            ret, err = networking.set_interface_ip_info(ifname, d)
            if not ret:
                if err:
                    raise Exception('Error changing interface address : %s' %
                                    err)
                else:
                    raise Exception('Error changing interface address')

            restart = False
            print
            print
            valid_input = False
            while not valid_input:
                str_to_print = 'Restart network services now (y/n) :'
                print
                input = raw_input(str_to_print)
                if input:
                    if input.lower() in ['y', 'n']:
                        valid_input = True
                        if input.lower() == 'y':
                            restart = True
                if not valid_input:
                    print "Invalid value. Please try again."
            print

            if restart:
                ret, err = networking.restart_networking()
                if not ret:
                    if err:
                        raise Exception(err)
                    else:
                        raise Exception("Couldn't restart.")

                use_salt, err = common.use_salt()
                if err:
                    raise Exception(err)
                if use_salt:
                    (r, rc), err = command.execute_with_rc(
                        'service salt-minion restart')
                    if err:
                        raise Exception(err)
                    if rc == 0:
                        print "Salt minion service restarted succesfully."
                    else:
                        print "Error restarting salt minion services."
                        raw_input('Press enter to return to the main menu')
                        return -1
        else:
            print
            print
            raw_input(
                'No changes have been made to the configurations. Press enter to return to the main menu.'
            )
            return 0

    except Exception, e:
        print "Error configuring network settings : %s" % e
        return -1
コード例 #22
0
def display_status():

    try:
        hostname = socket.gethostname()
        use_salt, err = common.use_salt()
        if err:
            raise Exception(err)
        if use_salt:
            print "Salt master service status :",
            (r,
             rc), err = command.execute_with_rc('service salt-master status')
            if err:
                raise Exception(err)
            l, err = command.get_output_list(r)
            if err:
                raise Exception(err)
            if l:
                print '\n'.join(l)
            else:
                l, err = command.get_error_list(r)
                if err:
                    raise Exception(err)
                if l:
                    print '\n'.join(l)
            print "Salt minion service status :",
            (r,
             rc), err = command.execute_with_rc('service salt-minion status')
            if err:
                raise Exception(err)
            l, err = command.get_output_list(r)
            if err:
                raise Exception(err)
            if l:
                print '\n'.join(l)
            else:
                l, err = command.get_error_list(r)
                if err:
                    raise Exception(err)
                print l
                if l:
                    print '\n'.join(l)
        print "Samba service status :",
        (r, rc), err = command.execute_with_rc('service smb status')
        if err:
            raise Exception(err)
        l, err = command.get_output_list(r)
        if err:
            raise Exception(err)
        if l:
            print '\n'.join(l)
        else:
            l, err = command.get_error_list(r)
            if err:
                raise Exception(err)
            if l:
                print '\n'.join(l)
        print "Winbind service status :",
        (r, rc), err = command.execute_with_rc('service winbind status')
        if err:
            raise Exception(err)
        l, err = command.get_output_list(r)
        if err:
            raise Exception(err)
        if l:
            print '\n'.join(l)
        else:
            l, err = command.get_error_list(r)
            if err:
                raise Exception(err)
            if l:
                print '\n'.join(l)
    except Exception, e:
        print "Error displaying system status : %s" % e
        return -1