Example #1
0
    def initial_contact(
        self,
        enable_ssh=True,
        time_zone=None,
        keyboard=None,
        install_on_server=None,
        filename=None,
        as_base64=False,
    ):
        """
        Allows to save the initial contact for for the specified node

        :param bool enable_ssh: flag to know if we allow the ssh daemon on the
               specified node
        :param str time_zone: optional time zone to set on the specified node
        :param str keyboard: optional keyboard to set on the specified node
        :param bool install_on_server: optional flag to know if the generated
            configuration needs to be installed on SMC Install server
            (POS is needed)
        :param str filename: filename to save initial_contact to
        :param bool as_base64: return the initial config in base 64 format. Useful
            for cloud based engine deployments as userdata
        :raises NodeCommandFailed: IOError handling initial configuration data
        :return: initial contact text information
        :rtype: str
        """
        result = self.make_request(
            NodeCommandFailed,
            method="create",
            raw_result=True,
            resource="initial_contact",
            params={"enable_ssh": enable_ssh},
        )

        if result.content:
            if as_base64:
                result.content = b64encode(result.content)

            if filename:
                try:
                    save_to_file(filename, result.content)
                except IOError as e:
                    raise NodeCommandFailed(
                        "Error occurred when attempting to save initial "
                        "contact to file: {}".format(e))
        return result.content
    def export_certificate(self, filename=None):
        """
        Export the certificate. Returned certificate will be in string
        format. If filename is provided, the certificate will also be saved
        to the file specified.
        
        :raises CertificateExportError: error exporting certificate
        :rtype: str or None
        """
        result = self.make_request(CertificateExportError,
                                   raw_result=True,
                                   resource='certificate_export')

        if filename is not None:
            save_to_file(filename, result.content)
            return

        return result.content
Example #3
0
 def export_certificate(self, filename=None):
     """
     Export the certificate. Returned certificate will be in string
     format. If filename is provided, the certificate will also be saved
     to the file specified.
     
     :raises CertificateExportError: error exporting certificate
     :rtype: str or None
     """
     result = self.make_request(
         CertificateExportError,
         raw_result=True,
         resource='certificate_export')
         
     if filename is not None:
         save_to_file(filename, result.content)
         return
 
     return result.content
Example #4
0
    def initial_contact(self, enable_ssh=True, time_zone=None,
                        keyboard=None,
                        install_on_server=None,
                        filename=None,
                        as_base64=False):
        """
        Allows to save the initial contact for for the specified node

        :param bool enable_ssh: flag to know if we allow the ssh daemon on the
               specified node
        :param str time_zone: optional time zone to set on the specified node
        :param str keyboard: optional keyboard to set on the specified node
        :param bool install_on_server: optional flag to know if the generated
            configuration needs to be installed on SMC Install server
            (POS is needed)
        :param str filename: filename to save initial_contact to
        :param bool as_base64: return the initial config in base 64 format. Useful
            for cloud based engine deployments as userdata
        :raises NodeCommandFailed: IOError handling initial configuration data
        :return: initial contact text information
        :rtype: str
        """
        result = self.make_request(
            NodeCommandFailed,
            method='create',
            raw_result=True,
            resource='initial_contact',
            params={'enable_ssh': enable_ssh})
        
        if result.content:
            if as_base64:
                result.content = b64encode(result.content)
                    
            if filename:
                try:
                    save_to_file(filename, result.content)
                except IOError as e:
                    raise NodeCommandFailed(
                        'Error occurred when attempting to save initial '
                        'contact to file: {}'.format(e))
        return result.content
Example #5
0
    def initial_contact(self,
                        enable_ssh=True,
                        time_zone=None,
                        keyboard=None,
                        install_on_server=None,
                        filename=None):
        """ 
        Allows to save the initial contact for for the specified node
 
        :param boolean enable_ssh: flag to know if we allow the ssh daemon on the 
               specified node
        :param str time_zone: optional time zone to set on the specified node 
        :param str keyboard: optional keyboard to set on the specified node
        :param boolean install_on_server: optional flag to know if the generated configuration 
               needs to be installed on SMC Install server (POS is needed)
        :param str filename: filename to save initial_contact to
        :return: str initial contact text information
        :raises: :py:class:`smc.api.exceptions.NodeCommandFailed` 
        """
        try:
            result = prepared_request(href=self._link('initial_contact'),
                                      params={
                                          'enable_ssh': enable_ssh
                                      }).create()
            if result.content:
                if filename:
                    try:
                        save_to_file(filename, result.content)
                    except IOError as e:
                        raise NodeCommandFailed(
                            "Error occurred when attempting to "
                            "save initial contact to file: {}".format(e))
            return result.content
        except ResourceNotFound:
            raise NodeCommandFailed(
                'Initial contact not supported on this node type')
Example #6
0
 def test_save_to_bad_file(self):
     # Invalid file
     self.assertRaises(IOError, lambda: save_to_file('foo/efwef/', 'foo'))
Example #7
0
 def test_save_to_file(self):
     # Valid
     self.assertIsNone(save_to_file('blah', 'foo'))