示例#1
0
def main():

    lg = None
    try:
        lg, err = logger.get_script_logger('Generate manifest',
                                           '/var/log/integralstor/scripts.log',
                                           level=logging.DEBUG)
        logger.log_or_print('Generate manifest initiated.', lg, level='info')

        num_args = len(sys.argv)
        if num_args > 1:
            path = sys.argv[1]
        else:
            path, err = common.get_system_status_path()
            if err:
                raise Exception(err)
            if not path:
                path = '/tmp'
        logger.log_or_print("Generating the manifest in %s" % path,
                            lg,
                            level='info')
        rc, err = gen_manifest(path)
        if err:
            raise Exception(err)
        #print rc
    except Exception, e:
        str = "Error generating manifest file : %s" % e
        logger.log_or_print(str, lg, level='critical')
        return -1
def load_system_config(first_time = False):

  d = None
  try:
    if first_time:
      system_status_path, err = common.get_tmp_path()
      if err:
        raise Exception(err)
    else:
      system_status_path, err = common.get_system_status_path()
      if err:
        raise Exception(err)
  
    msfn = "%s/master.status"%system_status_path
    mmfn = "%s/master.manifest"%system_status_path
  
    with open(msfn, "r") as f:
      ms_nodes = json.load(f)
    with open(mmfn, "r") as f:
      mm_nodes = json.load(f)
    
    d = {}
    # First load it with the master node keys
    for k in mm_nodes.keys():
      d[k] = mm_nodes[k]
  
    for k in d.keys():
      if k not in ms_nodes:
        continue
      status_node = ms_nodes[k]
      for sk in status_node.keys():
        if sk not in d[k]:
          d[k][sk] = status_node[sk]
        elif sk == "disks":
          for disk in status_node["disks"].keys():
            if disk in d[k]["disks"]:
              d[k]["disks"][disk].update(status_node["disks"][disk])
            '''
            else:
              d[k]["disks"][disk] = status_node["disks"][disk]
            '''
        elif sk == "interfaces":
          for interface in status_node["interfaces"].keys():
            if interface in d[k]["interfaces"]:
              d[k]["interfaces"][interface].update(status_node["interfaces"][interface])
            '''
            else:
              d[k]["interfaces"][interface] = status_node["interfaces"][interface]
            '''
        elif sk == "memory":
          for mem_key in status_node["memory"].keys():
            if mem_key not in d[k]["memory"]:
              d[k]["memory"][mem_key] = status_node["memory"][mem_key]
  
  
    
  except Exception, e:
    return None, 'Error loading system configuration : %s'%str(e)
def main():

  try :
    num_args = len(sys.argv)
    if num_args > 1:
      path = sys.argv[1]
    else:
      path = common.get_system_status_path()
      if not path:
        path = '/tmp'
    print "Generating the manifest in %s"%path
    rc = gen_manifest(path)
    print rc
  except Exception, e:
    print "Error generating manifest file : %s"%e
    return -1
