예제 #1
0
 def put_default_ifc():
     print "Adding default IFC for %s" % sip_uri
     stats["Missing IFCs re-created"] += 1
     global pending_requests
     pending_requests+=1
     homestead.put_filter_criteria(sip_uri,
                                   ifcs.generate_ifcs(settings.SIP_DIGEST_REALM),
                                   logging_handler)
예제 #2
0
 def put_default_ifc():
     print "Adding default IFC for %s" % sip_uri
     stats["Missing IFCs re-created"] += 1
     global pending_requests
     pending_requests+=1
     homestead.put_filter_criteria(sip_uri,
                                   ifcs.generate_ifcs(utils.sip_uri_to_domain(sip_uri)),
                                   logging_handler)
예제 #3
0
 def put_default_ifc():
     print "Adding default IFC for %s" % sip_uri
     stats["Missing IFCs re-created"] += 1
     global pending_requests
     pending_requests += 1
     homestead.put_filter_criteria(
         sip_uri, ifcs.generate_ifcs(utils.sip_uri_to_domain(sip_uri)),
         logging_handler)
예제 #4
0
파일: repop_hs.py 프로젝트: AiprNick/ellis
 def get_ifc_callback(response, sip_uri=sip_uri):
     """
     Handle response to initial GET, only PUT new data if there 
     wasn't anything there.
     """
     global num_responses, num_requests
     print "%s Get ifc response %s" % (sip_uri, response.code)
     if response.code == 404:
         print "%s ifc needs to be repopulated" % (sip_uri,)
         homestead.put_filter_criteria(sip_uri, ifcs.generate_ifcs(utils.sip_uri_to_domain(sip_uri)), put_ifc_callback)
     else:
         inc_resp_count()
예제 #5
0
def standalone():
    if len(sys.argv) != 2:
        print USAGE
        return
    csv_filename = sys.argv[1]
    csv_filename_prefix = string.replace(csv_filename, ".csv", "")
    output_filename = "%s_prepared.csv" % (csv_filename_prefix)
    print "Preparing %s for bulk provisioning..." % (csv_filename)
    try:
        with open(csv_filename, 'rb') as csv_file, \
             open(output_filename, 'w') as output_file:

            reader = csv.reader(csv_file)
            for row in reader:
                if len(row) >= 4:
                    [public_id, private_id, realm, password] = row[0:4]

                    # Hash the password and generate the IMSSubscriptionXML.
                    hash = utils.md5("%s:%s:%s" % (private_id, realm, password))
                    publicidentity_xml = "<PublicIdentity><Identity>%s</Identity></PublicIdentity>" % public_id
                    initial_filter_xml = ifcs.generate_ifcs(utils.sip_uri_to_domain(public_id))
                    ims_subscription_xml = create_imssubscription_xml(private_id, publicidentity_xml, initial_filter_xml)
                    irs_uuid = uuid.uuid4();
                    sp_uuid = uuid.uuid4();

                    # Print a line for the user
                    output_file.write("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n" % (public_id, private_id, realm, hash, SIMSERVS, publicidentity_xml, initial_filter_xml, ims_subscription_xml, irs_uuid, sp_uuid, password))
                else:
                    print 'Error: row %s contains <4 entries - ignoring' % row

        print "Bulk provisioning input created"
        print "- BulkProvision homer %s" % (output_filename)
        print "- BulkProvision homestead-local %s" % (output_filename)
        print "- BulkProvision homestead-hss %s" % (output_filename)
    except IOError as e:
        print "Failed to read/write to %s:" % (e.filename,)
        traceback.print_exc();
