Exemple #1
0
    def delete(self, delete_devices=False):
        self.prep_attributes()

        if delete_devices and len(self.devices) == 0:
            self.load_devices()

        if self.sip_user_id is None:
            raise ValueError("can't call Account.delete() without a value for sip_user_id")

        # going to do this as a compound request so that it's pseudo-atomic...if one fails, the rest should
        # fail, regardless of where in the process that failure occurs
        b = BroadsoftRequest()
        self.inject_broadsoftinstance(child=b)

        # build XML to delete user
        user = UserDeleteRequest(sip_user_id=self.sip_user_id)
        b.commands = [user]

        # -- doing no device management in broadsoft, therefore no need for
        # -- "clear the decks behavior"...create device. Exists already? Fine.
        # for each device, add XML for device deletion
        # for d in self.devices:
        #    b.commands.append(d.delete(bundle=True))

        b.post()
        return [b]
Exemple #2
0
    def build_provision_request(self):
        # going to do this as a compound request so that it's pseudo-atomic...if one fails, the rest should
        # fail, regardless of where in the process that failure occurs
        b = BroadsoftRequest()
        self.inject_broadsoftinstance(child=b)

        # object to create the user
        u_add = UserAddRequest()
        self.inject_broadsoftinstance(child=u_add)
        u_add.first_name = self.first_name
        u_add.last_name = self.last_name
        u_add.did = self.did
        u_add.kname = self.kname
        u_add.sip_user_id = self.sip_user_id
        u_add.sip_password = self.sip_password
        u_add.email = self.email
        b.commands = [u_add]

        # if there are services to add for user, add them
        self.add_services(req_object=b)

        # if there are devices to add for user, add them
        self.add_devices(req_object=b)

        # default settings for all SCAs, set once per account
        self.configure_sca_settings(req_object=b)

        # set authentication creds
        self.set_auth_creds(req_object=b)

        return b
Exemple #3
0
    def load_devices(self):
        # if there's no XML for the user, fetch entire User. Primary device will be in User record, rest found by
        # searching for shared call appearances. Since .fetch() calls .load_devices(), will wind up back here.
        if self.xml is None:
            self.fetch()

        # if there is XML for the user...
        else:
            # first, any that were directly in xml
            for ade in self.xml.findall('./command/accessDeviceEndpoint'):
                d = Device()
                self.inject_broadsoftinstance(child=d)
                # the <accessDeviceEndpoint> gives us enough info to actually fetch the device
                d.bootstrap_access_device_endpoint(ade=ade)
                d.fetch(target_name=d.name)
                self.devices.append(d)

            # now find any shared call appearances
            sca_xml = UserSharedCallAppearanceGetRequest.get_devices(sip_user_id=self.sip_user_id,
                                                                     broadsoftinstance=self.broadsoftinstance)
            scas = BroadsoftRequest.convert_results_table(xml=sca_xml)
            for sca in scas:
                d = Device()
                self.inject_broadsoftinstance(child=d)
                # the shared call appearance listings give us nearly everything about a device, but we run a fetch as well
                # to get everything
                d.bootstrap_shared_call_appearance(sca=sca)
                d.fetch(target_name=d.name)
                self.devices.append(d)
Exemple #4
0
    def test_set_password_deriving_sip_user_name(
            self, device_mod_patch, post_patch
    ):
        b = BroadsoftRequest()

        # just a did
        d = Device(name='devicename')
        d.set_password(did=6175551212, sip_password='******')

        call = device_mod_patch.call_args_list[0]
        args, kwargs = call
        self.assertEqual('6175551212@' + d.broadsoftinstance.default_domain, kwargs['sip_user_name'])

        # just a sip_user_name
        d = Device(name='devicename')
        d.set_password(sip_user_name='*****@*****.**', sip_password='******')

        call = device_mod_patch.call_args_list[1]
        args, kwargs = call
        self.assertEqual('*****@*****.**', kwargs['sip_user_name'])

        # both; sip_user_name should win
        d = Device(name='devicename')
        d.set_password(did=6175551212, sip_user_name='*****@*****.**', sip_password='******')

        call = device_mod_patch.call_args_list[2]
        args, kwargs = call
        self.assertEqual('*****@*****.**', kwargs['sip_user_name'])
Exemple #5
0
    def activate_voicemail(self, type=None, voicemail_object=None):
        if not self.sip_user_id:
            raise ValueError("can't call Account.activate_unity_voicemail without a value for sip_user_id")

        # no type provided? inherit from object.
        if type is None:
            type = self.voicemail

        # user didn't specify a custom Voicemail object? Instantiate the default for the given type.
        if voicemail_object is None:
            voicemail_object = Voicemail(type=type, broadsoftinstance=self.broadsoftinstance,
                                         logging_level=self.logging_level)

        # get email, sip_user_id, and mwi into voicemail object, whether constructed or passed
        if voicemail_object.email is None:
            voicemail_object.email = self.email
        if voicemail_object.sip_user_id is None:
            voicemail_object.sip_user_id = self.sip_user_id
        if voicemail_object.mwi is None:
            voicemail_object.mwi = self.voicemail_mwi
        if voicemail_object.sip_password is None:
            voicemail_object.sip_password = self.sip_password
        if voicemail_object.did is None:
            voicemail_object.did = self.did

        # going to do this as a compound request so that it's pseudo-atomic...if one fails, the rest should
        # fail, regardless of where in the process that failure occurs
        b = BroadsoftRequest()
        self.inject_broadsoftinstance(child=b)

        # build XML to activate chosen voicemail system
        # makes more sense to deactivate counterpart first, but this is the step that's more likely to fail, so might
        # as well put it first
        activate = voicemail_object.build_activate_command()

        # build XML to deactivate counterpart
        deactivate = voicemail_object.build_deactivate_counterpart_command()

        b.commands = activate + deactivate
        b.post()
        return [b]
    def derive_sip_user_id(self, did):
        did = BroadsoftRequest.convert_phone_number(number=did)

        if not did:
            raise ValueError(
                "can't run BroadsoftObject.derive_sip_user_id without a value for did"
            )

        if not self.broadsoftinstance.default_domain:
            raise ValueError(
                "can't run BroadsoftObject.derive_sip_user_id without a value for default_domain"
            )

        return did + '@' + self.broadsoftinstance.default_domain
    def prep_attributes(self):
        if self.broadsoftinstance is None:
            self.broadsoftinstance = self.derive_broadsoft_instance(
                instance=self.instance)

        if hasattr(self, 'did') and self.did:
            self.did = BroadsoftRequest.convert_phone_number(number=self.did)

        if hasattr(self,
                   'sip_user_id') and self.did and self.sip_user_id is None:
            self.sip_user_id = self.derive_sip_user_id(did=self.did)

        if self.xml and type(self.xml) is str:
            self.xml = ET.fromstring(self.xml)

        if hasattr(self, 'kname') and hasattr(
                self,
                'email') and self.kname is not None and self.email is None:
            self.email = self.kname + '@mit.edu'
 def login(self):
     r = BroadsoftRequest(broadsoftinstance=self.broadsoftinstance)
     r.authenticate_and_login()