def create_server(self, server):
        """
        Create a server and its storages based on a (locally created) Server object.

        Populates the given Server instance with the API response.

        0.3.0: also supports giving the entire POST body as a dict that is directly
        serialised into JSON. Refer to the REST API documentation for correct format.

        Example:
        server1 = Server( core_number = 1,
              memory_amount = 512,
              hostname = "my.example.1",
              zone = ZONE.London,
              storage_devices = [
                Storage(os = "Ubuntu 14.04", size=10, tier=maxiops, title='The OS drive'),
                Storage(size=10),
                Storage()
              title = "My Example Server"
            ])
        manager.create_server(server1)

        One storage should contain an OS. Otherwise storage fields are optional.
        - size defaults to 10,
        - title defaults to hostname + " OS disk" and hostname + " storage disk id"
          (id is a running starting from 1)
        - tier defaults to maxiops
        - valid operating systems are:
          "CentOS 6.5", "CentOS 7.0"
          "Debian 7.8"
          "Ubuntu 12.04", "Ubuntu 14.04"
          "Windows 2003","Windows 2008" ,"Windows 2012"
        """
        if isinstance(server, Server):
            body = server.prepare_post_body()
        else:
            server = Server._create_server_obj(server, cloud_manager=self)
            body = server.prepare_post_body()

        res = self.post_request('/server', body)

        server_to_return = server
        server_to_return._reset(
            res['server'],
            cloud_manager=self,
            populated=True
        )
        return server_to_return
Exemple #2
0
    def create_server(self, server):
        """
        Create a server and its storages based on a (locally created) Server object.

        Populates the given Server instance with the API response.

        0.3.0: also supports giving the entire POST body as a dict that is directly
        serialised into JSON. Refer to the REST API documentation for correct format.

        Example:
        server1 = Server( core_number = 1,
              memory_amount = 512,
              hostname = "my.example.1",
              zone = ZONE.London,
              storage_devices = [
                Storage(os = "Ubuntu 14.04", size=10, tier=maxiops, title='The OS drive'),
                Storage(size=10),
                Storage()
              title = "My Example Server"
            ])
        manager.create_server(server1)

        One storage should contain an OS. Otherwise storage fields are optional.
        - size defaults to 10,
        - title defaults to hostname + " OS disk" and hostname + " storage disk id"
          (id is a running starting from 1)
        - tier defaults to maxiops
        - valid operating systems are:
          "CentOS 6.5", "CentOS 7.0"
          "Debian 7.8"
          "Ubuntu 12.04", "Ubuntu 14.04"
          "Windows 2003","Windows 2008" ,"Windows 2012"
        """
        if isinstance(server, Server):
            body = server.prepare_post_body()
        else:
            server = Server._create_server_obj(server, cloud_manager=self)
            body = server.prepare_post_body()

        res = self.post_request('/server', body)

        server_to_return = server
        server_to_return._reset(res['server'],
                                cloud_manager=self,
                                populated=True)
        return server_to_return
Exemple #3
0
    def test_server_prepare_post_body_optional_attributes(self):
        server1 = Server(
            core_number=2,
            memory_amount=1024,
            hostname='my.example.com',
            zone='us-chi1',
            storage_devices=[
                Storage(
                    os='01000000-0000-4000-8000-000030200200',
                    size=10
                )
            ],
            vnc_password='******',
            password_delivery='email',
            login_user=login_user_block('upclouduser', ['this-is-a-SSH-key']),
            avoid_host='12345678',
            user_data='https://my.script.com/some_script.py',
            ip_addresses = [
                IPAddress(family='IPv4', access='public'),
                IPAddress(family='IPv6', access='public')
            ]
        )


        server2_dict = {
            'core_number':2,
            'memory_amount':1024,
            'hostname':'my.example.com',
            'zone': 'us-chi1',
            'storage_devices':[
                {'os': '01000000-0000-4000-8000-000030200200', 'size': 10}
            ],
            'vnc_password': '******',
            'password_delivery': 'email',
            'login_user': login_user_block('upclouduser', ['this-is-a-SSH-key']),
            'avoid_host': '12345678',
            'user_data': 'https://my.script.com/some_script.py',
            'ip_addresses': [
                {'family':'IPv4', 'access':'public'},
                {'family':'IPv6', 'access':'public'}
            ]
        }
        server2 = Server._create_server_obj(server2_dict, cloud_manager=self)

        body1 = server1.prepare_post_body()
        body2 = server2.prepare_post_body()


        for body in [body1, body2]:
            assert body['server']['title'] == 'my.example.com'
            assert body['server']['core_number'] == 2
            assert body['server']['memory_amount'] == 1024
            assert body['server']['hostname'] == server1.title
            assert body['server']['zone'] == 'us-chi1'
            assert body['server']['vnc_password'] == 'my-passwd'
            assert body['server']['password_delivery'] == 'email'
            assert body['server']['login_user'] == {
                'username': '******',
                'create_password': '******',
                'ssh_keys': {
                    'ssh_key': ['this-is-a-SSH-key']
                }
            }
            assert body['server']['avoid_host'] == '12345678'
            assert body['server']['user_data'] == 'https://my.script.com/some_script.py'
            assert body['server']['ip_addresses'] == {
                'ip_address': [
                    {'family': 'IPv4', 'access': 'public'},
                    {'family': 'IPv6', 'access': 'public'}
                ]
            }
Exemple #4
0
 def create_server(self, server):
     return Server._create_server_obj(server, cloud_manager=self)