parameters: (self, request)
docstring: Create Network
          :param request: create parameter
          :return: organization ID
          :rtype: uuid
docstring_summary: Create Network
          :param request: create parameter
          :return: organization ID
          :rtype: uuid
docstring_tokens: Create Network : param request : create parameter : return : organization ID : rtype : uuid
function: def create(self, request):
          """
          Create Network
          :param request: create parameter
          :return: organization ID
          :rtype: uuid
          """
          try:
              serializer = NetworkCreateBody(data=request.data)
              if serializer.is_valid(raise_exception=True):
                  name = serializer.validated_data.get("name")
                  consensus = serializer.validated_data.get("consensus")
                  database = serializer.validated_data.get("database")
  
                  try:
                      if Network.objects.get(name=name):
                          raise ResourceExists
                  except ObjectDoesNotExist:
                      pass
                  org = request.user.organization
                  if org.network:
                      raise ResourceExists
  
                  orderers = []
                  peers = []
                  orderers.append({"name": org.name, "hosts": []})
                  peers.append({"name": org.name, "hosts": []})
                  nodes = Node.objects.filter(organization=org)
                  for node in nodes:
                      if node.type == "peer":
                          peers[0]["hosts"].append({"name": node.name})
                      elif node.type == "orderer":
                          orderers[0]["hosts"].append({"name": node.name})
  
                  ConfigTX(name).create(consensus=consensus, orderers=orderers, peers=peers)
                  ConfigTxGen(name).genesis()
  
                  block = self._genesis2base64(name)
                  network = Network(name=name, consensus=consensus, genesisblock=block)
                  network.save()
                  org.network = network
                  org.save()
                  nodes = Node.objects.filter(organization=org)
                  for node in nodes:
                      try:
                          threading.Thread(target=self._start_node, args=(node.id,)).start()
                      except Exception as e:
                          raise e
  
                  response = NetworkIDSerializer(data=network.__dict__)
                  if response.is_valid(raise_exception=True):
                      return Response(
                          ok(response.validated_data), status=status.HTTP_201_CREATED
                      )
          except ResourceExists as e:
              raise e
          except Exception as e:
              return Response(
                  err(e.args), status=status.HTTP_400_BAD_REQUEST
              )
function_tokens: def create ( self , request ) : try : serializer = NetworkCreateBody ( data = request . data ) if serializer . is_valid ( raise_exception = True ) : name = serializer . validated_data . get ( "name" ) consensus = serializer . validated_data . get ( "consensus" ) database = serializer . validated_data . get ( "database" ) try : if Network . objects . get ( name = name ) : raise ResourceExists except ObjectDoesNotExist : pass org = request . user . organization if org . network : raise ResourceExists orderers = [ ] peers = [ ] orderers . append ( { "name" : org . name , "hosts" : [ ] } ) peers . append ( { "name" : org . name , "hosts" : [ ] } ) nodes = Node . objects . filter ( organization = org ) for node in nodes : if node . type == "peer" : peers [ 0 ] [ "hosts" ] . append ( { "name" : node . name } ) elif node . type == "orderer" : orderers [ 0 ] [ "hosts" ] . append ( { "name" : node . name } ) ConfigTX ( name ) . create ( consensus = consensus , orderers = orderers , peers = peers ) ConfigTxGen ( name ) . genesis ( ) block = self . _genesis2base64 ( name ) network = Network ( name = name , consensus = consensus , genesisblock = block ) network . save ( ) org . network = network org . save ( ) nodes = Node . objects . filter ( organization = org ) for node in nodes : try : threading . Thread ( target = self . _start_node , args = ( node . id , ) ) . start ( ) except Exception as e : raise e response = NetworkIDSerializer ( data = network . __dict__ ) if response . is_valid ( raise_exception = True ) : return Response ( ok ( response . validated_data ) , status = status . HTTP_201_CREATED ) except ResourceExists as e : raise e except Exception as e : return Response ( err ( e . args ) , status = status . HTTP_400_BAD_REQUEST )