Exemplo n.º 1
0
 def update_servers(req):
     """
     Update a server group
     """
     try:
         UCSUtil.check_ucs_login(req)
     except KubamError as e:
         return {"error": str(e)}, Const.HTTP_UNAUTHORIZED
     db = YamlDB()
     err, msg = db.update_server_group(Const.KUBAM_CFG, req)
     if err == 1:
         return {"error": msg}, Const.HTTP_BAD_REQUEST
     return {"status": "server group {0} updated!".format(req['name'])}, Const.HTTP_CREATED
Exemplo n.º 2
0
    def create_servers(req):
        """
        Create a new UCS Domain
        Format of request should be JSON that looks like:
        {"name", "ucs01", "type" : "ucsm", "credentials":
            {"user": "******", "password": "******", "ip" : "172.28.225.163" }}
        """
        err, msg = YamlDB.check_valid_server_group(req)
        if err != 0:
            return {"error": msg}, Const.HTTP_BAD_REQUEST
        # Make sure we can log in first.
        if not 'type' in req:
            return {"error": "No server type sent as part of request"}, Const.HTTP_UNAUTHORIZED
        if req['type'] == "ucsm":
            try:
                UCSUtil.check_ucs_login(req)
            except KubamError as e:
                return {"error": str(e)}, Const.HTTP_UNAUTHORIZED
        elif req["type"] == "ucsc":
            try:
                UCSCUtil.check_ucsc_login(req)
            except KubamError as e: 
                return {"error":str(e)}, Const.HTTP_UNAUTHORIZED
        elif req["type"] == "imc":
            try: 
                IMCUtil.check_imc_login(req)
            except KubamError as e: 
                return {"error":str(e)}, Const.HTTP_UNAUTHORIZED
        else:
            return {"error": "type: {0} is not recognized".format(req["type"])}, Const.HTTP_UNAUTHORIZED

        db = YamlDB()
        err, msg = db.new_server_group(Const.KUBAM_CFG, req)
        if err == 1:
            return {"error": msg}, Const.HTTP_BAD_REQUEST
        return {"status": "new server group {0} created!".format(req['name'])}, Const.HTTP_CREATED