예제 #6
0
파일: numbers.py 프로젝트: biddyweb/ellis
    def post(self, username):
        """Allocate a phone number."""
        _log.debug("Number allocation API call (PSTN = %s)", self.get_argument('pstn', 'false'))
        user_id = self.get_and_check_user_id(username)
        db_sess = self.db_session()
        pstn = self.get_argument('pstn', 'false') == 'true'
        private_id = self.get_argument('private_id', None)
        try:
            number_id = numbers.allocate_number(db_sess, user_id, pstn)
            sip_uri = numbers.get_number(db_sess, number_id, user_id)
            self.sip_uri = sip_uri
            _log.debug("SIP URI %s", sip_uri)
            # FIXME We shouldn't commit until we know XDM/HS have succeeded but
            # if we hold the transaction open we can deadlock
            # * Request 1 comes in and allocates a number, kicks off requests
            #   to XDM/Homestead, has transaction open, returns thread to Tornado
            # * Request 2 comes in, allocates same number, can't lock it for
            #   update because Request 1 is holding it.  Blocks.
            # * Request 1 gets response but the thread is tied up
            # * Request 2 SQL transaction times out.
            # * Request 1 probably completes..
            db_sess.commit()
        except NotFound:
            # FIXME email operator to tell them we're out of numbers!
            _log.warning("No available numbers")
            raise HTTPError(httplib.SERVICE_UNAVAILABLE,
                            "No available numbers")

        # Work out the response we'll send if the upstream requests
        # are successful.
        number = utils.sip_uri_to_phone_number(sip_uri)
        pretty_number = utils.format_phone_number(number)
        self.__response = {"sip_uri": sip_uri,
                           "sip_username": number,
                           "number": number,
                           "pstn": pstn,
                           "formatted_number": pretty_number,
                           "number_id": number_id.hex}

        # Generate a random password and store it in Homestead.
        _log.debug("Populating other servers...")
        self._request_group = HTTPCallbackGroup(self._on_post_success,
                                                self._on_post_failure)

        public_callback = self._request_group.callback()

        if private_id == None:
            # No private id was provided, so we need to create a new
            # digest in Homestead
            private_id = utils.sip_public_id_to_private(sip_uri)
            sip_password = utils.generate_sip_password()
            homestead.create_private_id(private_id,
                                        sip_password,
                                        self._request_group.callback())
            self.__response["sip_password"] = sip_password

        # Associate the new public identity with the private identity in Homestead
        # and store the iFCs in homestead.
        homestead.create_public_id(private_id,
                                   sip_uri,
                                   ifcs.generate_ifcs(settings.SIP_DIGEST_REALM),
                                   public_callback)

        self.__response["private_id"] = private_id

        # Concurrently, store the default simservs in XDM.
        with open(settings.XDM_DEFAULT_SIMSERVS_FILE) as xml_file:
            default_xml = xml_file.read()
        xdm.put_simservs(sip_uri, default_xml, self._request_group.callback())
