Example #1
0
 def handle_update(self, json_snippet, tmpl_diff, prop_diff):
     if 'members' in prop_diff:
         members = set(prop_diff['members'])
         old_members = set(self.t['Properties'].get('members', []))
         client = self.neutron()
         for member in old_members - members:
             member_id = db_api.resource_data_get(self, member)
             try:
                 client.delete_member(member_id)
             except NeutronClientException as ex:
                 if ex.status_code != 404:
                     raise ex
             db_api.resource_data_delete(self, member)
         pool = self.properties['pool_id']
         nova_client = self.nova()
         protocol_port = self.properties['protocol_port']
         for member in members - old_members:
             address = nova_utils.server_to_ipaddress(nova_client, member)
             lb_member = client.create_member({
                 'member': {
                     'pool_id': pool,
                     'address': address,
                     'protocol_port': protocol_port
                 }
             })['member']
             db_api.resource_data_set(self, member, lb_member['id'])
Example #2
0
 def handle_create(self):
     pub_key = self.properties['public_key'] or None
     new_keypair = self.nova().keypairs.create(self.properties['name'],
                                               public_key=pub_key)
     if (self.properties['save_private_key']
             and hasattr(new_keypair, 'private_key')):
         db_api.resource_data_set(self, 'private_key',
                                  new_keypair.private_key, True)
     self.resource_id_set(new_keypair.id)
Example #3
0
 def handle_create(self):
     pub_key = self.properties['public_key'] or None
     new_keypair = self.nova().keypairs.create(self.properties['name'],
                                               public_key=pub_key)
     if (self.properties['save_private_key'] and
             hasattr(new_keypair, 'private_key')):
         db_api.resource_data_set(self, 'private_key',
                                  new_keypair.private_key,
                                  True)
     self.resource_id_set(new_keypair.id)
Example #4
0
 def test_resource_data_delete(self):
     stack = self._setup_test_stack('stack', UUID1)[1]
     self._mock_create(self.m)
     self.m.ReplayAll()
     stack.create()
     rsrc = stack.resources['WebServer']
     db_api.resource_data_set(rsrc, 'test', 'test_data')
     self.assertEqual('test_data', db_api.resource_data_get(rsrc, 'test'))
     db_api.resource_data_delete(rsrc, 'test')
     self.assertRaises(exception.NotFound,
                       db_api.resource_data_get, rsrc, 'test')
Example #5
0
 def test_resource_data_delete(self):
     stack = self._setup_test_stack('stack', UUID1)[1]
     self._mock_create(self.m)
     self.m.ReplayAll()
     stack.create()
     rsrc = stack['WebServer']
     db_api.resource_data_set(rsrc, 'test', 'test_data')
     self.assertEqual('test_data', db_api.resource_data_get(rsrc, 'test'))
     db_api.resource_data_delete(rsrc, 'test')
     self.assertRaises(exception.NotFound,
                       db_api.resource_data_get, rsrc, 'test')
Example #6
0
    def handle_create(self):
        asclient = self.stack.clients.auto_scale()
        args = self._get_args(self.properties)
        webhook = asclient.add_webhook(**args)
        self.resource_id_set(webhook.id)

        for link in webhook.links:
            rel_to_key = {'self': 'executeUrl', 'capability': 'capabilityUrl'}
            key = rel_to_key.get(link['rel'])
            if key is not None:
                url = link['href'].encode('utf-8')
                db_api.resource_data_set(self, key, url)
Example #7
0
    def handle_create(self):
        server = super(CloudServer, self).handle_create()

        #  Server will not have an adminPass attribute if Nova's
        #  "enable_instance_password" config option is turned off
        if (self.properties.get(self.SAVE_ADMIN_PASS) and
                hasattr(server, 'adminPass') and server.adminPass):
            db_api.resource_data_set(self, self.ADMIN_PASS,
                                     server.adminPass,
                                     redact=True)

        return server
Example #8
0
 def handle_create(self):
     pool = self.properties['pool_id']
     client = self.neutron()
     nova_client = self.nova()
     protocol_port = self.properties['protocol_port']
     for member in self.properties['members']:
         address = nova_utils.server_to_ipaddress(nova_client, member)
         lb_member = client.create_member({
             'member': {
                 'pool_id': pool,
                 'address': address,
                 'protocol_port': protocol_port}})['member']
         db_api.resource_data_set(self, member, lb_member['id'])
