コード例 #1
0
ファイル: test_upcloud.py プロジェクト: stirlab/libcloud
 def test_creating_node_from_template_image(self):
     body = UpcloudCreateNodeRequestBody(name='ts',
                                         image=self.image,
                                         location=self.location,
                                         size=self.size)
     json_body = body.to_json()
     dict_body = json.loads(json_body)
     expected_body = {
         'server': {
             'title': 'ts',
             'hostname': 'localhost',
             'plan': '1xCPU-1GB',
             'zone': 'fi-hel1',
             'login_user': {
                 'username': '******',
                 'create_password': '******'
             },
             'storage_devices': {
                 'storage_device': [{
                     'action': 'clone',
                     'title': 'Ubuntu Server 16.04 LTS (Xenial Xerus)',
                     'storage': '01000000-0000-4000-8000-000030060200',
                     'size': 30,
                     'tier': 'maxiops',
                 }]
             },
         }
     }
     self.assertDictEqual(expected_body, dict_body)
コード例 #2
0
ファイル: test_upcloud.py プロジェクト: wandera/libcloud
 def test_creating_node_from_template_image(self):
     body = UpcloudCreateNodeRequestBody(name="ts",
                                         image=self.image,
                                         location=self.location,
                                         size=self.size)
     json_body = body.to_json()
     dict_body = json.loads(json_body)
     expected_body = {
         "server": {
             "title": "ts",
             "hostname": "localhost",
             "plan": "1xCPU-1GB",
             "zone": "fi-hel1",
             "login_user": {
                 "username": "******",
                 "create_password": "******"
             },
             "storage_devices": {
                 "storage_device": [{
                     "action": "clone",
                     "title": "Ubuntu Server 16.04 LTS (Xenial Xerus)",
                     "storage": "01000000-0000-4000-8000-000030060200",
                     "size": 30,
                     "tier": "maxiops",
                 }]
             },
         }
     }
     self.assertDictEqual(expected_body, dict_body)
コード例 #3
0
    def create_node(
        self,
        name,
        size,
        image,
        location,
        auth=None,
        ex_hostname="localhost",
        ex_username="******",
    ):
        """
        Creates instance to upcloud.

        If auth is not given then password will be generated.

        :param name:   String with a name for this new node (required)
        :type name:   ``str``

        :param size:   The size of resources allocated to this node.
                            (required)
        :type size:   :class:`.NodeSize`

        :param image:  OS Image to boot on node. (required)
        :type image:  :class:`.NodeImage`

        :param location: Which data center to create a node in. If empty,
                              undefined behavior will be selected. (optional)
        :type location: :class:`.NodeLocation`

        :param auth:   Initial authentication information for the node
                            (optional)
        :type auth:   :class:`.NodeAuthSSHKey`

        :param ex_hostname: Hostname. Default is 'localhost'. (optional)
        :type ex_hostname: ``str``

        :param ex_username: User's username, which is created.
                            Default is 'root'. (optional)
        :type ex_username: ``str``

        :return: The newly created node.
        :rtype: :class:`.Node`
        """
        body = UpcloudCreateNodeRequestBody(
            name=name,
            size=size,
            image=image,
            location=location,
            auth=auth,
            ex_hostname=ex_hostname,
            ex_username=ex_username,
        )
        response = self.connection.request(
            "1.2/server", method="POST", data=body.to_json()
        )
        server = response.object["server"]
        # Upcloud server's are in maintenace state when goind
        # from state to other, it is safe to assume STARTING state
        return self._to_node(server, state=NodeState.STARTING)
コード例 #4
0
ファイル: test_upcloud.py プロジェクト: stirlab/libcloud
    def test_creating_node_with_non_default_username(self):
        body = UpcloudCreateNodeRequestBody(name='ts',
                                            image=self.image,
                                            location=self.location,
                                            size=self.size,
                                            ex_username='******')
        json_body = body.to_json()
        dict_body = json.loads(json_body)

        login_user = dict_body['server']['login_user']
        self.assertDictEqual({
            'username': '******',
            'create_password': '******'
        }, login_user)
コード例 #5
0
ファイル: test_upcloud.py プロジェクト: wandera/libcloud
    def test_creating_node_with_non_default_username(self):
        body = UpcloudCreateNodeRequestBody(
            name="ts",
            image=self.image,
            location=self.location,
            size=self.size,
            ex_username="******",
        )
        json_body = body.to_json()
        dict_body = json.loads(json_body)

        login_user = dict_body["server"]["login_user"]
        self.assertDictEqual({
            "username": "******",
            "create_password": "******"
        }, login_user)
コード例 #6
0
ファイル: test_upcloud.py プロジェクト: wandera/libcloud
    def test_creating_node_using_ssh_keys(self):
        auth = NodeAuthSSHKey("sshkey")

        body = UpcloudCreateNodeRequestBody(
            name="ts",
            image=self.image,
            location=self.location,
            size=self.size,
            auth=auth,
        )
        json_body = body.to_json()
        dict_body = json.loads(json_body)
        expected_body = {
            "server": {
                "title": "ts",
                "hostname": "localhost",
                "plan": "1xCPU-1GB",
                "zone": "fi-hel1",
                "login_user": {
                    "username": "******",
                    "ssh_keys": {
                        "ssh_key": ["sshkey"]
                    },
                },
                "storage_devices": {
                    "storage_device": [{
                        "action":
                        "clone",
                        "size":
                        30,
                        "title":
                        "Ubuntu Server 16.04 LTS (Xenial Xerus)",
                        "tier":
                        "maxiops",
                        "storage":
                        "01000000-0000-4000-8000-000030060200",
                    }]
                },
            }
        }
        self.assertDictEqual(expected_body, dict_body)
コード例 #7
0
ファイル: test_upcloud.py プロジェクト: stirlab/libcloud
    def test_creating_node_using_ssh_keys(self):
        auth = NodeAuthSSHKey('sshkey')

        body = UpcloudCreateNodeRequestBody(name='ts',
                                            image=self.image,
                                            location=self.location,
                                            size=self.size,
                                            auth=auth)
        json_body = body.to_json()
        dict_body = json.loads(json_body)
        expected_body = {
            'server': {
                'title': 'ts',
                'hostname': 'localhost',
                'plan': '1xCPU-1GB',
                'zone': 'fi-hel1',
                'login_user': {
                    'username': '******',
                    'ssh_keys': {
                        'ssh_key': ['sshkey']
                    },
                },
                'storage_devices': {
                    'storage_device': [{
                        'action':
                        'clone',
                        'size':
                        30,
                        'title':
                        'Ubuntu Server 16.04 LTS (Xenial Xerus)',
                        'tier':
                        'maxiops',
                        'storage':
                        '01000000-0000-4000-8000-000030060200'
                    }]
                },
            }
        }
        self.assertDictEqual(expected_body, dict_body)