def write_homestead_scripts(csv_filename, write_plaintext_password):
    csv_filename_prefix = string.replace(csv_filename, ".csv", "")
    homestead_filename = "%s.create_homestead.sh" % (csv_filename_prefix)
    homestead_prov_casscli_filename = "%s.create_homestead_provisioning.casscli" % (csv_filename_prefix)
    homestead_cache_casscli_filename = "%s.create_homestead_cache.casscli" % (csv_filename_prefix)

    with open(homestead_filename, 'w') as homestead_file, \
         open(homestead_cache_casscli_filename, 'w') as homestead_cache_casscli_file, \
         open(homestead_prov_casscli_filename, 'w') as homestead_prov_casscli_file:

        # Write Homestead/cassandra-cli header
        homestead_file.write("#!/bin/bash\n")
        homestead_file.write("# Homestead bulk provisioning script for users in %s\n" % (csv_filename))
        homestead_file.write("# Run this script on any node in your Homestead deployment to create the users\n")
        homestead_file.write("# The %s and %s files must also be present on this system\n" % (homestead_cache_casscli_filename, homestead_prov_casscli_filename))
        homestead_file.write("\n")
        homestead_file.write("[ -f %s ] || echo \"The %s file must be present on this system.\"\n" % (homestead_cache_casscli_filename, homestead_cache_casscli_filename))
        homestead_file.write("[ -f %s ] || echo \"The %s file must be present on this system.\"\n" % (homestead_prov_casscli_filename, homestead_prov_casscli_filename))
        homestead_file.write("cassandra-cli -B -f %s\n" % (homestead_cache_casscli_filename))
        homestead_file.write("cassandra-cli -B -f %s\n" % (homestead_prov_casscli_filename))
        homestead_cache_casscli_file.write("USE homestead_cache;\n")
        homestead_prov_casscli_file.write("USE homestead_provisioning;\n")
        i=0 #count user info
        for public_id, private_id, realm, password in csv_iterator(csv_filename):
            print str(public_id) + ':' + str(i)
            # Generate the user-specific data
            hash = utils.md5("%s:%s:%s" % (private_id, realm, password))

            public_identity_xml = "<PublicIdentity><BarringIndication>1</BarringIndication><Identity>%s</Identity></PublicIdentity>" % public_id
            initial_filter_xml = ifcs.generate_ifcs(utils.sip_uri_to_domain(public_id))
            #
            if i % 2 == 1:
                print 'Receiver add VSIF iFC.'
                initial_filter_xml = '<?xml version="1.0" encoding="UTF-8"?><ServiceProfile><InitialFilterCriteria><Priority>0</Priority><TriggerPoint><ConditionTypeCNF>0</ConditionTypeCNF><SPT><ConditionNegated>0</ConditionNegated><Group>0</Group><Method>INVITE</Method><Extension/></SPT></TriggerPoint><ApplicationServer><ServerName>sip:vsif.clearwater:5060</ServerName><DefaultHandling>1</DefaultHandling></ApplicationServer></InitialFilterCriteria></ServiceProfile>'
            ims_subscription_xml = create_imssubscription_xml(private_id, public_identity_xml, initial_filter_xml)
            irs_uuid = str(uuid.uuid4())
            sp_uuid = str(uuid.uuid4())

            # Add the user to the optimized cassandra cache.
            homestead_cache_casscli_file.write(
                create_row_command("impi", private_id))
            homestead_cache_casscli_file.write(
                "SET impi['%s']['digest_ha1'] = '%s';\n" % (private_id, hash))
            homestead_cache_casscli_file.write(
                "SET impi['%s']['digest_realm'] = '%s';\n" % (private_id, realm))
            homestead_cache_casscli_file.write(
                "SET impi['%s']['public_id_%s'] = '';\n" % (private_id,
                                                            public_id))

            homestead_cache_casscli_file.write(
                create_row_command("impu", public_id))
            homestead_cache_casscli_file.write(
                "SET impu['%s']['ims_subscription_xml'] = '%s';\n" % (
                    public_id,
                    ims_subscription_xml.replace("'", "\\'")))

            # Populate the provisioning tables for the user.
            homestead_prov_casscli_file.write(
                create_row_command("implicit_registration_sets", irs_uuid))
            homestead_prov_casscli_file.write(
                "SET implicit_registration_sets['%s']['service_profile_%s'] = lexicaluuid('%s');\n" % (irs_uuid,
                                                                                                       sp_uuid,
                                                                                                       sp_uuid))
            homestead_prov_casscli_file.write(
                "SET implicit_registration_sets['%s']['associated_private_%s'] = utf8('%s');\n" % (irs_uuid,
                                                                                                   private_id,
                                                                                                   private_id))

            homestead_prov_casscli_file.write(
                create_row_command("service_profiles", sp_uuid))
            homestead_prov_casscli_file.write(
                "SET service_profiles['%s']['irs'] = '%s';\n" % (sp_uuid,
                                                                 irs_uuid))
            homestead_prov_casscli_file.write(
                "SET service_profiles['%s']['initialfiltercriteria'] = '%s';\n" % (sp_uuid,
                                                                                   initial_filter_xml))
            homestead_prov_casscli_file.write(
                "SET service_profiles['%s']['public_id_%s'] = utf8('%s');\n" % (sp_uuid,
                                                                                public_id,
                                                                                public_id))

            homestead_prov_casscli_file.write(
                create_row_command("public", public_id))
            homestead_prov_casscli_file.write(
                "SET public['%s']['publicidentity'] = '%s';\n" % (public_id,
                                                                  public_identity_xml))
            homestead_prov_casscli_file.write(
                "SET public['%s']['service_profile'] = '%s';\n" % (public_id,
                                                                   sp_uuid))

            password_to_write = password if write_plaintext_password else ""
            homestead_prov_casscli_file.write(
                create_row_command("private", private_id))
            homestead_prov_casscli_file.write(
                "SET private['%s']['digest_ha1'] = '%s';\n" % (private_id,
                                                               hash))
            homestead_prov_casscli_file.write(
                "SET private['%s']['plaintext_password'] = '******';\n" % (private_id,
                                                                       password_to_write))
            homestead_prov_casscli_file.write(
                "SET private['%s']['realm'] = '%s';\n" % (private_id, realm))
            homestead_prov_casscli_file.write(
                "SET private['%s']['associated_irs_%s'] = lexicaluuid('%s');\n" % (private_id,
                                                                                   irs_uuid,
                                                                                   irs_uuid))
            i=i+1

    # Make the created .sh files executable
    permissions = stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE
    os.chmod(homestead_filename, permissions)

    print "Generated homestead bulk provisioning scripts"
    print "- %-46s - run this script on Homestead" % (homestead_filename)
    print "- %-46s - copy this file onto Homestead" % (homestead_cache_casscli_filename)
    print "- %-46s - copy this file onto Homestead" % (homestead_prov_casscli_filename)
