def test_ip_in_server_creation(self): """IPAddress in server creation. https://www.upcloud.com/api/8-servers/#create-server """ ip1 = IPAddress(family='IPv4', access='public') ip2 = IPAddress(family='IPv6', access='private') assert ip1.to_dict() == {'family': 'IPv4', 'access': 'public'} assert ip2.to_dict() == {'family': 'IPv6', 'access': 'private'}
def attach_ip(self, server, family='IPv4'): """ Attach a new (random) IPAddress to the given server (object or UUID). """ body = {'ip_address': {'server': str(server), 'family': family}} res = self.post_request('/ip_address', body) return IPAddress(cloud_manager=self, **res['ip_address'])
def get_ip(self, address): """ Get an IPAddress object with the IP address (string) from the API. e.g manager.get_ip('80.69.175.210') """ res = self.get_request('/ip_address/' + address) return IPAddress(cloud_manager=self, **res['ip_address'])
def modify_ip(self, ip_addr, ptr_record): """ Modify an IP address' ptr-record (Reverse DNS). Accepts an IPAddress instance (object) or its address (string). """ body = {'ip_address': {'ptr_record': ptr_record}} res = self.put_request('/ip_address/' + str(ip_addr), body) return IPAddress(cloud_manager=self, **res['ip_address'])
def test_ip_details(self): """IPAdress LIST/GET. https://www.upcloud.com/api/10-ip-addresses/#list-ip-addresses """ ip = IPAddress(**json.loads( read_from_file('ip_address_10.1.0.101.json'))['ip_address']) assert ip.to_dict() == { 'access': 'private', 'address': '10.1.0.101', 'family': 'IPv4', 'part_of_plan': 'yes', 'ptr_record': 'a.ptr.record', 'server': '008c365d-d307-4501-8efc-cd6d3bb0e494' }
def test_ip_in_server_details(self): """IPAddress in server details. https://www.upcloud.com/api/8-servers/#get-server-details """ ip = IPAddress(access='private', address='10.0.0.0', family='IPv4') assert ip.to_dict() == { 'access': 'private', 'address': '10.0.0.0', 'family': 'IPv4' } data = read_from_file( 'server_00798b85-efdc-41ca-8021-f6ef457b8531.json') s = Server(**json.loads(data)) for ip in s.ip_addresses: assert set(ip.to_dict().keys()) == set( ['address', 'family', 'access'])
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'} ] }
Storage(os='01000000-0000-4000-8000-000030060200', size=10), Storage(size=10, tier='maxiops') ]), 'web2': Server( core_number=1, memory_amount=1024, hostname='web2.example.com', zone='uk-lon1', password_delivery='none', storage_devices=[ Storage(os='01000000-0000-4000-8000-000030060200', size=10), Storage(size=10, tier='maxiops'), ], ip_addresses=[ IPAddress(family='IPv6', access='public') ]), 'db': Server( core_number=1, memory_amount=1024, hostname='db.example.com', zone='uk-lon1', password_delivery='none', storage_devices=[ Storage(os='01000000-0000-4000-8000-000050010300', size=10), Storage(size=10), ], login_user=login_user_block('testuser', ['ssh-rsa AAAAB3NzaC1yc2EAA[...]ptshi44x [email protected]'], True), ),
password_delivery='none', storage_devices=[ Storage(os='Ubuntu 14.04', size=10), Storage(size=10, tier='maxiops') ]), 'web2': Server(core_number=1, memory_amount=1024, hostname='web2.example.com', zone=ZONE.London, password_delivery='none', storage_devices=[ Storage(os='Ubuntu 14.04', size=10), Storage(size=10, tier='maxiops'), ], ip_addresses=[IPAddress(family='IPv6', access='public')]), 'db': Server( core_number=1, memory_amount=1024, hostname='db.example.com', zone=ZONE.London, password_delivery='none', storage_devices=[ Storage(os='CentOS 7.6', size=10), Storage(size=10), ], login_user=login_user_block( 'testuser', ['ssh-rsa AAAAB3NzaC1yc2EAA[...]ptshi44x [email protected]'], True), ),