コード例 #1
0
ファイル: volume.py プロジェクト: devcamcar/heat
    def delete(self):
        if self.state == self.DELETE_IN_PROGRESS or \
           self.state == self.DELETE_COMPLETE:
            return
        self.state_set(self.DELETE_IN_PROGRESS)
        Resource.delete(self)

        server_id = self.t['Properties']['InstanceId']
        volume_id = self.t['Properties']['VolumeId']
        logger.info('VolumeAttachment un-attaching %s %s' % \
                    (server_id, volume_id))

        volapi = self.nova().volumes
        volapi.delete_server_volume(server_id,
                                    volume_id)

        vol = self.nova('volume').volumes.get(volume_id)
        logger.info('un-attaching %s, status %s' % (volume_id, vol.status))
        while vol.status == 'in-use':
            logger.info('trying to un-attach %s, but still %s' %
                        (volume_id, vol.status))
            eventlet.sleep(1)
            try:
                volapi.delete_server_volume(server_id,
                                            volume_id)
            except Exception:
                pass
            vol.get()

        self.state_set(self.DELETE_COMPLETE)
コード例 #2
0
ファイル: wait_condition.py プロジェクト: devcamcar/heat
    def delete(self):
        if self.state == self.DELETE_IN_PROGRESS or self.state == self.DELETE_COMPLETE:
            return

        self.state_set(self.DELETE_IN_PROGRESS)
        Resource.delete(self)
        self.state_set(self.DELETE_COMPLETE)
コード例 #3
0
ファイル: instance.py プロジェクト: devcamcar/heat
 def delete(self):
     if self.state == self.DELETE_IN_PROGRESS or self.state == self.DELETE_COMPLETE:
         return
     self.state_set(self.DELETE_IN_PROGRESS)
     Resource.delete(self)
     server = self.nova().servers.get(self.instance_id)
     server.delete()
     self.instance_id = None
     self.state_set(self.DELETE_COMPLETE)
コード例 #4
0
ファイル: wait_condition.py プロジェクト: devcamcar/heat
    def create(self):
        if self.state != None:
            return
        self.state_set(self.CREATE_IN_PROGRESS)
        Resource.create(self)

        self.instance_id = "%s/stacks/%s/resources/%s" % (self.stack.metadata_server, self.stack.name, self.name)

        self.state_set(self.CREATE_COMPLETE)
コード例 #5
0
ファイル: instance.py プロジェクト: devcamcar/heat
    def reload(self):
        """
        re-read the server's ipaddress so FnGetAtt works.
        """
        try:
            server = self.nova().servers.get(self.instance_id)
            for n in server.networks:
                self.ipaddress = server.networks[n][0]
        except NotFound:
            self.ipaddress = "0.0.0.0"

        Resource.reload(self)
コード例 #6
0
ファイル: eip.py プロジェクト: devcamcar/heat
    def reload(self):
        '''
        get the ipaddress here
        '''
        if self.instance_id != None:
            try:
                ips = self.nova().floating_ips.get(self.instance_id)
                self.ipaddress = ips.ip
            except Exception as ex:
                logger.warn("Error getting floating IPs: %s" % str(ex))

        Resource.reload(self)
コード例 #7
0
ファイル: eip.py プロジェクト: devcamcar/heat
    def delete(self):
        """Remove a floating IP address from a server."""
        if self.state == self.DELETE_IN_PROGRESS or \
           self.state == self.DELETE_COMPLETE:
            return

        self.state_set(self.DELETE_IN_PROGRESS)
        Resource.delete(self)

        server = self.nova().servers.get(self.t['Properties']['InstanceId'])
        server.remove_floating_ip(self.t['Properties']['EIP'])

        self.state_set(self.DELETE_COMPLETE)
コード例 #8
0
ファイル: eip.py プロジェクト: devcamcar/heat
    def delete(self):
        """De-allocate a floating IP."""
        if self.state == self.DELETE_IN_PROGRESS or \
           self.state == self.DELETE_COMPLETE:
            return

        self.state_set(self.DELETE_IN_PROGRESS)
        Resource.delete(self)

        if self.instance_id != None:
            self.nova().floating_ips.delete(self.instance_id)

        self.state_set(self.DELETE_COMPLETE)
コード例 #9
0
ファイル: volume.py プロジェクト: devcamcar/heat
    def delete(self):
        if self.state == self.DELETE_IN_PROGRESS or \
           self.state == self.DELETE_COMPLETE:
            return

        if self.instance_id != None:
            vol = self.nova('volume').volumes.get(self.instance_id)
            if vol.status == 'in-use':
                logger.warn('cant delete volume when in-use')
                return

        self.state_set(self.DELETE_IN_PROGRESS)
        Resource.delete(self)

        if self.instance_id != None:
            self.nova('volume').volumes.delete(self.instance_id)
        self.state_set(self.DELETE_COMPLETE)
コード例 #10
0
ファイル: security_group.py プロジェクト: devcamcar/heat
    def delete(self):
        if self.state == self.DELETE_IN_PROGRESS or \
           self.state == self.DELETE_COMPLETE:
            return

        self.state_set(self.DELETE_IN_PROGRESS)
        Resource.delete(self)

        if self.instance_id != None:
            sec = self.nova().security_groups.get(self.instance_id)

            for rule in sec.rules:
                self.nova().security_group_rules.delete(rule['id'])

            self.nova().security_groups.delete(sec)
            self.instance_id = None

        self.state_set(self.DELETE_COMPLETE)