예제 #8
0
파일: bulk_create.py 프로젝트: rkday/crest
Each row in the input CSV file describes a user, and must contain 4 columns:
- public SIP ID
- private SIP ID
- realm
- password
If you have a CSV file with fewer columns, you can autocomplete the remaining
columns using the bulk_autocomplete.py script.
"""

import sys, string, csv
from metaswitch.crest import settings
from metaswitch.common import utils
from metaswitch.common import ifcs

INITIAL_FILTER_CRITERIA = ifcs.generate_ifcs(settings.SIP_DIGEST_REALM)
with open(settings.XDM_DEFAULT_SIMSERVS_FILE, "rb") as simservs_file:
    SIMSERVS = simservs_file.read()


def standalone():
    if len(sys.argv) != 2:
        print USAGE
        return
    csv_filename = sys.argv[1]
    csv_filename_prefix = string.replace(csv_filename, ".csv", "")
    homestead_filename = "%s.create_homestead.sh" % (csv_filename_prefix, )
    homestead_casscli_filename = "%s.create_homestead.casscli" % (
        csv_filename_prefix, )
    xdm_filename = "%s.create_xdm.sh" % (csv_filename_prefix, )
    xdm_cqlsh_filename = "%s.create_xdm.cqlsh" % (csv_filename_prefix, )
예제 #9
0
def write_homestead_scripts(csv_filename, write_plaintext_password):
    csv_filename_prefix = string.replace(csv_filename, ".csv", "")
    homestead_filename = "%s.create_homestead.sh" % (csv_filename_prefix)
    homestead_prov_casscli_filename = "%s.create_homestead_provisioning.casscli" % (
        csv_filename_prefix)
    homestead_cache_casscli_filename = "%s.create_homestead_cache.casscli" % (
        csv_filename_prefix)

    with open(homestead_filename, 'w') as homestead_file, \
         open(homestead_cache_casscli_filename, 'w') as homestead_cache_casscli_file, \
         open(homestead_prov_casscli_filename, 'w') as homestead_prov_casscli_file:

        # Write Homestead/cassandra-cli header
        homestead_file.write("#!/bin/bash\n")
        homestead_file.write(
            "# Homestead bulk provisioning script for users in %s\n" %
            (csv_filename))
        homestead_file.write(
            "# Run this script on any node in your Homestead deployment to create the users\n"
        )
        homestead_file.write(
            "# The %s and %s files must also be present on this system\n" %
            (homestead_cache_casscli_filename,
             homestead_prov_casscli_filename))
        homestead_file.write("\n")
        homestead_file.write(
            "[ -f %s ] || echo \"The %s file must be present on this system.\"\n"
            % (homestead_cache_casscli_filename,
               homestead_cache_casscli_filename))
        homestead_file.write(
            "[ -f %s ] || echo \"The %s file must be present on this system.\"\n"
            %
            (homestead_prov_casscli_filename, homestead_prov_casscli_filename))
        homestead_file.write("cassandra-cli -B -f %s\n" %
                             (homestead_cache_casscli_filename))
        homestead_file.write("cassandra-cli -B -f %s\n" %
                             (homestead_prov_casscli_filename))
        homestead_cache_casscli_file.write("USE homestead_cache;\n")
        homestead_prov_casscli_file.write("USE homestead_provisioning;\n")

        for public_id, private_id, realm, password in csv_iterator(
                csv_filename):

            # Generate the user-specific data
            hash = utils.md5("%s:%s:%s" % (private_id, realm, password))

            public_identity_xml = "<PublicIdentity><Identity>%s</Identity></PublicIdentity>" % public_id
            initial_filter_xml = ifcs.generate_ifcs(
                utils.sip_uri_to_domain(public_id))
            ims_subscription_xml = create_imssubscription_xml(
                private_id, public_identity_xml, initial_filter_xml)
            irs_uuid = str(uuid.uuid4())
            sp_uuid = str(uuid.uuid4())

            # Add the user to the optimized cassandra cache.
            homestead_cache_casscli_file.write(
                create_row_command("impi", private_id))
            homestead_cache_casscli_file.write(
                "SET impi['%s']['digest_ha1'] = '%s';\n" % (private_id, hash))
            homestead_cache_casscli_file.write(
                "SET impi['%s']['digest_realm'] = '%s';\n" %
                (private_id, realm))
            homestead_cache_casscli_file.write(
                "SET impi['%s']['public_id_%s'] = '';\n" %
                (private_id, public_id))

            homestead_cache_casscli_file.write(
                create_row_command("impu", public_id))
            homestead_cache_casscli_file.write(
                "SET impu['%s']['ims_subscription_xml'] = '%s';\n" %
                (public_id, ims_subscription_xml.replace("'", "\\'")))

            # Populate the provisioning tables for the user.
            homestead_prov_casscli_file.write(
                create_row_command("implicit_registration_sets", irs_uuid))
            homestead_prov_casscli_file.write(
                "SET implicit_registration_sets['%s']['service_profile_%s'] = lexicaluuid('%s');\n"
                % (irs_uuid, sp_uuid, sp_uuid))
            homestead_prov_casscli_file.write(
                "SET implicit_registration_sets['%s']['associated_private_%s'] = utf8('%s');\n"
                % (irs_uuid, private_id, private_id))

            homestead_prov_casscli_file.write(
                create_row_command("service_profiles", sp_uuid))
            homestead_prov_casscli_file.write(
                "SET service_profiles['%s']['irs'] = '%s';\n" %
                (sp_uuid, irs_uuid))
            homestead_prov_casscli_file.write(
                "SET service_profiles['%s']['initialfiltercriteria'] = '%s';\n"
                % (sp_uuid, initial_filter_xml))
            homestead_prov_casscli_file.write(
                "SET service_profiles['%s']['public_id_%s'] = utf8('%s');\n" %
                (sp_uuid, public_id, public_id))

            homestead_prov_casscli_file.write(
                create_row_command("public", public_id))
            homestead_prov_casscli_file.write(
                "SET public['%s']['publicidentity'] = '%s';\n" %
                (public_id, public_identity_xml))
            homestead_prov_casscli_file.write(
                "SET public['%s']['service_profile'] = '%s';\n" %
                (public_id, sp_uuid))

            password_to_write = password if write_plaintext_password else ""
            homestead_prov_casscli_file.write(
                create_row_command("private", private_id))
            homestead_prov_casscli_file.write(
                "SET private['%s']['digest_ha1'] = '%s';\n" %
                (private_id, hash))
            homestead_prov_casscli_file.write(
                "SET private['%s']['plaintext_password'] = '******';\n" %
                (private_id, password_to_write))
            homestead_prov_casscli_file.write(
                "SET private['%s']['realm'] = '%s';\n" % (private_id, realm))
            homestead_prov_casscli_file.write(
                "SET private['%s']['associated_irs_%s'] = lexicaluuid('%s');\n"
                % (private_id, irs_uuid, irs_uuid))

    # Make the created .sh files executable
    permissions = stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE
    os.chmod(homestead_filename, permissions)

    print "Generated homestead bulk provisioning scripts"
    print "- %-46s - run this script on Homestead" % (homestead_filename)
    print "- %-46s - copy this file onto Homestead" % (
        homestead_cache_casscli_filename)
    print "- %-46s - copy this file onto Homestead" % (
        homestead_prov_casscli_filename)
예제 #10
0
파일: numbers.py 프로젝트: AiprNick/ellis
    def post(self, username, sip_uri):
        """Allocate a phone number."""
        _log.debug("Specific number allocation API call (%s)", sip_uri)
        self.is_admin_request()
        user_id = self.get_and_check_user_id(username)
        db_sess = self.db_session()
        pstn = self.get_argument("pstn", "false").lower() == "true"
        private_id = self.get_argument("private_id", None)
        new_private_id = self.get_argument("new_private_id", "false").lower() == "true"
        try:
            number_id = uuid.UUID(numbers.get_sip_uri_number_id(db_sess, sip_uri))
        except NotFound:
            # This SIP URI is not currently in the pool, so add it
            number_id = numbers.add_number_to_pool(db_sess, sip_uri, False, True)
        numbers.allocate_specific_number(db_sess, user_id, number_id)
        self.sip_uri = sip_uri
        db_sess.commit()

        # Work out the response we'll send if the upstream requests
        # are successful.
        number = utils.sip_uri_to_phone_number(sip_uri)
        pretty_number = format_phone_number(number)
        self.__response = {
            "sip_uri": sip_uri,
            "sip_username": number,
            "number": number,
            "pstn": pstn,
            "formatted_number": pretty_number,
            "number_id": number_id.hex,
        }

        # Generate a random password and store it in Homestead.
        _log.debug("Populating other servers...")
        self._request_group = HTTPCallbackGroup(self._on_post_success, self._on_post_failure)

        public_callback = self._request_group.callback()

        if private_id == None:
            # No private id was provided, so we need to create a new
            # digest in Homestead
            private_id = utils.sip_public_id_to_private(sip_uri)
            new_private_id = True

        if new_private_id:
            sip_password = utils.generate_sip_password()
            _log.debug("About to create private ID at Homestead")
            homestead.create_private_id(
                private_id, utils.sip_uri_to_domain(sip_uri), sip_password, self._request_group.callback()
            )
            _log.debug("Created private ID at Homestead")

            self.__response["sip_password"] = sip_password
        self.__response["sip_username"] = private_id

        # Associate the new public identity with the private identity in Homestead
        # and store the iFCs in homestead.
        homestead.create_public_id(
            private_id, sip_uri, ifcs.generate_ifcs(utils.sip_uri_to_domain(sip_uri)), public_callback
        )

        self.__response["private_id"] = private_id

        # Concurrently, store the default simservs in XDM.
        with open(settings.XDM_DEFAULT_SIMSERVS_FILE) as xml_file:
            default_xml = xml_file.read()
        xdm.put_simservs(sip_uri, default_xml, self._request_group.callback())
예제 #11
0
Each row in the input CSV file describes a user, and must contain 4 columns:
- public SIP ID
- private SIP ID
- realm
- password
If you have a CSV file with fewer columns, you can autocomplete the remaining
columns using the bulk_autocomplete.py script.
"""

