コード例 #1
0
ファイル: openstack.py プロジェクト: JackDan9/hamal
    def auth(self):
        auth_url = self.auth_url + '/v2.0/tokens'
        data = {
            "auth": {
                "passwordCredentials": {
                    "username": self.username,
                    "password": self.password
                }
            }
        }

        try:
            resp_data = post_request(url=auth_url, body=data)
        except Exception as e:
            LOG.exception(
                _LW("Hamal openstack authentication PasswordCredentials exception ERROR_CLUSTER : [%(cluster_name)s], ERROR_CONTENT : %(message)s"
                    ), {
                        "cluster_name": self.cluster_name,
                        "message": e
                    })
            raise HttpException(code=401,
                                message="Cluster [%s] auth error : %s" %
                                (self.cluster_name, str(e)))

        openstack_user_token = resp_data['access']['token']['id']
        data = {
            "auth": {
                "tenantId": self.tenant_id,
                "token": {
                    "id": openstack_user_token
                }
            }
        }

        try:
            resp_data = post_request(url=auth_url, body=data)
        except Exception as e:
            LOG.exception(
                _LW("Hamal openstack authentication TenantId exception ERROR_CLUSTER : [%(cluster_name)s], ERROR_CONTENT : %(message)s"
                    ), {
                        "cluster_name": self.cluster_name,
                        "message": str(e)
                    })
            raise HttpException(code=401,
                                message="Cluster [%s] auth error : %s" %
                                (self.cluster_name, str(e)))

        self._openstack_user_token = resp_data['access']['token']['id']

        token_expire_timestamp = calendar.timegm(
            datetime.strptime(
                transfer_datetime(resp_data['access']['token']['expires']),
                "%Y-%m-%d %H:%M:%S").timetuple())
        LOG.info(
            _LI("Hamal openstack user token expire timestamp is %(timestamp)s"
                ), {"timestamp": token_expire_timestamp})

        self._openstack_user_token_expire = token_expire_timestamp - 300
        self.service_catalog = resp_data
コード例 #2
0
ファイル: neutron.py プロジェクト: JackDan9/hamal
    def create_security_group(self, name):
        if name == 'default':
            name = 'hamal-default'
        data = {"security_group": {"name": name}}

        return post_request(self._security_groups_url, data,
                            self.openstack_user_token)
コード例 #3
0
ファイル: nova.py プロジェクト: JackDan9/hamal
    def volumes_boot(self, name, flavor_id, source_type, source_id,
                     volume_size, net_ids):
        volume_boot_url = self._volume_boot_url

        data = {
            "server": {
                "name":
                name,
                "imageRef":
                "",
                "block_device_mapping_v2": [{
                    "boot_index": "0",
                    "uuid": source_id,
                    "volume_size": volume_size,
                    "device_name": "vda",
                    "source_type": source_type,
                    "device_type": "disk",
                    "destination_type": "volume"
                }],
                "flavorRef":
                flavor_id,
                "max_count":
                1,
                "min_count":
                1,
                "networks":
                map(lambda net_id: {"uuid": net_id}, net_ids)
            }
        }

        resp_data = post_request(volume_boot_url, data,
                                 self.openstack_user_token)
        return resp_data
コード例 #4
0
ファイル: cinder.py プロジェクト: JackDan9/hamal
    def create_volume(self,
                      size,
                      display_name=None,
                      display_description=None,
                      image_id=None,
                      volume_type=None):
        data = {
            "volume": {
                "status": "creating",
                "availability_zone": None,
                "source_volid": None,
                "display_description": display_description,
                "snapshot_id": None,
                "user_id": None,
                "size": size,
                "display_name": display_name,
                "imageRef": image_id,
                "attach_status": "detached",
                "volume_type": volume_type,
                "project_id": None,
                "metadata": {}
            }
        }

        return post_request(self._volumes_url, data, self.openstack_user_token)
コード例 #5
0
ファイル: nova.py プロジェクト: JackDan9/hamal
    def volume_attach_instance(self, instance_id, volume_id):
        instance_volume_attachment_url = self._instance_volume_attachments_url.format(
            instance_id=instance_id)

        data = {"volumeAttachment": {"device": None, "volumeId": volume_id}}

        return post_request(instance_volume_attachment_url, data,
                            self.openstack_user_token)
