def setUpClass(self): self.resource = resource() self.client = ProfitBricksService(username=configuration.USERNAME, password=configuration.PASSWORD, headers=configuration.HEADERS) ipblock1 = IPBlock(**self.resource['ipblock']) ipblock1.size = 2 self.ipblock1 = self.client.reserve_ipblock(ipblock1) ipblock2 = IPBlock(**self.resource['ipblock']) self.ipblock2 = self.client.reserve_ipblock(ipblock2)
def setUpClass(cls): cls.resource = resource() cls.client = ProfitBricksService( username=configuration.USERNAME, password=configuration.PASSWORD, headers=configuration.HEADERS) ipblock1 = IPBlock(**cls.resource['ipblock']) ipblock1.size = 2 cls.ipblock1 = cls.client.reserve_ipblock(ipblock1) ipblock2 = IPBlock(**cls.resource['ipblock']) cls.ipblock2 = cls.client.reserve_ipblock(ipblock2)
def reserve_ipblock(call=None, kwargs=None): """ Reserve the IP Block """ if call == "action": raise SaltCloudSystemExit( "The reserve_ipblock function must be called with -f or --function." ) conn = get_conn() if kwargs is None: kwargs = {} ret = {} ret["ips"] = [] if kwargs.get("location") is None: raise SaltCloudExecutionFailure('The "location" parameter is required') location = kwargs.get("location") size = 1 if kwargs.get("size") is not None: size = kwargs.get("size") block = conn.reserve_ipblock(IPBlock(size=size, location=location)) for item in block["properties"]["ips"]: ret["ips"].append(item) return ret
def reserve_ipblock(call=None, kwargs=None): ''' Reserve the IP Block ''' if call == 'action': raise SaltCloudSystemExit( 'The reserve_ipblock function must be called with -f or ' '--function.') conn = get_conn() if kwargs is None: kwargs = {} ret = {} ret['ips'] = [] if kwargs.get('location') is None: raise SaltCloudExecutionFailure('The "location" parameter is required') location = kwargs.get('location') size = 1 if kwargs.get('size') is not None: size = kwargs.get('size') block = conn.reserve_ipblock(IPBlock(size=size, location=location)) for item in block['properties']['ips']: ret['ips'].append(item) return ret
def test_reserve_failure(self): try: ipblock = IPBlock(name=self.resource['ipblock']['name'], size=1) self.client.reserve_ipblock(ipblock) except PBError as e: self.assertIn(self.resource['missing_attribute_error'] % 'location', e.content[0]['message'])
def test_reserve_ipblock(self): ipblock = self.client.reserve_ipblock(IPBlock(**self.resource['ipblock'])) assertRegex(self, ipblock['id'], self.resource['uuid_match']) self.assertEqual(ipblock['properties']['name'], (self.resource['ipblock']['name'])) self.assertEqual(ipblock['properties']['size'], self.resource['ipblock']['size']) self.assertEqual(ipblock['properties']['location'], self.resource['ipblock']['location']) self.client.delete_ipblock(ipblock['id'])
def reserve_ipblock(module, profitbricks): """ Creates an IPBlock. module : AnsibleModule object profitbricks: authenticated profitbricks object. Returns: The IPBlock instance """ name = module.params.get('name') location = module.params.get('location') size = module.params.get('size') wait = module.params.get('wait') wait_timeout = module.params.get('wait_timeout') ip_list = profitbricks.list_ipblocks() ip = None for i in ip_list['items']: if name == i['properties']['name']: ip = i break should_change = ip is None if module.check_mode: module.exit_json(changed=should_change) if not should_change: return {'changed': should_change, 'ipblock': ip} try: ipblock = IPBlock(name=name, location=location, size=size) ipblock_response = profitbricks.reserve_ipblock(ipblock) if wait: _wait_for_completion(profitbricks, ipblock_response, wait_timeout, "reserve_ipblock") return {'failed': False, 'changed': True, 'ipblock': ipblock_response} except Exception as e: module.fail_json(msg="failed to create the IPBlock: %s" % to_native(e))
# pylint: disable=pointless-string-statement,reimported,wrong-import-position import os """List IPBlocks """ from profitbricks.client import ProfitBricksService client = ProfitBricksService( username=os.getenv('PROFITBRICKS_USERNAME'), password=os.getenv('PROFITBRICKS_PASSWORD')) ipblocks = client.list_ipblocks() print(ipblocks) """Reserve IPBlock """ from profitbricks.client import ProfitBricksService, IPBlock # noqa i = IPBlock(name='py-test', location='de/fra', size=1) ipblock = client.reserve_ipblock(i) """Release IPBlock """ from profitbricks.client import ProfitBricksService # noqa ipblock_id = ipblock['id'] ipblock = client.delete_ipblock(ipblock_id)
def setUpClass(self): self.resource = resource() self.client = ProfitBricksService(username=configuration.USERNAME, password=configuration.PASSWORD, headers=configuration.HEADERS) # Create datacenter resource self.datacenter = self.client.create_datacenter(datacenter=Datacenter( **self.resource['datacenter'])) self.client.wait_for_completion(self.datacenter) # Create volume resource volume = Volume(**self.resource['volume']) self.volume = self.client.create_volume( datacenter_id=self.datacenter['id'], volume=volume) self.client.wait_for_completion(self.volume) self.image = find_image(self.client, configuration.IMAGE_NAME) # Create snapshot resource self.snapshot = self.client.create_snapshot( datacenter_id=self.datacenter['id'], volume_id=self.volume['id'], name=self.resource['snapshot']['name']) self.client.wait_for_completion(self.snapshot) # Reserve IP block resource self.ipblock = self.client.reserve_ipblock( IPBlock(**self.resource['ipblock'])) # Create User 1 self.user_dict1 = User( firstname='John', lastname='Doe', email='*****@*****.**' % randint(0, 9999999999999), password='******' % randint(0, 99999999), administrator=True, force_sec_auth=False) self.user1 = self.client.create_user(user=self.user_dict1) # Create User 2 self.user_dict2 = User( firstname='John', lastname='Doe', email='*****@*****.**' % randint(0, 9999999999999), password='******' % randint(0, 99999999)) self.user2 = self.client.create_user(user=self.user_dict2) # Create User 3 self.user_dict3 = User( firstname='John', lastname='Doe', email='*****@*****.**' % randint(0, 9999999999999), password='******' % randint(0, 99999999)) self.user3 = self.client.create_user(user=self.user_dict3) # Create Group 1 group = Group(**self.resource['group']) self.group1 = self.client.create_group(group) # Create Group 2 group.name = self.resource['group']['name'] + ' 2' self.group2 = self.client.create_group(group) # Create Group 3 group.name = self.resource['group']['name'] + ' 3' self.group3 = self.client.create_group(group) # Create Share 1 self.share1 = self.client.add_share(group_id=self.group3['id'], resource_id=self.datacenter['id'], edit_privilege=True, share_privilege=True)