import sys, string, csv
from metaswitch.crest import settings
from metaswitch.common import utils
from metaswitch.common import ifcs

INITIAL_FILTER_CRITERIA = ifcs.generate_ifcs(settings.SIP_DIGEST_REALM)
with open(settings.XDM_DEFAULT_SIMSERVS_FILE, "rb") as simservs_file:
    SIMSERVS = simservs_file.read()

def standalone():
    if len(sys.argv) != 2:
        print USAGE
        return
    csv_filename = sys.argv[1]
    csv_filename_prefix = string.replace(csv_filename, ".csv", "")
    homestead_filename = "%s.create_homestead.sh" % (csv_filename_prefix,)
    homestead_cqlsh_filename = "%s.create_homestead.cqlsh" % (csv_filename_prefix,)
    xdm_filename = "%s.create_xdm.sh" % (csv_filename_prefix,)
    xdm_cqlsh_filename = "%s.create_xdm.cqlsh" % (csv_filename_prefix,)
    print "Generating bulk provisioning scripts for users in %s..." % (csv_filename,)
    try:
예제 #12
0
def write_homestead_scripts(csv_filename, write_plaintext_password):
    csv_filename_prefix = string.replace(csv_filename, ".csv", "")
    homestead_filename = "%s.create_homestead.sh" % (csv_filename_prefix)
    homestead_prov_casscli_filename = "%s.create_homestead_provisioning.casscli" % (csv_filename_prefix)
    homestead_cache_casscli_filename = "%s.create_homestead_cache.casscli" % (csv_filename_prefix)

    with open(homestead_filename, 'w') as homestead_file, \
         open(homestead_cache_casscli_filename, 'w') as homestead_cache_casscli_file, \
         open(homestead_prov_casscli_filename, 'w') as homestead_prov_casscli_file:

        # Write Homestead/cassandra-cli header
        homestead_file.write("#!/bin/bash\n")
        homestead_file.write("# Homestead bulk provisioning script for users in %s\n" % (csv_filename))
        homestead_file.write("# Run this script on any node in your Homestead deployment to create the users\n")
        homestead_file.write("# The %s and %s files must also be present on this system\n" % (homestead_cache_casscli_filename, homestead_prov_casscli_filename))
        homestead_file.write("\n")
        homestead_file.write("[ -f %s ] || echo \"The %s file must be present on this system.\"\n" % (homestead_cache_casscli_filename, homestead_cache_casscli_filename))
        homestead_file.write("[ -f %s ] || echo \"The %s file must be present on this system.\"\n" % (homestead_prov_casscli_filename, homestead_prov_casscli_filename))
        homestead_file.write("cassandra-cli -B -f %s\n" % (homestead_cache_casscli_filename))
        homestead_file.write("cassandra-cli -B -f %s\n" % (homestead_prov_casscli_filename))
        homestead_cache_casscli_file.write("USE homestead_cache;\n")
        homestead_prov_casscli_file.write("USE homestead_provisioning;\n")

        for public_id, private_id, realm, password in csv_iterator(csv_filename):

            # Generate the user-specific data
            hash = utils.md5("%s:%s:%s" % (private_id, realm, password))

            public_identity_xml = "<PublicIdentity><Identity>%s</Identity></PublicIdentity>" % public_id
            initial_filter_xml = ifcs.generate_ifcs(utils.sip_uri_to_domain(public_id))
            ims_subscription_xml = create_imssubscription_xml(private_id, public_identity_xml, initial_filter_xml)
            irs_uuid = str(uuid.uuid4())
            sp_uuid = str(uuid.uuid4())

            # Add the user to the optimized cassandra cache.
            homestead_cache_casscli_file.write(
                create_row_command("impi", private_id))
            homestead_cache_casscli_file.write(
                "SET impi['%s']['digest_ha1'] = '%s';\n" % (private_id, hash))
            homestead_cache_casscli_file.write(
                "SET impi['%s']['digest_realm'] = '%s';\n" % (private_id, realm))
            homestead_cache_casscli_file.write(
                "SET impi['%s']['public_id_%s'] = '';\n" % (private_id,
                                                            public_id))

            homestead_cache_casscli_file.write(
                create_row_command("impu", public_id))
            homestead_cache_casscli_file.write(
                "SET impu['%s']['ims_subscription_xml'] = '%s';\n" % (
                    public_id,
                    ims_subscription_xml.replace("'", "\\'")))

            # Populate the provisioning tables for the user.
            homestead_prov_casscli_file.write(
                create_row_command("implicit_registration_sets", irs_uuid))
            homestead_prov_casscli_file.write(
                "SET implicit_registration_sets['%s']['service_profile_%s'] = lexicaluuid('%s');\n" % (irs_uuid,
                                                                                                       sp_uuid,
                                                                                                       sp_uuid))
            homestead_prov_casscli_file.write(
                "SET implicit_registration_sets['%s']['associated_private_%s'] = utf8('%s');\n" % (irs_uuid,
                                                                                                   private_id,
                                                                                                   private_id))

            homestead_prov_casscli_file.write(
                create_row_command("service_profiles", sp_uuid))
            homestead_prov_casscli_file.write(
                "SET service_profiles['%s']['irs'] = '%s';\n" % (sp_uuid,
                                                                 irs_uuid))
            homestead_prov_casscli_file.write(
                "SET service_profiles['%s']['initialfiltercriteria'] = '%s';\n" % (sp_uuid,
                                                                                   initial_filter_xml))
            homestead_prov_casscli_file.write(
                "SET service_profiles['%s']['public_id_%s'] = utf8('%s');\n" % (sp_uuid,
                                                                                public_id,
                                                                                public_id))

            homestead_prov_casscli_file.write(
                create_row_command("public", public_id))
            homestead_prov_casscli_file.write(
                "SET public['%s']['publicidentity'] = '%s';\n" % (public_id,
                                                                  public_identity_xml))
            homestead_prov_casscli_file.write(
                "SET public['%s']['service_profile'] = '%s';\n" % (public_id,
                                                                   sp_uuid))

            password_to_write = password if write_plaintext_password else ""
            homestead_prov_casscli_file.write(
                create_row_command("private", private_id))
            homestead_prov_casscli_file.write(
                "SET private['%s']['digest_ha1'] = '%s';\n" % (private_id,
                                                               hash))
            homestead_prov_casscli_file.write(
                "SET private['%s']['plaintext_password'] = '******';\n" % (private_id,
                                                                       password_to_write))
            homestead_prov_casscli_file.write(
                "SET private['%s']['realm'] = '%s';\n" % (private_id, realm))
            homestead_prov_casscli_file.write(
                "SET private['%s']['associated_irs_%s'] = lexicaluuid('%s');\n" % (private_id,
                                                                                   irs_uuid,
                                                                                   irs_uuid))

    # Make the created .sh files executable
    permissions = stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE
    os.chmod(homestead_filename, permissions)

    print "Generated homestead bulk provisioning scripts"
    print "- %-46s - run this script on Homestead" % (homestead_filename)
    print "- %-46s - copy this file onto Homestead" % (homestead_cache_casscli_filename)
    print "- %-46s - copy this file onto Homestead" % (homestead_prov_casscli_filename)