def main():

    '''
    try :
    '''
    num_args = len(sys.argv)
    if num_args > 1:
      path = sys.argv[1]
    else:
      path = common.get_system_status_path()
      if not path:
        path = '/tmp'
    print "Generating the status in %s"%path
    rc = gen_status(path)
    print rc
    '''
def main():

  lg = None
  try :
    lg, err = logger.get_script_logger('Generate status', '/var/log/integralstor/scripts.log', level = logging.DEBUG)

    logger.log_or_print('Generate status initiated.', lg, level='info')

    platform, err = common.get_platform()
    if err:
      raise Exception(err)

    default_path = False

    num_args = len(sys.argv)

    if num_args > 1:
      path = sys.argv[1]
    else:
      default_path = True
      path, err = common.get_system_status_path()
      if err:
        raise Exception(err)
      if not path:
        path = '/tmp'
    #print platform, path

    if platform == 'gridcell' and default_path:
      #This means that I must've been called from a cron script so need to check if I really need to execute..
      from integralstor_gridcell import grid_ops
      active, err = grid_ops.is_active_admin_gridcell()
      if err:
        raise Exception(err)
      if not active:
        logger.log_or_print('Not active admin GRIDCell so exiting.', lg, level='info')
        sys.exit(0)

    logger.log_or_print("Generating the status in %s"%path, lg, level='info')
    rc, err = gen_status(path, lg)
    if err:
      raise Exception(err)
    #print rc
  except Exception, e:
    str = "Error generating status file : %s"%e
    logger.log_or_print(str, lg, level='critical')
    sys.exit(-1)
示例#6
0
def main():

    try:
        num_args = len(sys.argv)
        if num_args > 1:
            path = sys.argv[1]
        else:
            path, err = common.get_system_status_path()
            if err:
                raise Exception(err)
            if not path:
                path = '/tmp'
        print "Generating the manifest in %s" % path
        rc = gen_manifest(path)
        print rc
    except Exception, e:
        print "Error generating manifest file : %s" % e
        return -1
def load_system_config(first_time = False):

  if first_time:
    system_status_path = common.get_tmp_path()
  else:
    system_status_path = common.get_system_status_path()

  msfn = "%s/master.status"%system_status_path
  mmfn = "%s/master.manifest"%system_status_path

  with open(msfn, "r") as f:
    ms_nodes = json.load(f)
  with open(mmfn, "r") as f:
    mm_nodes = json.load(f)
  
  d = {}
  # First load it with the master node keys
  for k in mm_nodes.keys():
    d[k] = mm_nodes[k]

  for k in d.keys():
    if k not in ms_nodes:
      continue
    status_node = ms_nodes[k]
    for sk in status_node.keys():
      if sk not in d[k]:
        d[k][sk] = status_node[sk]
      elif sk == "disks":
        for disk in status_node["disks"]:
          if disk in d[k]["disks"]:
            d[k]["disks"][disk].update(status_node["disks"][disk])
          else:
            d[k]["disks"][disk] = status_node["disks"][disk]
      elif sk == "interfaces":
        for interface in status_node["interfaces"]:
          if interface in d[k]["interfaces"]:
            d[k]["interfaces"][interface].update(status_node["interfaces"][interface])
          else:
            d[k]["interfaces"][interface] = status_node["interfaces"][interface]

  return d
def reload_manifest(request):
  return_dict = {}
  try:
    if request.method == "GET":
      from integralstor_unicell import manifest_status as iu
      mi, err = iu.generate_manifest_info()
      #print mi, err
      if err:
        raise Exception(err)
      if not mi:
        raise Exception('Could not load new configuration')
      return_dict["mi"] = mi[mi.keys()[0]] # Need the hostname here. 
      return django.shortcuts.render_to_response("reload_manifest.html", return_dict, context_instance=django.template.context.RequestContext(request))
    elif request.method == "POST":
      common_python_scripts_path, err = common.get_common_python_scripts_path()
      if err:
        raise Exception(err)
      ss_path, err = common.get_system_status_path()
      if err:
        raise Exception(err)
      #(ret,rc), err = command.execute_with_rc("python %s/generate_manifest.py %s"%(common_python_scripts_path, ss_path))
      ret, err = command.get_command_output("python %s/generate_manifest.py %s"%(common_python_scripts_path, ss_path))
      #print 'mani', ret, err
      if err:
        raise Exception(err)
      #(ret,rc), err = command.execute_with_rc("python %s/generate_status.py %s"%(common.get_python_scripts_path(), common.get_system_status_path()))
      ret, err = command.get_command_output("python %s/generate_status.py %s"%(common_python_scripts_path, ss_path))
      #print 'stat', ret, err
      if err:
        raise Exception(err)
      return django.http.HttpResponseRedirect("/show/node_info/")
  except Exception, e:
    return_dict['base_template'] = "system_base.html"
    return_dict["page_title"] = 'Reload system configuration'
    return_dict['tab'] = 'node_info_tab'
    return_dict["error"] = 'Error reloading system configuration'
    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))
def edit_hostname(request):
  return_dict = {}
  try:

    hostname = socket.gethostname()
    if request.method == "GET":
      hostname = socket.gethostname()
      domain_name,err = networking.get_domain_name()
      if err:
        raise Exception(err)

      initial = {}
      initial['hostname'] = hostname
      initial['domain_name'] = domain_name

      form = networking_forms.EditHostnameForm(initial=initial)
      return_dict['form'] = form
      return django.shortcuts.render_to_response("edit_hostname.html", return_dict, context_instance = django.template.context.RequestContext(request))
    else:
      form = networking_forms.EditHostnameForm(request.POST)
      return_dict['form'] = form
      if not form.is_valid():
        return django.shortcuts.render_to_response("edit_hostname.html", return_dict, context_instance = django.template.context.RequestContext(request))
      cd = form.cleaned_data
      result_str = ""
      domain_name = None
      if 'domain_name' in cd:
        domain_name = cd['domain_name']
      result, err = networking.set_hostname(cd['hostname'], domain_name)
      if not result:
        if err:
          raise Exception(err)
        else:
          raise Exception('Error setting hostname')
      result, err = networking.set_domain_name(domain_name)
      if not result:
        if err:
          raise Exception(err)
        else:
          raise Exception('Error setting domain name')
      python_scripts_path, err = common.get_python_scripts_path()
      if err:
        raise Exception(err)
      common_python_scripts_path, err = common.get_common_python_scripts_path()
      if err:
        raise Exception(err)
      ss_path, err = common.get_system_status_path()
      if err:
        raise Exception(err)

      ret, err = command.get_command_output("python %s/generate_manifest.py %s"%(common_python_scripts_path, ss_path))
      if err:
        raise Exception(err)

      ret, err = command.get_command_output("python %s/generate_status.py %s"%(common_python_scripts_path, ss_path))
      if err:
        raise Exception(err)

      audit_str = "Hostname set to %s."%cd['hostname']
      if 'domain_name' in cd:
        audit_str += 'Domain name set to %s'%cd['domain_name']
      ret, err = audit.audit("edit_hostname", audit_str, request.META["REMOTE_ADDR"])
      if err:
        raise Exception(err)
              
      return django.http.HttpResponseRedirect('/view_hostname?result=saved')
  except Exception, e:
    return_dict['base_template'] = "networking_base.html"
    return_dict["page_title"] = 'Modify system hostname'
    return_dict['tab'] = 'view_hostname_tab'
    return_dict["error"] = 'Error modifying system hostname'
    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))
示例#10
0
def edit_hostname(request):
    return_dict = {}
    try:

        hostname = socket.gethostname()
        if request.method == "GET":
            hostname, err = networking.get_hostname()
            if err:
                raise Exception(err)
            domain_name, err = networking.get_domain_name()
            if err:
                raise Exception(err)

            initial = {}
            initial['hostname'] = hostname
            initial['domain_name'] = domain_name

            form = networking_forms.EditHostnameForm(initial=initial)
            return_dict['form'] = form
            return django.shortcuts.render_to_response(
                "edit_hostname.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            form = networking_forms.EditHostnameForm(request.POST)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response(
                    "edit_hostname.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
            cd = form.cleaned_data
            result_str = ""
            domain_name = None
            if 'domain_name' in cd:
                domain_name = cd['domain_name']
            result, err = networking.set_hostname(cd['hostname'], domain_name)
            if not result:
                if err:
                    raise Exception(err)
                else:
                    raise Exception('Error setting hostname')
            result, err = networking.set_domain_name(domain_name)
            if not result:
                if err:
                    raise Exception(err)
                else:
                    raise Exception('Error setting domain name')
            python_scripts_path, err = common.get_python_scripts_path()
            if err:
                raise Exception(err)
            common_python_scripts_path, err = common.get_common_python_scripts_path(
            )
            if err:
                raise Exception(err)
            ss_path, err = common.get_system_status_path()
            if err:
                raise Exception(err)

            ret, err = command.get_command_output(
                "python %s/generate_manifest.py %s" %
                (common_python_scripts_path, ss_path))
            if err:
                raise Exception(err)

            ret, err = command.get_command_output(
                "python %s/generate_status.py %s" %
                (common_python_scripts_path, ss_path))

            audit_str = "Hostname set to %s." % cd['hostname']
            if 'domain_name' in cd:
                audit_str += 'Domain name set to %s' % cd['domain_name']
            ret, err = audit.audit("edit_hostname", audit_str, request.META)
            if err:
                raise Exception(err)

            return django.http.HttpResponseRedirect(
                '/view_hostname?result=saved')
    except Exception, e:
        return_dict['base_template'] = "networking_base.html"
        return_dict["page_title"] = 'Modify system hostname'
        return_dict['tab'] = 'view_hostname_tab'
        return_dict["error"] = 'Error modifying system hostname'
        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))
示例#11
0
def remove_bond(request):

    return_dict = {}
    try:
        if 'name' not in request.REQUEST:
            raise Exception("No bond name specified. Please use the menus")

        name = request.REQUEST["name"]
        return_dict["name"] = name

        if request.method == "GET":
            #Return the conf page
            return django.shortcuts.render_to_response(
                "remove_bond_conf.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            result, err = networking.remove_bond(name)
            if not result:
                if not err:
                    raise Exception("Error removing bond")
                else:
                    raise Exception(err)

            python_scripts_path, err = common.get_python_scripts_path()
            if err:
                raise Exception(err)
            common_python_scripts_path, err = common.get_common_python_scripts_path(
            )
            if err:
                raise Exception(err)
            status_path, err = common.get_system_status_path()
            if err:
                raise Exception(err)

            ret, err = command.get_command_output(
                "python %s/generate_manifest.py %s" %
                (common_python_scripts_path, status_path))
            if err:
                raise Exception(err)

            ret, err = command.get_command_output(
                "python %s/generate_status.py %s" %
                (common_python_scripts_path, status_path))
            if err:
                raise Exception(err)

            audit_str = "Removed network bond %s" % (name)
            audit.audit("remove_bond", audit_str, request.META)
            return django.http.HttpResponseRedirect(
                '/view_interfaces?ack=removed_bond')
    except Exception, e:
        return_dict['base_template'] = "networking_base.html"
        return_dict["page_title"] = 'Remove a network interface bond'
        return_dict['tab'] = 'view_interfaces_tab'
        return_dict["error"] = 'Error removing a network interface bond'
        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))
示例#12
0
def create_bond(request):
    return_dict = {}
    try:

        interfaces, err = networking.get_interfaces()
        if err:
            raise Exception(err)
        if not interfaces:
            raise Exception(
                "Error loading network interface information : No interfaces found"
            )

        bm, err = networking.get_bonding_masters()
        if err:
            raise Exception(err)
        bid, err = networking.get_bonding_info_all()
        if err:
            raise Exception(err)

        return_dict['interfaces'] = interfaces
        if_list = []
        existing_bonds = []
        for if_name, iface in interfaces.items():
            ret, err = networking.get_ip_info(if_name)
            if ret:
                continue
            if if_name.startswith('lo') or if_name in bid['by_slave']:
                continue
            if if_name in bm:
                existing_bonds.append(if_name)
                continue
            if_list.append(if_name)

        if request.method == "GET":
            form = networking_forms.CreateBondForm(
                interfaces=if_list, existing_bonds=existing_bonds)
            return_dict['form'] = form
            return django.shortcuts.render_to_response(
                "create_bond.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            form = networking_forms.CreateBondForm(
                request.POST,
                interfaces=if_list,
                existing_bonds=existing_bonds)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response(
                    "create_bond.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
            cd = form.cleaned_data
            print cd
            result, err = networking.create_bond(cd['name'], cd['slaves'],
                                                 int(cd['mode']))
            if not result:
                if err:
                    raise Exception(err)
                else:
                    raise Exception('Bond creation failed!')
            python_scripts_path, err = common.get_python_scripts_path()
            if err:
                raise Exception(err)
            common_python_scripts_path, err = common.get_common_python_scripts_path(
            )
            if err:
                raise Exception(err)
            status_path, err = common.get_system_status_path()
            if err:
                raise Exception(err)

            ret, err = command.get_command_output(
                "python %s/generate_manifest.py %s" %
                (common_python_scripts_path, status_path))
            if err:
                raise Exception(err)

            ret, err = command.get_command_output(
                "python %s/generate_status.py %s" %
                (common_python_scripts_path, status_path))
            if err:
                raise Exception(err)

            audit_str = "Created a network bond named %s with slaves %s" % (
                cd['name'], ','.join(cd['slaves']))
            audit.audit("create_bond", audit_str, request.META)
            return django.http.HttpResponseRedirect(
                '/view_interfaces?ack=created_bond')
    except Exception, e:
        return_dict['base_template'] = "networking_base.html"
        return_dict["page_title"] = 'Create a network interface bond'
        return_dict['tab'] = 'view_interfaces_tab'
        return_dict["error"] = 'Error creating a network interface bond'
        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))
示例#13
0
def load_system_config(first_time=False):

    d = None
    try:
        if first_time:
            system_status_path, err = common.get_tmp_path()
            if err:
                raise Exception(err)
        else:
            system_status_path, err = common.get_system_status_path()
            if err:
                raise Exception(err)

        msfn = "%s/master.status" % system_status_path
        mmfn = "%s/master.manifest" % system_status_path

        with open(msfn, "r") as f:
            ms_nodes = json.load(f)
        with open(mmfn, "r") as f:
            mm_nodes = json.load(f)

        d = {}
        # First load it with the master node keys
        for k in mm_nodes.keys():
            d[k] = mm_nodes[k]

        for k in d.keys():
            if k not in ms_nodes:
                continue
            status_node = ms_nodes[k]
            for sk in status_node.keys():
                if sk not in d[k]:
                    d[k][sk] = status_node[sk]
                elif sk == "disks":
                    for disk in status_node["disks"].keys():
                        if disk in d[k]["disks"]:
                            d[k]["disks"][disk].update(
                                status_node["disks"][disk])
                    pool_list, err = zfs.get_pools()
                    if pool_list:
                        for sn, disk in d[k]['disks'].items():
                            id = disk['id']
                            found = False
                            for pool in pool_list:
                                devices_list, err = zfs.get_disks_in_component(
                                    pool['config']['pool']['root'])
                                if err:
                                    raise Exception(err)
                                if devices_list and id in devices_list:
                                    disk['pool'] = pool['pool_name']
                        '''
            else:
              d[k]["disks"][disk] = status_node["disks"][disk]
            '''
                elif sk == "interfaces":
                    for interface in status_node["interfaces"].keys():
                        if interface in d[k]["interfaces"]:
                            d[k]["interfaces"][interface].update(
                                status_node["interfaces"][interface])
                        '''
            else:
              d[k]["interfaces"][interface] = status_node["interfaces"][interface]
            '''
                elif sk == "memory":
                    for mem_key in status_node["memory"].keys():
                        if mem_key not in d[k]["memory"]:
                            d[k]["memory"][mem_key] = status_node["memory"][
                                mem_key]

    except Exception, e:
        return None, 'Error loading system configuration : %s' % str(e)