コード例 #11
0
ファイル: wait_condition.py プロジェクト: devcamcar/heat
    def create(self):
        if self.state != None:
            return
        self.state_set(self.CREATE_IN_PROGRESS)
        Resource.create(self)

        self._get_handle_resource_id()

        # keep polling our Metadata to see if the cfn-signal has written
        # it yet. The execution here is limited by timeout.
        print "timeout %d" % self.timeout
        tmo = eventlet.Timeout(self.timeout)
        status = "WAITING"
        reason = ""
        try:
            while status == "WAITING":
                pt = None
                if self.stack.parsed_template_id:
                    try:
                        pt = db_api.parsed_template_get(None, self.stack.parsed_template_id)
                    except Exception as ex:
                        if "not found" in ex:
                            # entry deleted
                            return
                        else:
                            pass

                if pt:
                    res = pt.template["Resources"][self.resource_id]
                    metadata = res.get("Metadata", {})
                    status = metadata.get("Status", "WAITING")
                    reason = metadata.get("Reason", "Reason not provided")
                    logger.debug("got %s" % json.dumps(metadata))
                if status == "WAITING":
                    logger.debug("Waiting some more for the Metadata[Status]")
                    eventlet.sleep(30)
        except eventlet.Timeout, t:
            if t is not tmo:
                # not my timeout
                raise
            else:
                status = "TIMEDOUT"
                reason = "Timed out waiting for instance"
コード例 #12
0
ファイル: security_group.py プロジェクト: devcamcar/heat
    def create(self):
        if self.state != None:
            return
        self.state_set(self.CREATE_IN_PROGRESS)
        Resource.create(self)
        sec = None

        groups = self.nova().security_groups.list()
        for group in groups:
            if group.name == self.name:
                sec = group
                break

        if not sec:
            sec = self.nova().security_groups.create(self.name,
                                                     self.description)

        self.instance_id_set(sec.id)

        if 'SecurityGroupIngress' in self.t['Properties']:
            rules_client = self.nova().security_group_rules
            for i in self.t['Properties']['SecurityGroupIngress']:
                try:
                    rule = rules_client.create(sec.id,
                                               i['IpProtocol'],
                                               i['FromPort'],
                                               i['ToPort'],
                                               i['CidrIp'])
                except BadRequest as ex:
                    if ex.message.find('already exists') >= 0:
                        # no worries, the rule is already there
                        pass
                    else:
                        # unexpected error
                        raise

        self.state_set(self.CREATE_COMPLETE)
コード例 #13
0
ファイル: cloud_watch.py プロジェクト: kiranmurari/heat
 def validate(self):
     '''
     Validate the Properties
     '''
     return Resource.validate(self)
コード例 #14
0
ファイル: cloud_watch.py プロジェクト: kiranmurari/heat
 def validate(self):
     '''
     Validate the Properties
     '''
     return Resource.validate(self)
コード例 #15
0
 def __init__(self, name, json_snippet, stack):
     Resource.__init__(self, name, json_snippet, stack)
     self._nested = None
コード例 #16
0
ファイル: eip.py プロジェクト: kiranmurari/heat
 def validate(self):
     '''
     Validate the ip address here
     '''
     return Resource.validate(self)
コード例 #17
0
ファイル: stack.py プロジェクト: patlachance/heat
 def __init__(self, name, json_snippet, stack):
     Resource.__init__(self, name, json_snippet, stack)
     self._nested = None
コード例 #18
0
 def validate(self):
     '''
     Validate the ip address here
     '''
     return Resource.validate(self)
コード例 #19
0
ファイル: instance.py プロジェクト: devcamcar/heat
    def create(self):
        def _null_callback(p, n, out):
            """
            Method to silence the default M2Crypto.RSA.gen_key output.
            """
            pass

        if self.state != None:
            return
        self.state_set(self.CREATE_IN_PROGRESS)
        Resource.create(self)
        props = self.t["Properties"]
        if not "KeyName" in props:
            raise exception.UserParameterMissing(key="KeyName")
        if not "InstanceType" in props:
            raise exception.UserParameterMissing(key="InstanceType")
        if not "ImageId" in props:
            raise exception.UserParameterMissing(key="ImageId")

        security_groups = props.get("SecurityGroups")

        userdata = self.t["Properties"]["UserData"]

        flavor = self.itype_oflavor[self.t["Properties"]["InstanceType"]]
        key_name = self.t["Properties"]["KeyName"]

        keypairs = self.nova().keypairs.list()
        key_exists = False
        for k in keypairs:
            if k.name == key_name:
                # cool it exists
                key_exists = True
                break
        if not key_exists:
            raise exception.UserKeyPairMissing(key_name=key_name)

        image_name = self.t["Properties"]["ImageId"]
        image_id = None
        image_list = self.nova().images.list()
        for o in image_list:
            if o.name == image_name:
                image_id = o.id

        if image_id is None:
            logger.info("Image %s was not found in glance" % image_name)
            raise exception.ImageNotFound(image_name=image_name)

        flavor_list = self.nova().flavors.list()
        for o in flavor_list:
            if o.name == flavor:
                flavor_id = o.id

        server_userdata = self._build_userdata(userdata)
        server = self.nova().servers.create(
            name=self.name,
            image=image_id,
            flavor=flavor_id,
            key_name=key_name,
            security_groups=security_groups,
            userdata=server_userdata,
        )
        while server.status == "BUILD":
            server.get()
            eventlet.sleep(1)
        if server.status == "ACTIVE":
            self.instance_id_set(server.id)
            self.state_set(self.CREATE_COMPLETE)
            # just record the first ipaddress
            for n in server.networks:
                self.ipaddress = server.networks[n][0]
                break
        else:
            raise exception.Error(server.status)