예제 #13
0
파일: numbers.py 프로젝트: vitosans/ellis
    def post(self, username, sip_uri):  # pragma: no cover
        """Allocate a phone number."""
        _log.debug("Specific number allocation API call (%s)", sip_uri)
        self.is_admin_request()
        user_id = self.get_and_check_user_id(username)
        db_sess = self.db_session()
        pstn = self.get_argument('pstn', 'false').lower() == 'true'
        private_id = self.get_argument('private_id', None)
        new_private_id = self.get_argument('new_private_id',
                                           'false').lower() == 'true'
        try:
            number_id = uuid.UUID(
                numbers.get_sip_uri_number_id(db_sess, sip_uri))
        except NotFound:
            # This SIP URI is not currently in the pool, so add it
            number_id = numbers.add_number_to_pool(db_sess, sip_uri, False,
                                                   True)
        numbers.allocate_specific_number(db_sess, user_id, number_id)
        self.sip_uri = sip_uri
        db_sess.commit()

        # Work out the response we'll send if the upstream requests
        # are successful.
        number = utils.sip_uri_to_phone_number(sip_uri)
        pretty_number = format_phone_number(number)
        self.__response = {
            "sip_uri": sip_uri,
            "sip_username": number,
            "number": number,
            "pstn": pstn,
            "formatted_number": pretty_number,
            "number_id": number_id.hex
        }

        # Generate a random password and store it in Homestead.
        _log.debug("Populating other servers...")
        self._request_group = HTTPCallbackGroup(self._on_post_success,
                                                self._on_post_failure)

        public_callback = self._request_group.callback()

        if private_id == None:
            # No private id was provided, so we need to create a new
            # digest in Homestead
            private_id = utils.sip_public_id_to_private(sip_uri)
            new_private_id = True

        if new_private_id:
            sip_password = utils.generate_sip_password()
            _log.debug("About to create private ID at Homestead")
            homestead.create_private_id(private_id,
                                        utils.sip_uri_to_domain(sip_uri),
                                        sip_password,
                                        self._request_group.callback())
            _log.debug("Created private ID at Homestead")

            self.__response["sip_password"] = sip_password
        self.__response["sip_username"] = private_id

        # Associate the new public identity with the private identity in Homestead
        # and store the iFCs in homestead.
        homestead.create_public_id(
            private_id, sip_uri,
            ifcs.generate_ifcs(utils.sip_uri_to_domain(sip_uri)),
            public_callback)

        self.__response["private_id"] = private_id

        # Concurrently, store the default simservs in XDM.
        xdm.put_simservs(sip_uri, simservs.default_simservs(),
                         self._request_group.callback())
