I have set up Openstack 4.0.2 (Train release). I'm trying to provide APIs to my client for building a web application. Everything works on the command line as well as on Horizon Dashboard. However, through API right from the token generation to flavor creation, server (VM) creation works except for Image Upload!
Below is the cURL command for Token Generation:
export TOKEN=`curl --silent -X POST -H "Content-Type: application/json" -d '{ "auth": { "identity": { "methods": ["password"], "password": { "user": { "name": "admin", "domain": { "id": "default" }, "password": "MYPASS123" } } }, "scope": { "project": { "name": "admin", "domain": { "id": "default" } } } } }' -i "http://controller:5000/v3/auth/tokens" | grep X-Subject-Token | cut -d ":" -f 2`
The token is generated based on project scope.
echo $TOKEN
gAAAAABh1tudXXtt............3J-1E3KCMR7tlq-gacOmo8
Below is the cURL command to create an Image
curl -X POST -s http://controller:8774/v2.1/servers -d '{"server": { "name": "API1", "imageRef":"a62daa1b-2fba-47ad-8008-538cd88f306c", "flavorRef":"54eb939a-a39a-40ae-b50c-ed69b9f565ba ", "OS-DCF:diskConfig": "AUTO", "security_groups": [ { "name": "sg2" } ], "networks": [ { "uuid": "1c4d7023-4d3e-4d4a-aacc-deba1e9f9b98" } ], "user_data":" I2Nsb3VkLWNvbmZpZwpwYXNzd29yZDogY2VudG9zCmNocGFzc3dkOiB7IGV4cGlyZTogRmFsc2UgfQpzc2hfcHdhdXRoOiBUcnVlCgo=" }}' -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" | python -m json.tool
glance-api.log
2022-01-05 14:08:09.687 26227 DEBUG eventlet.wsgi.server [-] (26227) accepted ('controller', 53108) server /usr/lib/python2.7/site-packages/eventlet/wsgi.py:985
2022-01-05 14:08:09.695 26227 DEBUG glance.api.middleware.version_negotiation [-] Determining version of request: GET /v2/images Accept: */* process_request /usr/lib/python2.7/site-packages/glance/api/middleware/version_negotiation.py:45
2022-01-05 14:08:09.697 26227 DEBUG glance.api.middleware.version_negotiation [-] Using url versioning process_request /usr/lib/python2.7/site-packages/glance/api/middleware/version_negotiation.py:57
2022-01-05 14:08:09.699 26227 DEBUG glance.api.middleware.version_negotiation [-] Matched version: v2 process_request /usr/lib/python2.7/site-packages/glance/api/middleware/version_negotiation.py:69
2022-01-05 14:08:09.700 26227 DEBUG glance.api.middleware.version_negotiation [-] new path /v2/images process_request /usr/lib/python2.7/site-packages/glance/api/middleware/version_negotiation.py:70
2022-01-05 14:08:11.592 26227 WARNING keystonemiddleware.auth_token [-] Authorization failed for token: InvalidToken: Token authorization failed
Keystone.log
2022-01-05 14:08:11.584 492 WARNING keystone.server.flask.application [req-cecd6824-2faf-453b-8772-e2d0f67573c5 ba62aab1541c47fe8c59aeecb82c71d1 4d2a479d2d544c0c994bf55405f83d64 - default default] Could not recognize Fernet token: TokenNotFound: Could not recognize Fernet token
keystone.conf
[cache]
memcache_servers = controller:11211
[database]
connection = mysql+pymysql://keystone:MYPASS123#controller/keystone
[token]
provider = fernet
glance-api.conf
[DEFAULT]
bind_host = 0.0.0.0
[database]
connection = mysql+pymysql://glance:glancepass123#controller/glance
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
[keystone_authtoken]
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance123
[paste_deploy]
flavor = keystone
glance policy.json
{
"context_is_admin": "role:admin",
"default": "role:admin",
"add_image": "role:admin",
"delete_image": "role:admin",
"get_image": "",
"get_images": "",
"modify_image": "",
"publicize_image": "role:admin",
"communitize_image": "",
"copy_from": "",
"download_image": "",
"upload_image": "role:admin",
"delete_image_location": "",
"get_image_location": "",
"set_image_location": "",
"add_member": "",
"delete_member": "",
"get_member": "",
"get_members": "",
"modify_member": "",
"manage_image_cache": "role:admin",
"get_task": "",
"get_tasks": "",
"add_task": "",
"modify_task": "",
"tasks_api_access": "role:admin",
"deactivate": "",
"reactivate": "",
"get_metadef_namespace": "",
"get_metadef_namespaces":"",
"modify_metadef_namespace":"",
"add_metadef_namespace":"",
"get_metadef_object":"",
"get_metadef_objects":"",
"modify_metadef_object":"",
"add_metadef_object":"",
"list_metadef_resource_types":"",
"get_metadef_resource_type":"",
"add_metadef_resource_type_association":"",
"get_metadef_property":"",
"get_metadef_properties":"",
"modify_metadef_property":"",
"add_metadef_property":"",
"get_metadef_tag":"",
"get_metadef_tags":"",
"modify_metadef_tag":"",
"add_metadef_tag":"",
"add_metadef_tags":""
}
Openstack role assignment list:
[root#controller glance]# openstack role assignment list --names --role admin
+-------+-----------------------+-------+-----------------+---------+--------+-----------+
| Role | User | Group | Project | Domain | System | Inherited |
+-------+-----------------------+-------+-----------------+---------+--------+-----------+
| admin | neutron#Default | | service#Default | | | False |
| admin | cinder#Default | | service#Default | | | False |
| admin | admin#Default | | admin#Default | | | False |
| admin | placement#Default | | service#Default | | | False |
| admin | glance#Default | | service#Default | | | False |
| admin | glance#Default | | admin#Default | | | False |
| admin | nova#Default | | service#Default | | | False |
| admin | demouser#Default | | admin#Default | | | False |
| admin | admin#Default | | | | all | False |
+-------+-----------------------+-------+-----------------+---------+--------+-----------+
Please help me to figure out what am I missing? Thanks in advance
Related
[
{
"arguments": {
"leases": [
{
"cltt": 1658763299,
"fqdn-fwd": false,
"fqdn-rev": false,
"hostname": "",
"hw-address": "00:aa:bb:cc:dd:ee",
"ip-address": "192.168.0.2",
"state": 0,
"subnet-id": 1,
"valid-lft": 3600
},
{
"cltt": 1658763207,
"fqdn-fwd": false,
"fqdn-rev": false,
"hostname": "",
"hw-address": "00:11:22:33:44:55",
"ip-address": "192.168.1.3",
"state": 0,
"subnet-id": 1,
"valid-lft": 3600
}
]
},
"result": 0,
"text": "2 IPv4 lease(s) found."
}
]
This is a snippet, but in reality there's much more entries. Currently I filter out MAC and IP with jq expression:
jq --raw-output '.[0] | select(.result == 0) | .arguments.leases[] | "\(.["hw-address"]) \(.["ip-address"])"'
Now I'm wondering: does jq have ability to filter out by regexp? For instance I'd like to dump only entries where IP is 192.168.1.*, can it be done with jq? Ideally I'd like to pass regexp to my script as a parameter:
jq --raw-output --arg addr "$1" ...
Would appreciate suggestions on how to do this.
jq has test to test an input against a regular expression:
first
| select(.result == 0)
| .arguments.leases[]
| select(."ip-address"|test("^192\\.168\\.1"))
| "\(."hw-address") \(."ip-address")"
and to provide the regex as argument via command line:
jq -r --arg regex '^192\.168\.1\.' 'first
| select(.result == 0)
| .arguments.leases[]
| select(."ip-address"|test($regex))
| "\(."hw-address") \(."ip-address")"'
If you only want to check the start of the IP address, you could also use startswith: select(."ip-address"|startswith("192.168.1.")):
jq -r --arg prefix '192.168.1.' 'first
| select(.result == 0)
| .arguments.leases[]
| select(."ip-address"|startswith($prefix))
| "\(."hw-address") \(."ip-address")"'
You can use test with regular expressions, and select to filter:
jq -r --arg addr "192\\.168\\.1\\..*" '
.[0] | select(.result == 0) | .arguments.leases[]
| "\(.["hw-address"]) \(.["ip-address"] | select(test($addr)))"
'
00:11:22:33:44:55 192.168.1.3
Demo
Note: 192.168.1.* is not a regular expression (or at least not one you want to use, as it would also match 192.168.100.4 for instance, because . stands for any value; a literal dot has to be escaped)
A call to the following local endpoint:-
curl -k --location --request POST 'https://localhost:8443/project_exports' \
--header 'Authorization: Bearer eyJ0eXA...YVhA' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "bob#test.com",
"projectid": 0,
"status": true,
"emailedat": "2022-08-22T09:56:28.487Z",
"generatedat": "2022-08-22T09:56:28.487Z"
}'
returns an error like thus:-
"message": "An exception occurred while executing a query: SQLSTATE[42703]: Undefined column: 7 ERROR: column \"projectid\" of relation \"project_export\" does not exist\nLINE 1: INSERT INTO project_export (id, email, projectid, status, em...\n ^",
"code": 500
But the field exists in both entity and db:-
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\ProjectExportRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* #ORM\Entity(repositoryClass=ProjectExportRepository::class)
*/
#[ApiResource]
class ProjectExport
{
...
/**
* #ORM\Column(type="integer")
*/
#[Groups('entry-index')]
private $projectid;
...
mysql> describe project_export
-> ;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| email | varchar(255) | NO | | NULL | |
| projectid | int | NO | | NULL | |
| status | tinyint(1) | NO | | NULL | |
| emailedat | datetime | NO | | NULL | |
| generatedat | datetime | NO | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)
I'm serving the api from a docker instance locally. Not sure if this affects it any way?
So, why then, no data gets persisted and the error thrown?
My JSON looks like this.
"[{
changes": [
{
"change": "{users=[7], submitted=true}",
"date": "2016-11-13T14:34:27.353Z",
"user": "abcd"
}
]
}]
Expected Output:
{
id: null,
date: "2016-11-13T14:34:27.353Z",
type: "submission",
user: abcd,
_processDate: todaysDate
}
JQ I tried
[.[][] as $source |
$source.changes[] as $log |
$log.change |
{
submitted: .| (scan("submitted=(?<submitted>[^,}]+)") // [""] ) | .[0],
rejected: .| (scan("rejected=(?<rejected>[^,}]+)") // [""] ) | .[0]
} as $change |
[
(
select($change.submitted == "true") |
{
id: $source.id,
date: $log.date,
type: "submission",
user: $log.user,
_processDate: now | todate
}),
(select($change.rejected == "true") |
{
id: $source.id,
date: $log.date,
type: "rejection",
user: $log.user,
_processDate: now | todate
}
)
] |
.[]]
There could 'rejections' in the json and the output should display the rejections .
My JQ is not yielding expected output.
Any pointers on how to fix this query.
Thank you for your help.
Appreciate it.
I'd take a completely different approach and do this instead.
(now | todate) as $_processDate | [
.[].changes[]
| (.change
| scan("\\b(submitted|rejected)=true\\b")[]
| {submitted:"submission",rejected:"rejection"}[.]) as $type
| {id, date, $type, user, $_processDate}
]
First take note of the current date at the beginning. Then determine what type of change it is. Assuming that "submitted" and "rejected" (or other "types") are mutually exclusive, easier to match on the key name. Then build up the result. This will keep the results in an array.
https://jqplay.org/s/S65ySzbF30
When I create new image using glance does not matter if using cli or gui I am getting returned code 0 and image is created but its size is zero.
The behavior is slightly different as from GUI my browser crushes but stil image is created from cli I am getting return code 0.
Command:
openstack image create --file cirros-0.4.0-x86_64-disk.img --disk-format qcow2 --container-format bare --public --debug cirros-deb
+------------------+------------------------------------------------------+
| Field | Value |
+------------------+------------------------------------------------------+
| checksum | d41d8cd98f00b204e9800998ecf8427e |
| container_format | bare |
| created_at | 2018-01-20T23:24:47Z |
| disk_format | qcow2 |
| file | /v2/images/c695bc30-731d-4a4f-ab0f-12eb972d8188/file |
| id | c695bc30-731d-4a4f-ab0f-12eb972d8188 |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros-deb |
| owner | a3460a3b0e8f4d0bbdd25bf790fe504c |
| protected | False |
| schema | /v2/schemas/image |
| size | 0 |
| status | active |
| tags | |
| updated_at | 2018-01-20T23:24:47Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+
clean_up CreateImage:
END return value: 0
I tried with different cirros image and with ubuntu cloud image always behavior is the same.
Under /var/lib/glance/images file is created with size 0:
-rw-r-----. 1 glance glance 0 Jan 21 00:24 c695bc30-731d-4a4f-ab0f-12eb972d8188
grep c695bc30-731d-4a4f-ab0f-12eb972d8188 glance/api.log
2018-01-21 00:24:47.915 1894 INFO eventlet.wsgi.server [req-7246cd30-47c4-41a5-b358-c8e5cc0f4e56 8bd3e4905ffb4f698e2476d9080a7d90 a3460a3b0e8f4d0bbdd25bf790fe504c - default default] 172.19.254.50 - - [21/Jan/2018 00:24:47] "PUT /v2/images/c695bc30-731d-4a4f-ab0f-12eb972d8188/file HTTP/1.1" 204 213 0.111323
2018-01-21 00:24:47.931 1894 INFO eventlet.wsgi.server [req-28e0cda2-c9f7-4543-b19a-d59eccffa47e 8bd3e4905ffb4f698e2476d9080a7d90 a3460a3b0e8f4d0bbdd25bf790fe504c - default default] 172.19.254.50 - - [21/Jan/2018 00:24:47] "GET /v2/images/c695bc30-731d-4a4f-ab0f-12eb972d8188 HTTP/1.1" 200 780 0.015399
Any idea what can be wrong?
Find location of python glance client.
find / -name http.py
vi /usr/lib/python2.7/site-packages/glanceclient/common/http.py
- data = self._chunk_body(data)
+ pass
Referenc:
https://bugs.launchpad.net/python-glanceclient/+bug/1666511
https://ask.openstack.org/en/question/101944/why-does-openstack-image-create-of-cirros-result-in-size-0/?answer=102303#post-id-102303
Angular NormalizedCollection is now working when reference of 'bookings.reservationFor.apartmentId' is passed. It was working perfect when I created a sample firebase entry and defined apartmentId as a value of 'reservationFor' directly and passed 'bookings.reservationFor' in select() parameter.
I am new to angularFire. Please let me know what is wrong with this code.
Using Firebase v2.2.9; AngularJs v1.5.6; AngularFire v1.2.0;
firebase structure
FB
|
--apartment
| |
| --apartment1
| |
| --name: "test name"
| --address: "test address"
| --apartment2
| |
| --name: "test name"
| --address: "test address"
|
--booking
|
--"-JFZG3coHOAblHZ7XSjK"
| |
| --date: "booking date 1"
| --reservatonFor:
|
--apartmentId: "apartment1"
|
--"-KJKJASDIUOPIWE9WEeJ"
| |
| --date: "booking date 2"
| --reservatonFor:
|
--apartmentId: "apartment2"
|
--"-YtUTRGJLNL876F3SSwS"
| |
| --date: "booking date 3"
| --reservatonFor:
|
--apartmentId: "apartment1"
|
Controller
function mainCtrlFunc($scope, $firebaseArray) {
var baseRef = new Firebase(firebaseUrl);
var norm = new Firebase.util.NormalizedCollection(
[baseRef.child("booking"), "bookings"]
[baseRef.child("apartment"), "apartments", "bookings.reservationFor.apartmentId"]
).select(
"bookings.date",
"apartments.name"
)ref();
$scope.bookings = $firebaseArray(norm);
}
Error:
Firebase.child failed: First argument was an invalid path: "[object Object]". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"