コード例 #6
0
ファイル: cinder.py プロジェクト: JackDan9/hamal
    def set_volume_status(self, volume_id, status):
        data = {"os-reset_status": {"status": status}}

        volume_url = self._volume_action_url(volume_id=volume_id)
        return post_request(volume_url,
                            data,
                            self.openstack_user_token,
                            no_resp_content=True)
コード例 #7
0
ファイル: cinder.py プロジェクト: JackDan9/hamal
    def set_volume_bootable(self, volume_id, bootable):
        data = {"os-set_bootable": {"bootable": bootable}}

        volume_url = self._volume_action_url.format(volume_id=volume_id)
        return post_request(volume_url,
                            data,
                            self.openstack_user_token,
                            no_resp_content=True)
コード例 #8
0
ファイル: neutron.py プロジェクト: JackDan9/hamal
    def create_floatingip(self, net_id, ip, port_id):
        data = {
            "floatingip": {
                "floating_network_id": net_id,
                "floating_ip_address": ip,
                "port_id": port_id
            }
        }

        return post_request(self._floating_ips_url, data,
                            self.openstack_user_token)
コード例 #9
0
ファイル: cinder.py プロジェクト: JackDan9/hamal
    def create_snapshot_from_volume(self, volume_id):
        data = {
            "snapshot": {
                "display_name": "hamal-volume-%s" % volume_id,
                "force": "True",
                "display_description": None,
                "volume_id": volume_id
            }
        }

        return post_request(self._snapshot_url, data,
                            self.openstack_user_token)
コード例 #10
0
ファイル: nova.py プロジェクト: JackDan9/hamal
 def start_instance(self, instance_id):
     instance_url = self._instance_action_url.format(
         instance_id=instance_id)
     data = {"os-start": None}
     try:
         return post_request(instance_url,
                             body=data,
                             token=self.openstack_user_token,
                             no_resp_content=True)
     except HamalException as he:
         LOG.exception(
             _LE("Start instance exception is : %(he)s", {"he": he}))
         if he.code != 409:
             raise he
コード例 #11
0
ファイル: neutron.py プロジェクト: JackDan9/hamal
    def create_security_group_rule(self, security_group_id, direction,
                                   ethertype, port_range_max, port_range_min,
                                   protocol, remote_group_id,
                                   remote_ip_prefix):
        data = {
            "security_group_rule": {
                "security_group_id": security_group_id,
                "direction": direction,
                "ethertype": ethertype,
                "port_range_max": port_range_max,
                "port_range_min": port_range_min,
                "protocol": protocol,
                "remote_group_id": remote_group_id,
                "remote_ip_prefix": remote_ip_prefix
            }
        }

        return post_request(self._security_group_rules_url, data,
                            self.openstack_user_token)
コード例 #12
0
ファイル: nova.py プロジェクト: JackDan9/hamal
    def create_flavor(self, vcpus, disk, name, is_public, rxtx_factor,
                      ephemeral, ram, swap):
        data = {
            "flavor": {
                "vcpus": vcpus,
                "disk": disk,
                "name": name,
                "os-flavor-access:is_public": is_public,
                "rxtx_factor": rxtx_factor,
                "OS-FLV-EXT-DATA:ephemeral": ephemeral,
                "ram": ram,
                "id": None,
                "swap": swap
            }
        }

        resp_data = post_request(self._flavors_url, data,
                                 self.openstack_user_token)
        return resp_data
コード例 #13
0
ファイル: cinder.py プロジェクト: JackDan9/hamal
    def create_another_env_image(self, volume_id, image_name, glance_ip,
                                 glance_port, glance_token, container_format,
                                 disk_format):
        data = {
            "os-volume_upload_image": {
                "glance_ip": glance_ip,
                "glance_use_ssl": "0",
                "force": "True",
                "glance_version": "1",
                "container_format": container_format,
                "disk_format": disk_format,
                "image_name": image_name,
                "glance_token": glance_token,
                "glance_port": glance_port
            }
        }

        volume_url = self._volume_action_url.format(volume_id=volume_id)
        return post_request(volume_url, data, self.openstack_user_token)