예제 #14
0
파일: numbers.py 프로젝트: vitosans/ellis
    def post(self, username):
        """Allocate a phone number."""
        _log.debug("Number allocation API call (PSTN = %s)",
                   self.get_argument('pstn', 'false'))
        user_id = self.get_and_check_user_id(username)
        db_sess = self.db_session()
        pstn = self.get_argument('pstn', 'false').lower() == 'true'
        private_id = self.get_argument('private_id', None)
        try:
            number_id = numbers.allocate_number(db_sess, user_id, pstn)
            sip_uri = numbers.get_number(db_sess, number_id, user_id)
            self.sip_uri = sip_uri
            _log.debug("SIP URI %s", sip_uri)
            # FIXME We shouldn't commit until we know XDM/HS have succeeded but
            # if we hold the transaction open we can deadlock
            # * Request 1 comes in and allocates a number, kicks off requests
            #   to XDM/Homestead, has transaction open, returns thread to Tornado
            # * Request 2 comes in, allocates same number, can't lock it for
            #   update because Request 1 is holding it.  Blocks.
            # * Request 1 gets response but the thread is tied up
            # * Request 2 SQL transaction times out.
            # * Request 1 probably completes..
            db_sess.commit()
        except NotFound:  # pragma: no cover
            # FIXME email operator to tell them we're out of numbers!
            db_sess.rollback()
            _log.warning("No available numbers")
            raise HTTPError(httplib.SERVICE_UNAVAILABLE,
                            "No available numbers")

        # Work out the response we'll send if the upstream requests
        # are successful.
        number = utils.sip_uri_to_phone_number(sip_uri)
        pretty_number = format_phone_number(number)
        self.__response = {
            "sip_uri": sip_uri,
            "sip_username": number,
            "number": number,
            "pstn": pstn,
            "formatted_number": pretty_number,
            "number_id": number_id.hex
        }

        # Generate a random password and store it in Homestead.
        _log.debug("Populating other servers...")
        self._request_group = HTTPCallbackGroup(self._on_post_success,
                                                self._on_post_failure)

        public_callback = self._request_group.callback()

        if private_id == None:
            # No private id was provided, so we need to create a new
            # digest in Homestead
            private_id = utils.sip_public_id_to_private(sip_uri)
            sip_password = utils.generate_sip_password()
            _log.debug("About to create private ID at Homestead")
            homestead.create_private_id(private_id,
                                        utils.sip_uri_to_domain(sip_uri),
                                        sip_password,
                                        self._request_group.callback())
            _log.debug("Created private ID at Homestead")
            self.__response["sip_password"] = sip_password

        # Associate the new public identity with the private identity in Homestead
        # and store the iFCs in homestead.
        homestead.create_public_id(
            private_id, sip_uri,
            ifcs.generate_ifcs(utils.sip_uri_to_domain(sip_uri)),
            public_callback)

        self.__response["private_id"] = private_id

        # Concurrently, store the default simservs in XDM.
        xdm.put_simservs(sip_uri, simservs.default_simservs(),
                         self._request_group.callback())