Example #9
0
    def handle_create(self):
        asclient = self.stack.clients.auto_scale()
        args = self._get_args(self.properties)
        webhook = asclient.add_webhook(**args)
        self.resource_id_set(webhook.id)

        for link in webhook.links:
            rel_to_key = {'self': 'executeUrl',
                          'capability': 'capabilityUrl'}
            key = rel_to_key.get(link['rel'])
            if key is not None:
                url = link['href'].encode('utf-8')
                db_api.resource_data_set(self, key, url)
Example #10
0
 def handle_create(self):
     pool = self.properties['pool_id']
     client = self.neutron()
     nova_client = self.nova()
     protocol_port = self.properties['protocol_port']
     for member in self.t['Properties'].get('members', []):
         address = nova_utils.server_to_ipaddress(nova_client, member)
         lb_member = client.create_member({
             'member': {
                 'pool_id': pool,
                 'address': address,
                 'protocol_port': protocol_port}})['member']
         db_api.resource_data_set(self, member, lb_member['id'])
Example #11
0
    def handle_create(self):
        server = super(CloudServer, self).handle_create()

        #  Server will not have an adminPass attribute if Nova's
        #  "enable_instance_password" config option is turned off
        if (self.properties.get(self.SAVE_ADMIN_PASS)
                and hasattr(server, 'adminPass') and server.adminPass):
            db_api.resource_data_set(self,
                                     self.ADMIN_PASS,
                                     server.adminPass,
                                     redact=True)

        return server
Example #12
0
def create_resource_data(ctx, resource, **kwargs):
    values = {
        'key': 'test_resource_key',
        'value': 'test_value',
        'redact': 0,
    }
    values.update(kwargs)
    return db_api.resource_data_set(resource, **values)
Example #13
0
def create_resource_data(ctx, resource, **kwargs):
    values = {
        'key': 'test_resource_key',
        'value': 'test_value',
        'redact': 0,
    }
    values.update(kwargs)
    return db_api.resource_data_set(resource, **values)
Example #14
0
 def set(cls, resource, key, value, *args, **kwargs):
     db_data = db_api.resource_data_set(
         resource.context,
         resource.id,
         key,
         value,
         *args,
         **kwargs
     )
     return db_data
Example #15
0
 def handle_update(self, json_snippet, tmpl_diff, prop_diff):
     if 'members' in prop_diff:
         members = set(prop_diff['members'])
         old_members = set(self.t['Properties'].get('members', []))
         client = self.neutron()
         for member in old_members - members:
             member_id = db_api.resource_data_get(self, member)
             try:
                 client.delete_member(member_id)
             except NeutronClientException as ex:
                 if ex.status_code != 404:
                     raise ex
             db_api.resource_data_delete(self, member)
         pool = self.properties['pool_id']
         nova_client = self.nova()
         protocol_port = self.properties['protocol_port']
         for member in members - old_members:
             address = nova_utils.server_to_ipaddress(nova_client, member)
             lb_member = client.create_member({
                 'member': {
                     'pool_id': pool,
                     'address': address,
                     'protocol_port': protocol_port}})['member']
             db_api.resource_data_set(self, member, lb_member['id'])
Example #16
0
 def private_key(self, private_key):
     """Save the resource's private SSH key to the database."""
     self._private_key = private_key
     if self.id is not None:
         db_api.resource_data_set(self, 'private_key', private_key, True)
Example #17
0
 def my_secret(self, my_secret):
     db_api.resource_data_set(self, 'my_secret', my_secret, True)
Example #18
0
 def private_key(self, private_key):
     """Save the resource's private SSH key to the database."""
     self._private_key = private_key
     if self.id is not None:
         db_api.resource_data_set(self, "private_key", private_key, True)
Example #19
0
 def my_secret(self, my_secret):
     db_api.resource_data_set(self, 'my_secret', my_secret, True)
Example #20
0
 def set(cls, resource, key, value, *args, **kwargs):
     db_data = db_api.resource_data_set(resource.context, resource.id, key,
                                        value, *args, **kwargs)
     return db_data